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 99558 - g_atexit() doesn't work on Win32
g_atexit() doesn't work on Win32
Status: RESOLVED NOTGNOME
Product: glib
Classification: Platform
Component: win32
2.0.x
Other Windows
: Normal normal
: ---
Assigned To: Tor Lillqvist
Tor Lillqvist
Depends on:
Blocks:
 
 
Reported: 2002-11-25 21:32 UTC by Tor Lillqvist
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tor Lillqvist 2002-11-25 21:32:43 UTC
For obscure reasons g_atexit() doesn't work in GLib on Windows, if GLib is 
built as a DLL, and compiled with gcc 2.95.3. If GLib is built with MSVC, 
it presumably works (a similar minimal test case behaves thusly).

I haven't yet checked yet whether GCC 3.2 would work any better. The 
minimal test case mentioned has a DLL that contains a function that calls 
atexit(), i.e. the same situation as with g_atexit() in the GLib DLL. If 
you build that DLL with MSVC, the atexit() call works. If you build it 
with gcc, it doesn't.

Anyway, calling atexit() directly from the application code works both 
with gcc and MSVC.

The simplest fix would be to have in gutils.h:

#ifdef G_OS_WIN32
  #define g_atexit(func) atexit(func)
#else
...

and perhaps add something like this to g_atexit():

#if defined(G_OS_WIN32) && defined(__GNUC__)
  g_warning ("This implementation of g_atexit() doesn't work. Recompile 
your code with at least GLib version 2.0.10") (or 2.1.x?)
#endif

A more elaborate fix would be to check how exactly the atexit() that one 
gets when building with gcc differes from the one one gets when building 
with MSVC, and add appropriate workarounds. Unfortunately this requires 
looking at the source code to Microsoft's C runtime. The source code is 
downloadable as part of the Windows Platform SDK, but I am not a lawyer, I 
can't say to what extent the Platform SDK license allows you to make use 
of knowledge acquired by reading the source code.
Comment 1 Tor Lillqvist 2002-11-26 00:05:39 UTC
Building the GLib DLL with a newer mingw runtime fixed this. The
next binary distribution of GLib will be built with GCC 3.2 and
the newer mingw runtime. Until then, use atexit() directly. Closing, 
as this was more of a bug in mingw than in GLib.