GNOME Bugzilla – Bug 769504
'gobject.c' (in git master) fails to compile with MSVC
Last modified: 2016-08-04 10:31:54 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).
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.
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.
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.
Sorry for the duplication! :-)
Created attachment 332704 [details] [review] Fix debug builds under MSVC / v2
Review of attachment 332704 [details] [review]: Thanks Emmanuele, that's fixed it. Release version and Debug version are both building fine again.
Thanks for testing; pushed attachment 332704 [details] [review] to master