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 754431 - Fix build of glib/gstrfuncs.c on Windows
Fix build of glib/gstrfuncs.c on Windows
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Windows
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-09-02 07:30 UTC by Fan, Chun-wei
Modified: 2017-08-05 23:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
glib/gstrfuncs.c: Fix Build on Windows (1.00 KB, patch)
2015-09-02 07:38 UTC, Fan, Chun-wei
none Details | Review
glib/gstrfuncs.c: Fix Build on Windows (1.02 KB, patch)
2015-09-02 08:11 UTC, Fan, Chun-wei
committed Details | Review
strerror_s only with _MSC_VER (396 bytes, patch)
2015-10-27 21:12 UTC, Cédric Krier
none Details | Review

Description Fan, Chun-wei 2015-09-02 07:30:11 UTC
Hi,

Commit 36fac0849 introduced the use of strerror_r() which is actually not available on Windows, which will then cause the build on Windows to break.

We can just use strerror_s(), which does more or less the same thing and should be thread-safe.
Comment 1 Fan, Chun-wei 2015-09-02 07:38:27 UTC
Created attachment 310461 [details] [review]
glib/gstrfuncs.c: Fix Build on Windows

Hi,

Please see the patch.

With blessigs, thank you!
Comment 2 Fan, Chun-wei 2015-09-02 08:11:35 UTC
Created attachment 310467 [details] [review]
glib/gstrfuncs.c: Fix Build on Windows

Hi,

I was testing the patch against the old DLL, and the previous patch tried to use uninitialized memory, bad :|

This is the correct patch.

With blessings, thank you!
Comment 3 Ignacio Casal Quinteiro (nacho) 2015-09-02 08:38:19 UTC
Review of attachment 310467 [details] [review]:

Looks good to me.
Comment 4 Fan, Chun-wei 2015-09-02 09:07:40 UTC
Hi Nacho,

Thanks for the very quick reviews :)!

The patch was pushed as 4cad3f5.

With blessings, thank you!
Comment 5 Sebastian Dröge (slomo) 2015-10-20 11:58:17 UTC
strerror_s only exists in msvcrt.dll since Windows Server 2003 it seems, Windows XP does not have it.
Comment 6 Sebastian Dröge (slomo) 2015-10-20 13:44:24 UTC
And in mingw only if you #define MINGW_HAS_SECURE_API? That seems weird.
Comment 7 Sebastian Dröge (slomo) 2015-10-20 13:53:47 UTC
And if we wanted to compile for newer Windows, we run into bug #756868
Comment 8 Cédric Krier 2015-10-27 21:12:17 UTC
Created attachment 314258 [details] [review]
strerror_s only with _MSC_VER

I need this patch to compile with mingw which doesn't have strerror_s.
Comment 9 Sebastian Dröge (slomo) 2015-10-27 22:52:03 UTC
mingw has it, but only if you #define MINGW_HAS_SECURE_API. See above :) In any case, something definitely needs some changes here
Comment 10 Cédric Krier 2015-10-28 08:14:34 UTC
But it is not defined after "./configure"
Comment 11 Sebastian Dröge (slomo) 2015-10-28 08:28:18 UTC
Yes, someone will have to investigate what this MINGW_HAS_SECURE_API is about in mingw.
Comment 12 Benjamin Gilbert 2015-11-25 06:13:18 UTC
mingw-w64-headers defines MINGW_HAS_SECURE_API (in _mingw.h) only if configured with --enable-secure-api, which is not the default.  Debian and Fedora build MinGW-w64 with --enable-secure-api for both i686 and x86_64 targets, but Cygwin enables it only for the x86_64 target.
Comment 13 Benjamin Gilbert 2015-11-30 20:05:16 UTC
I haven't found any documentation for MINGW_HAS_SECURE_API, so I had a look through the mingw-w64 repo.  --enable-secure-api and MINGW_HAS_SECURE_API only affect whether the prototypes for the "security-enhanced" (_s) functions are exposed by the headers.  AFAICT the macro is intended to be #defined by application code that is willing to require a newer msvcrt that includes those functions.  --enable-secure-api was added later; the commit message doesn't say why, but I suspect it's to prevent newer applications (which may assume the secure functions are available) from having to individually add the #define.

If it's okay for glib to depend on a post-XP msvcrt, I think the right fix is to #define MINGW_HAS_SECURE_API 1 before including system headers.  If not, strerror_s can't be used.
Comment 14 Sebastian Dröge (slomo) 2015-12-01 06:27:29 UTC
If I'm not mistaken, mingw will ship it's own implementation of those functions if they are not available in the target msvcrt.
Comment 15 Benjamin Gilbert 2015-12-07 22:08:03 UTC
Yes, it seems you're right.  The secapi polyfills were added to mingw-w64 starting in August 2012; strerror_s was added in March 2014.  Do we care about supporting Windows XP via MSVC builds (or builds with older mingw, I guess)?  Bug 736458 (missing rand_s) was fixed by dropping the rand_s call from glib, even though mingw-w64 added a rand_s implementation in June 2013.

MINGW_HAS_SECURE_API dates from October 2007, so I guess that macro is a historical artifact now.
Comment 16 Fan, Chun-wei 2015-12-09 02:30:51 UTC
Hi Benjamin,

(In reply to Benjamin Gilbert from comment #15)
> Do we care about supporting Windows XP via MSVC builds (or builds with older mingw, I guess)?

It is true that the general consensus from the maintainers' point of view would be to stop supporting Windows XP, as it reached end-of-life quite some time ago.  

For this bug specifically, on the MSVC side, is that the _s variants should be still supported on XP, as:

-The MSVC builds supported are for MSVC 2008 and later,
 and it is known that at a recent stage there are people that
 were able to build GLib successfully on MSVC 2005.
-The _s variants are supported since MSVC 2005, and they are
 supported in the CRT DLL that are shipped with the compilers,
 i.e. msvcrX0.dll, which should run on XP until MSVC 2012 (given
 that the XP support mode in MSVC 2012+ builds are not enabled).
-We don't support at this time building against the Windows DDK
 officially, which would then link to msvcrt.dll.

I can't say very much about the situation on MinGW or mingw-w64, sorry.

With blessings.
Comment 17 Benjamin Gilbert 2016-06-07 04:53:00 UTC
So it sounds as though we're okay on the MSVC side.  Cygwin is now building both MinGW-w64 targets with --enable-secure-api (see comment #12), so unless there's a major distro that still isn't doing that, I think this can be closed?
Comment 18 Daniel Boles 2017-08-05 23:53:54 UTC
Let's assume so!

If anyone hits this again, please do reopen with the info.