After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 711043 - MinGW : Implement fallback function for rand_s ()
MinGW : Implement fallback function for rand_s ()
Status: RESOLVED NOTGNOME
Product: glib
Classification: Platform
Component: general
2.39.x
Other Windows
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-10-29 03:11 UTC by tarnyko
Modified: 2014-06-17 04:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
glib-rand_s-mingw.patch (1.25 KB, patch)
2013-10-29 03:11 UTC, tarnyko
rejected Details | Review

Description tarnyko 2013-10-29 03:11:17 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.
Comment 1 Allison Karlitskaya (desrt) 2013-10-29 03:23:35 UTC
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
Comment 2 Allison Karlitskaya (desrt) 2013-10-29 03:25:42 UTC
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).
Comment 3 tarnyko 2013-10-29 03:36:32 UTC
(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.
Comment 4 Allison Karlitskaya (desrt) 2013-10-29 03:43:11 UTC
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?
Comment 5 tarnyko 2013-10-29 12:48:17 UTC
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...
Comment 6 Allison Karlitskaya (desrt) 2013-10-29 14:31:33 UTC
Thanks.  Can we say that this is OK for now, then?
Comment 7 tarnyko 2013-10-29 16:43:22 UTC
Yes I think it is. Thank you desrt.
Comment 8 tarnyko 2013-10-30 08:55:55 UTC
For the record :
https://sourceforge.net/p/mingw/bugs/2122/
Comment 9 Fan, Chun-wei 2014-05-16 02:09:51 UTC
Hi,

For records, closing this bug as Resolved-NotGNOME as this stemmed from a MinGW problem.

With blessings.