public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Xi Ruoyao <ryxi@stu.xidian.edu.cn>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH v2] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)
Date: Wed, 24 May 2017 19:28:00 -0000	[thread overview]
Message-ID: <20170524192810.GN12306@redhat.com> (raw)
In-Reply-To: <20170523161549.GE12306@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1214 bytes --]

On 23/05/17 17:15 +0100, Jonathan Wakely wrote:
>On 22/05/17 22:28 +0800, Xi Ruoyao wrote:
>>The new patch is attached.  Just merged the patches you sent and fixed
>>the ChangeLog of gnu.ver and testsuite_abi.cc.
>>
>>(For fun:  I had mistakenly attached the Vim .swp file of the patch
>>and almost sent it. :-p)
>
>Ha, that *definitely* wouldnt' have applied, but I think I'd have
>noticed the reason sooner ;-)
>
>I've committed the patch now - thanks.
>
>
>>@@ -334,6 +335,7 @@ compatible.
>>    <listitem><para>GCC 5.1.0: GLIBCXX_3.4.21, CXXABI_1.3.9</para></listitem>
>>    <listitem><para>GCC 6.1.0: GLIBCXX_3.4.22, CXXABI_1.3.10</para></listitem>
>>    <listitem><para>GCC 7.1.0: GLIBCXX_3.4.23, CXXABI_1.3.11</para></listitem>
>>+    <listitem><para>GCC 8.0.0: GLIBCXX_3.4.24, CXXABI_1.3.10</para></listitem>
>
>Oops, this should have been CXXABI_1.3.11, I fixed that before
>committing it.
>
>>+    if (static_cast<unsigned>(ent) > sizeof(result_type) * 8)
>>+      return static_cast<double>(sizeof(result_type) * 8);
>
>After committing it I realised this should use __CHAR_BIT__ instead of
>hardcoding 8, which I'll fix shortly.

Fixed with this patch. Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 853 bytes --]

commit 26e91f1858aa054c28b521d86065966df4ba7099
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 24 17:41:34 2017 +0100

    Use CHAR_BIT instead of assuming 8 bits
    
    	* src/c++11/random.cc (random_device::_M_getentropy): Use __CHAR_BIT__
    	instead of fixed number of bits.

diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc
index 5011cf2..ef17223 100644
--- a/libstdc++-v3/src/c++11/random.cc
+++ b/libstdc++-v3/src/c++11/random.cc
@@ -187,8 +187,9 @@ namespace std _GLIBCXX_VISIBILITY(default)
     if (ent < 0)
       return 0.0;
 
-    if (static_cast<unsigned>(ent) > sizeof(result_type) * 8)
-      return static_cast<double>(sizeof(result_type) * 8);
+    const int max = sizeof(result_type) * __CHAR_BIT__;
+    if (ent > max)
+      ent = max;
 
     return static_cast<double>(ent);
 #else

      reply	other threads:[~2017-05-24 19:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18 12:15 [PATCH] " Xi Ruoyao
2017-05-22 13:21 ` Jonathan Wakely
2017-05-22 13:50   ` Xi Ruoyao
2017-05-22 14:10     ` Jonathan Wakely
2017-05-22 14:19       ` Xi Ruoyao
2017-05-23 12:11         ` Jonathan Wakely
2017-05-22 14:30       ` [PATCH v2] " Xi Ruoyao
2017-05-23 16:22         ` Jonathan Wakely
2017-05-24 19:28           ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170524192810.GN12306@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ryxi@stu.xidian.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).