[glib/wip/private-rework-3: 1/5] Rejig the type definition macros for instance types



commit 6ad3446d11c2bd673a81489c0280c4e2f2c9993d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Jun 17 19:12:45 2013 +0100

    Rejig the type definition macros for instance types
    
    We need to reference the get_type() function from the get_private() one,
    so the latter has to come after the former. This requires restructuring
    the type definition macros for instance types — the only ones that can
    actually have private data
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700035

 gobject/gtype.h |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index a397ee3..53e36ee 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1339,7 +1339,7 @@ guint     g_type_get_type_registration_serial (void);
  * 
  * Since: 2.4
  */
-#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)         _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) 
{_C_;} _G_DEFINE_TYPE_EXTENDED_END()
+#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)         _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) 
{_C_;} _G_DEFINE_INSTANCE_TYPE_EXTENDED_END(TN, t_n)
 /**
  * G_DEFINE_TYPE_WITH_PRIVATE:
  * @TN: The name of the new type, in Camel case.
@@ -1385,7 +1385,7 @@ guint     g_type_get_type_registration_serial (void);
  * 
  * Since: 2.4
  */
-#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 
G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
+#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 
G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_INSTANCE_TYPE_EXTENDED_END(TN, t_n)
 /**
  * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE:
  * @TN: The name of the new type, in Camel case.
@@ -1461,7 +1461,7 @@ guint     g_type_get_type_registration_serial (void);
  *
  * Since: 2.4
  */
-#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)     _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) 
{_C_;} _G_DEFINE_TYPE_EXTENDED_END()
+#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)     _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) 
{_C_;} _G_DEFINE_INSTANCE_TYPE_EXTENDED_END(TN, t_n)
 
 /**
  * G_DEFINE_INTERFACE:
@@ -1597,15 +1597,6 @@ static void     type_name##_class_intern_init (gpointer klass) \
   type_name##_class_init ((TypeName##Class*) klass); \
 } \
 \
-static inline gpointer \
-type_name##_get_private (TypeName *self) \
-{ \
-  if (G_LIKELY (type_name##_private_offset != 0)) \
-    return (G_STRUCT_MEMBER_P (self, type_name##_private_offset)); \
-\
-  return g_type_instance_get_private ((GTypeInstance *) self, type_name##_get_type ()); \
-} \
-\
 GType \
 type_name##_get_type (void) \
 { \
@@ -1621,6 +1612,23 @@ type_name##_get_type (void) \
                                        (GInstanceInitFunc) type_name##_init, \
                                        (GTypeFlags) flags); \
       { /* custom code follows */
+#define _G_DEFINE_INSTANCE_TYPE_EXTENDED_END(TypeName, type_name) \
+        /* following custom code */    \
+      }                                        \
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
+    }                                  \
+  return g_define_type_id__volatile;   \
+} /* closes type_name##_get_type() */   \
+\
+static inline gpointer \
+type_name##_get_private (TypeName *self) \
+{ \
+  if (G_LIKELY (type_name##_private_offset != 0)) \
+    return (G_STRUCT_MEMBER_P (self, type_name##_private_offset)); \
+\
+  return g_type_instance_get_private ((GTypeInstance *) self, type_name##_get_type ()); \
+}
+
 #define _G_DEFINE_TYPE_EXTENDED_END()  \
         /* following custom code */    \
       }                                        \


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