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 769504 - 'gobject.c' (in git master) fails to compile with MSVC
'gobject.c' (in git master) fails to compile with MSVC
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Windows
: Normal blocker
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-08-04 08:25 UTC by John E
Modified: 2016-08-04 10:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix debug builds under MSVC (1.78 KB, patch)
2016-08-04 08:36 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
Fix debug builds under MSVC / v2 (1.81 KB, patch)
2016-08-04 09:20 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description John E 2016-08-04 08:25:07 UTC
Commit #42dad59cc1 (in glib git master) is causing compilation to fail when I try to compile a Debug build with MSVC. The problematic code looks like this at (approximately) line 400 of 'gobject/gobject.c':-

      GOBJECT_IF_DEBUG (OBJECTS,
      {
          debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
#ifndef G_HAS_CONSTRUCTORS
          g_atexit (debug_objects_atexit);
#endif /* G_HAS_CONSTRUCTORS */
      });

and there's a brief discussion here:- https://mail.gnome.org/archives/gtk-devel-list/2016-August/msg00006.html

The conclusion was that the above macro is effectively now a "macro within a macro" which MSVC doesn't allow (see Arnavion's post in the above discussion).  Previously, that particular section looked like this, which did compile okay:-

#ifdef  G_ENABLE_DEBUG
    IF_DEBUG (OBJECTS)
      {
        debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
#ifndef G_HAS_CONSTRUCTORS
        g_atexit (debug_objects_atexit);
#endif /* G_HAS_CONSTRUCTORS */
      }
#endif    /* G_ENABLE_DEBUG */

What confused us all was that the commit dates back to May 2014. However, it seems like it only got pushed upstream sometime around the 7th or 8th of July 2016 (hence why it's only just started to cause a problem).
Comment 1 Emmanuele Bassi (:ebassi) 2016-08-04 08:36:11 UTC
Created attachment 332703 [details] [review]
Fix debug builds under MSVC

The C spec leaves conditional evaluation inside a macro expansion as
undefined behaviour. This means we cannot use constructs like:

  GOBJECT_IF_DEBUG(OBJECTS, {
    ...
  #ifdef BLAH
    ...
  #endif
    ...});

Because compilers are entirely justified to ignore the conditional, or,
like in the case of MSVC, error out.
Comment 2 John E 2016-08-04 09:00:01 UTC
Hi Emmanuele and thanks for the prompt fix. The only problem is that (during the earlier change in July) the IF_DEBUG macro must have gotten removed, so that needs to get put back again.
Comment 3 John E 2016-08-04 09:05:31 UTC
Review of attachment 332703 [details] [review]:

It seems that (during the earlier change in July) the macro 'IF_DEBUG' must have gotten removed, so that needs to get put back again.
Comment 4 John E 2016-08-04 09:07:18 UTC
Sorry for the duplication!  :-)
Comment 5 Emmanuele Bassi (:ebassi) 2016-08-04 09:20:11 UTC
Created attachment 332704 [details] [review]
Fix debug builds under MSVC / v2
Comment 6 John E 2016-08-04 10:02:53 UTC
Review of attachment 332704 [details] [review]:

Thanks Emmanuele, that's fixed it. Release version and Debug version are both building fine again.
Comment 7 Emmanuele Bassi (:ebassi) 2016-08-04 10:31:50 UTC
Thanks for testing; pushed attachment 332704 [details] [review] to master