[glib] Fix debug builds under MSVC



commit 5ff8579527e75a9077c7152d4878d282123ddb45
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Aug 4 09:33:25 2016 +0100

    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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769504

 gobject/gobject.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 1621f0c..766d039 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -393,14 +393,23 @@ _g_object_type_init (void)
   type = g_type_register_fundamental (G_TYPE_OBJECT, g_intern_static_string ("GObject"), &info, &finfo, 0);
   g_assert (type == G_TYPE_OBJECT);
   g_value_register_transform_func (G_TYPE_OBJECT, G_TYPE_OBJECT, g_value_object_transform_value);
-  
-  GOBJECT_IF_DEBUG (OBJECTS,
+
+#if G_ENABLE_DEBUG
+  /* We cannot use GOBJECT_IF_DEBUG here because of the G_HAS_CONSTRUCTORS
+   * conditional in between, as the C spec leaves conditionals inside macro
+   * expansions as undefined behavior. Only GCC and Clang are known to work
+   * but compilation breaks on MSVC.
+   *
+   * See: https://bugzilla.gnome.org/show_bug.cgi?id=769504
+   */
+  if (_g_type_debug_flags & G_TYPE_DEBUG_OBJECTS) \
     {
       debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
-#ifndef G_HAS_CONSTRUCTORS
+# ifndef G_HAS_CONSTRUCTORS
       g_atexit (debug_objects_atexit);
-#endif /* G_HAS_CONSTRUCTORS */
-    });
+# endif /* G_HAS_CONSTRUCTORS */
+    }
+#endif /* G_ENABLE_DEBUG */
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]