[Cogl] [Patch][Cogl-1.18]: Fix build Cogl on non-GCC

Fan Chun-wei fanc999 at yahoo.com.tw
Sun Apr 6 21:31:00 PDT 2014


Hi,

In commit 1b2dd81 (Registers gtypes for all public objects and structs), 
varargs were used in macros for COGL_GTYPE_DEFINE_CLASS and 
COGL_GTYPE_DEFINE_BASE_CLASS (in cogl/cogl-gtype-private.h) in order to 
facilitate the definition of *_get_gtype() functions, which are needed 
for introspection.  This, however, introduced GCCisms, so that builds on 
non-GCC are boken.  This patch defines these two macros for non-GCC, 
using GLib's G_HAVE_GNUC_VARARGS (for GCC) and G_HAVE_ISO_VARARGS (for 
non-GCC, such as Visual Studio), in a manner not unlike 
deps/glib/gmessage.h, so that the build on non-GCC can be fixed.

I did not update build/autotools/as-glibconfig.m4 as I was not sure 
whether the build of Cogl via autotools is currently supported for 
non-GCC, and the Visual Studio Projects all require an existing GLib 
installation to build.

With blessings, thank you!
-------------- next part --------------
From 10e33ba147cdb4e9b152f7b150587328eeda5a0b Mon Sep 17 00:00:00 2001
From: Chun-wei Fan <fanchunwei at src.gnome.org>
Date: Mon, 7 Apr 2014 11:05:03 +0800
Subject: [PATCH 1/2] cogl/cogl-gtype-private.h: Fix Build on non-GCC

Commit 1b2dd815 (Registers gtypes for all public objects and structs)
introduced GCCism's in its use of varargs, which broke the build of Cogl
on other non-GCC compilers, such as Visual Studio.

Define the COGL_GTYPE_DEFINE_BASE_CLASS and COGL_GTYPE_DEFINE_CLASS macros
for non-GCC also, by using GLib's G_HAVE_GNUC_VARARGS (for GCC) and
G_HAVE_ISO_VARARGS (for non-GCC), in a manner similar to
deps/glib/gmessage.h, so that builds on non-GCC can be fixed.

As commit 1b2dd815 already implies that varargs are required, add a #error
to tell people that varargs support is required to build Cogl, since it
seems that varargs should be already supported on most, if not all,
reasonably-modern compilers (for example, for Visual Studio, since Visual
C++ 2005 and later).
---
 cogl/cogl-gtype-private.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/cogl/cogl-gtype-private.h b/cogl/cogl-gtype-private.h
index 03832ef..e6ba886 100644
--- a/cogl/cogl-gtype-private.h
+++ b/cogl/cogl-gtype-private.h
@@ -133,10 +133,19 @@ cogl_##name##_get_gtype (void)                                      \
     return type_id__volatile;                                           \
   }
 
+#ifdef G_HAVE_GNUC_VARARGS
 #define COGL_GTYPE_DEFINE_BASE_CLASS(Name,name,interfaces...)      \
   _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name)                   \
   {interfaces;}                                                    \
   _COGL_GTYPE_DEFINE_BASE_CLASS_END()
+#elif defined G_HAVE_ISO_VARARGS
+#define COGL_GTYPE_DEFINE_BASE_CLASS(Name,name,...)      \
+  _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name)         \
+  {__VA_ARGS__;}                                         \
+  _COGL_GTYPE_DEFINE_BASE_CLASS_END()
+#else
+#error "Either GCC-style or ISO-style varargs are required"
+#endif
 
 #define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN(Name,name)          \
                                                                         \
@@ -230,6 +239,7 @@ cogl_##name##_get_gtype (void)                                      \
     } /* closes name##_get_type() */
 
 
+#ifdef G_HAVE_GNUC_VARARGS
 #define COGL_GTYPE_DEFINE_CLASS(Name,name,interfaces...)                \
   typedef struct _Cogl##Name##Class Cogl##Name##Class;                  \
   struct _Cogl##Name##Class {                                           \
@@ -249,6 +259,29 @@ cogl_##name##_get_gtype (void)                                      \
   cogl_##name##_class_init (Cogl##Name##Class *klass)                   \
   {                                                                     \
   }
+#elif defined G_HAVE_ISO_VARARGS
+#define COGL_GTYPE_DEFINE_CLASS(Name,name,...)                          \
+  typedef struct _Cogl##Name##Class Cogl##Name##Class;                  \
+  struct _Cogl##Name##Class {                                           \
+    CoglObjectClass parent_class;                                       \
+  };                                                                    \
+  _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Cogl##Name,                    \
+                                         cogl_##name,                   \
+                                         cogl_object_get_gtype(),       \
+                                         0)                             \
+  {__VA_ARGS__;}                                                        \
+  _COGL_GTYPE_DEFINE_TYPE_EXTENDED_END()                                \
+  static void                                                           \
+  cogl_##name##_init (Cogl##Name *instance)                             \
+  {                                                                     \
+  }                                                                     \
+  static void                                                           \
+  cogl_##name##_class_init (Cogl##Name##Class *klass)                   \
+  {                                                                     \
+  }
+#else
+#error "Either GCC-style or ISO-style varargs are required"
+#endif
 
 void _cogl_gtype_object_init_value (GValue *value);
 void _cogl_gtype_object_free_value (GValue *value);
-- 
1.8.3.msysgit.0



More information about the Cogl mailing list