GNOME Bugzilla – Bug 711043
MinGW : Implement fallback function for rand_s ()
Last modified: 2014-06-17 04:36:39 UTC
Created attachment 258386 [details] [review] glib-rand_s-mingw.patch A recent commit introduced the use of "rand_s ()" under Win32 : https://git.gnome.org/browse/glib/commit/?id=0e1924a66c642d4aa4a30b97cff509903f972435 That's fine, except that it's MSVC-specific, and MinGW doesn't have it. Please consider attached patch, which adds configure checks and falls back to "srand ()/rand()" couples on MinGW, while MSVC should keep the functionality.
I tested this patch with mingw... it worked. [desrt@moonpix ~]$ grep -A1 -B1 -r '\<rand_s\>' /usr/i686-w64-mingw32/sys-root/mingw/include /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h-#ifdef _CRT_RAND_S /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h: _CRTIMP errno_t __cdecl rand_s(unsigned int *randomValue); /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h-#endif
Review of attachment 258386 [details] [review]: This patch reduces the randomness to being entirely determined by the current second. This is a substantial regression from even the old code. If it really comes down to it, I'd rather go with the other patch that was on bug 710738 (ie: using RtlGenRandom directly).
(In reply to comment #1) > I tested this patch with mingw... it worked. > > /usr/i686-w64-mingw32/sys-root/mingw/include > /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h-#ifdef _CRT_RAND_S > /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h: _CRTIMP errno_t __cdecl > rand_s(unsigned int *randomValue); > /usr/i686-w64-mingw32/sys-root/mingw/include/stdlib.h-#endif I tested that ; it's not upstream, though, which means we need to recompile MinGW libmsvcrt ourselves to provide the symbol. As it's in GLib unstable, we could try to push it upstream in MinGW so it *could* become available until we get stable. Or put RtlGenRandom() in MinGW #ifdef, which isn't elegant but a more secure alternative. I'd go for the 2nd, which would allow GTK+3 Win32 continuous to build meanwhile.
From what I understand, mingw is just providing a prototype for this function which is located in Microsoft's libraries. Couldn't we just add our own prototype instead?
I investigated a little bit, and here's the root cause : rand_s is implemented by MinGW64, but not MinGW32. MinGW32 : strings /usr/i686-pc-mingw32/sys-root/mingw/lib/libmsvcrt.a |grep rand_s <empty> MinGW64 : strings /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libmsvcrt.a |grep rand_s rand_s GNOME Win32 build machine currently uses MinGW32, but MinGW64 is functional since yesterday (https://bugzilla.gnome.org/show_bug.cgi?id=708151), so I'll just use it instead. And submit a patch to MinGW32 upstream meanwhile...
Thanks. Can we say that this is OK for now, then?
Yes I think it is. Thank you desrt.
For the record : https://sourceforge.net/p/mingw/bugs/2122/
Hi, For records, closing this bug as Resolved-NotGNOME as this stemmed from a MinGW problem. With blessings.