<div dir="rtl"><div dir="ltr">Hi,</div><div dir="ltr"><br></div><div dir="ltr">Sorry for not catching this thread earlier, MinGW does have rand_s if <font face="courier new, monospace">_CRT_RAND_S</font> is defined.</div><div dir="ltr">
>From stdio.h:</div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><font face="courier new, monospace">#ifdef _CRT_RAND_S</font></div><div dir="ltr"><font face="courier new, monospace"> _CRTIMP errno_t __cdecl rand_s(unsigned int *randomValue);</font></div>
<div dir="ltr"><font face="courier new, monospace">#endif</font></div><div><br></div><div>libcxx already uses rand_s in random_device and compiles with MinGW, here is the discussion:</div><div><br></div><div> <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131007/090656.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131007/090656.html</a><br>
</div><div><br></div><div>Yaron</div><div><br></div></div><div dir="ltr"><br></div><div dir="ltr"><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div dir="ltr">2014-02-11 5:46 GMT+02:00 Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span>:</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is hopefully resolved in r201124; I reimplemented the original<br>
patch using CryptGenRandom, which is effectively what rand_s() uses<br>
internally anyway.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, Feb 10, 2014 at 8:52 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
> It appears there is no rand_s() implementation for MinGW 32, so the<br>
> question becomes whether we back this change out, or fall back on<br>
> rand(). Unfortunately, r185126 is relying on this, and I'm loathe to<br>
> start backing out other people's work because of this. So instead, I<br>
> will gin up a replacement for MinGW 32 and hopefully Stephan can<br>
> either come up with a better fix, or mine will be sufficient for the<br>
> task.<br>
><br>
> ~Aaron<br>
><br>
> On Mon, Feb 10, 2014 at 2:15 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
>> Thank you for pointing this out, Galina and sorry for the difficulties!<br>
>><br>
>> Stephan, would you be able to look into this?<br>
>><br>
>> ~Aaron<br>
>><br>
>> On Mon, Feb 10, 2014 at 2:05 PM, Galina Kistanova <<a href="mailto:gkistanova@gmail.com">gkistanova@gmail.com</a>> wrote:<br>
>>> Hi Aaron,<br>
>>><br>
>>> Seems this revision broke clang-native-mingw32-win7 builder:<br>
>>> <a href="http://lab.llvm.org:8011/builders/clang-native-mingw32-win7/builds/5557" target="_blank">http://lab.llvm.org:8011/builders/clang-native-mingw32-win7/builds/5557</a><br>
>>><br>
>>> The last successful build was for revision 200765:<br>
>>> <a href="http://lab.llvm.org:8011/builders/clang-native-mingw32-win7/builds/5578" target="_blank">http://lab.llvm.org:8011/builders/clang-native-mingw32-win7/builds/5578</a><br>
>>> Please have a look at it.<br>
>>><br>
>>> Thanks<br>
>>><br>
>>> Galina<br>
>>><br>
>>><br>
>>><br>
>>> On Tue, Feb 4, 2014 at 6:49 AM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>><br>
>>> wrote:<br>
>>>><br>
>>>> Author: aaronballman<br>
>>>> Date: Tue Feb 4 08:49:21 2014<br>
>>>> New Revision: 200767<br>
>>>><br>
>>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200767&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=200767&view=rev</a><br>
>>>> Log:<br>
>>>> Implemented support for Process::GetRandomNumber on Windows.<br>
>>>><br>
>>>> Patch thanks to Stephan Tolksdorf!<br>
>>>><br>
>>>> Modified:<br>
>>>> llvm/trunk/lib/Support/Process.cpp<br>
>>>> llvm/trunk/lib/Support/Windows/Process.inc<br>
>>>> llvm/trunk/unittests/Support/ProcessTest.cpp<br>
>>>><br>
>>>> Modified: llvm/trunk/lib/Support/Process.cpp<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Process.cpp?rev=200767&r1=200766&r2=200767&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Process.cpp?rev=200767&r1=200766&r2=200767&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- llvm/trunk/lib/Support/Process.cpp (original)<br>
>>>> +++ llvm/trunk/lib/Support/Process.cpp Tue Feb 4 08:49:21 2014<br>
>>>> @@ -12,6 +12,11 @@<br>
>>>><br>
>>>> //===----------------------------------------------------------------------===//<br>
>>>><br>
>>>> #include "llvm/Config/config.h"<br>
>>>> +#if LLVM_ON_WIN32<br>
>>>> + // This define makes stdlib.h declare the rand_s function.<br>
>>>> +#define _CRT_RAND_S<br>
>>>> +#include <stdlib.h><br>
>>>> +#endif<br>
>>>> #include "llvm/Support/ErrorHandling.h"<br>
>>>> #include "llvm/Support/Process.h"<br>
>>>><br>
>>>><br>
>>>> Modified: llvm/trunk/lib/Support/Windows/Process.inc<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=200767&r1=200766&r2=200767&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=200767&r1=200766&r2=200767&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- llvm/trunk/lib/Support/Windows/Process.inc (original)<br>
>>>> +++ llvm/trunk/lib/Support/Windows/Process.inc Tue Feb 4 08:49:21 2014<br>
>>>> @@ -360,3 +360,10 @@ const char *Process::ResetColor() {<br>
>>>> SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),<br>
>>>> defaultColors());<br>
>>>> return 0;<br>
>>>> }<br>
>>>> +<br>
>>>> +unsigned Process::GetRandomNumber() {<br>
>>>> + unsigned int result;<br>
>>>> + const errno_t ec = rand_s(&result);<br>
>>>> + assert(ec == 0 && "rand_s failed");<br>
>>>> + return result;<br>
>>>> +}<br>
>>>><br>
>>>> Modified: llvm/trunk/unittests/Support/ProcessTest.cpp<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ProcessTest.cpp?rev=200767&r1=200766&r2=200767&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ProcessTest.cpp?rev=200767&r1=200766&r2=200767&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- llvm/trunk/unittests/Support/ProcessTest.cpp (original)<br>
>>>> +++ llvm/trunk/unittests/Support/ProcessTest.cpp Tue Feb 4 08:49:21 2014<br>
>>>> @@ -39,6 +39,13 @@ TEST(ProcessTest, SelfProcess) {<br>
>>>> EXPECT_GT(TimeValue::MaxTime, process::get_self()->get_wall_time());<br>
>>>> }<br>
>>>><br>
>>>> +TEST(ProcessTest, GetRandomNumberTest) {<br>
>>>> + const unsigned r1 = Process::GetRandomNumber();<br>
>>>> + const unsigned r2 = Process::GetRandomNumber();<br>
>>>> + // It should be extremely unlikely that both r1 and r2 are 0.<br>
>>>> + EXPECT_NE((r1 | r2), 0);<br>
>>>> +}<br>
>>>> +<br>
>>>> #ifdef _MSC_VER<br>
>>>> #define setenv(name, var, ignore) _putenv_s(name, var)<br>
>>>> #endif<br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> llvm-commits mailing list<br>
>>>> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
>>><br>
>>><br>
>>><br>
>>><br>
>>> --<br>
>>> Thanks<br>
>>><br>
>>> Galina<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>