[glib/wip/gproperty-2: 177/178] property: Simplify code generation and private data access



commit 847a5d1b727423fbc2271bbc4232fc4bdcb573dd
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Jun 11 12:07:50 2013 +0100

    property: Simplify code generation and private data access
    
    The macros (both internal and external) and the accessors can be
    simplified by the new private data memory layout, as well as by
    cleaning up some redundant checks.

 gobject/gproperty.c      |  185 +++++++++++++++++++++------------------------
 gobject/gproperty.h      |   83 ++++++++++++---------
 gobject/tests/property.c |    7 +-
 3 files changed, 135 insertions(+), 140 deletions(-)
---
diff --git a/gobject/gproperty.c b/gobject/gproperty.c
index 4d52596..4ee2554 100644
--- a/gobject/gproperty.c
+++ b/gobject/gproperty.c
@@ -347,6 +347,7 @@ struct _GProperty
 
   guint16 type_size;
   guint16 field_offset;
+  gint priv_offset;
 
   GQuark prop_id;
 
@@ -588,7 +589,7 @@ g_##g_t##_property_set_value (GProperty *property, \
                               gpointer   gobject, \
                               c_t        value) \
 { \
-  gboolean retval; \
+  gboolean retval = FALSE; \
 \
   if ((property->flags & G_PROPERTY_WRITABLE) == 0) \
     { \
@@ -623,22 +624,19 @@ g_##g_t##_property_set_value (GProperty *property, \
 \
       property_lock_internal (property, gobject); \
 \
-      priv_p = get_private_pointer (gobject); \
+      priv_p = get_private_pointer (property, gobject); \
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset); \
 \
-      if ((* (c_t *) field_p) == value) \
+      if ((* (c_t *) field_p) != value) \
         { \
-          property_unlock_internal (property, gobject); \
-          return FALSE; \
+          (* (c_t *) field_p) = value; \
+          retval = TRUE; \
         } \
 \
-      (* (c_t *) field_p) = value; \
-\
       property_unlock_internal (property, gobject); \
 \
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property); \
-\
-      retval = TRUE; \
+      if (retval) \
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property); \
     } \
   else \
     { \
@@ -670,12 +668,11 @@ g_##g_t##_property_get_value (GProperty *property, \
     } \
   else if (property->field_offset >= 0) \
     { \
-      gpointer priv_p, field_p; \
+      gpointer priv_p; \
 \
-      priv_p = get_private_pointer (gobject); \
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset); \
+      priv_p = get_private_pointer (property, gobject); \
 \
-      return (* (c_t *) field_p); \
+      return G_STRUCT_MEMBER (c_t, priv_p, property->field_offset); \
     } \
   else \
     { \
@@ -731,9 +728,10 @@ property_unlock_internal (GProperty *property,
 }
 
 static inline gpointer
-get_private_pointer (gpointer instance)
+get_private_pointer (GProperty *property,
+                     gpointer   instance)
 {
-  return g_type_instance_get_private (instance, G_OBJECT_TYPE (instance));
+  return G_STRUCT_MEMBER_P (instance, property->priv_offset);
 }
 
 /**
@@ -1175,22 +1173,19 @@ g_enum_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
-      if ((* (gulong *) field_p) == value)
+      if ((* (gulong *) field_p) != value)
         {
-          property_unlock_internal (property, gobject);
-          return FALSE;
+          (* (gulong *) field_p) = value;
+          retval = TRUE;
         }
 
-      (* (gulong *) field_p) = value;
-
       property_unlock_internal (property, gobject);
 
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property);
-
-      retval = TRUE;
+      if (retval)
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property);
     }
   else
     g_critical (G_STRLOC ": No setter function or field offset specified "
@@ -1200,7 +1195,7 @@ g_enum_property_set_value (GProperty *property,
   return retval;
 }
 
-static inline gulong
+static inline glong
 g_enum_property_get_value (GProperty *property,
                            gpointer   gobject)
 {
@@ -1218,12 +1213,11 @@ g_enum_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
 
-      priv_p = get_private_pointer (gobject);
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      priv_p = get_private_pointer (property, gobject);
 
-      return (* (gulong *) field_p);
+      return G_STRUCT_MEMBER (glong, priv_p, property->field_offset);
     }
   else
     {
@@ -1426,22 +1420,19 @@ g_flags_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
-      if ((* (gulong *) field_p) == value)
+      if ((* (gulong *) field_p) != value)
         {
-          property_unlock_internal (property, gobject);
-          return FALSE;
+          (* (gulong *) field_p) = value;
+          retval = TRUE;
         }
 
-      (* (gulong *) field_p) = value;
-
       property_unlock_internal (property, gobject);
 
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property);
-
-      retval = TRUE;
+      if (retval)
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property);
     }
   else
     g_critical (G_STRLOC ": No setter function or field offset specified "
@@ -1469,12 +1460,11 @@ g_flags_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
 
-      priv_p = get_private_pointer (gobject);
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      priv_p = get_private_pointer (property, gobject);
 
-      return (* (gulong *) field_p);
+      return G_STRUCT_MEMBER (gulong, priv_p, property->field_offset);
     }
   else
     {
@@ -1697,22 +1687,19 @@ g_float_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
-      if ((* (gfloat *) field_p) == value)
+      if ((* (gfloat *) field_p) != value)
         {
-          property_unlock_internal (property, gobject);
-          return FALSE;
+          (* (gfloat *) field_p) = value;
+          retval = TRUE;
         }
 
-      (* (gfloat *) field_p) = value;
-
       property_unlock_internal (property, gobject);
 
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property);
-
-      retval = TRUE;
+      if (retval)
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property);
     }
   else
     g_critical (G_STRLOC ": No setter function or field offset specified "
@@ -1740,12 +1727,11 @@ g_float_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
 
-      priv_p = get_private_pointer (gobject);
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      priv_p = get_private_pointer (property, gobject);
 
-      return (* (gfloat *) field_p);
+      return G_STRUCT_MEMBER (gfloat, priv_p, property->field_offset);
     }
   else
     {
@@ -1968,22 +1954,19 @@ g_double_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
-      if ((* (gdouble *) field_p) == value)
+      if ((* (gdouble *) field_p) != value)
         {
-          property_unlock_internal (property, gobject);
-          return FALSE;
+          (* (gdouble *) field_p) = value;
+          retval = TRUE;
         }
 
-      (* (gdouble *) field_p) = value;
-
       property_unlock_internal (property, gobject);
 
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property);
-
-      retval = TRUE;
+      if (retval)
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property);
     }
   else
     g_critical (G_STRLOC ": No setter function or field offset specified "
@@ -2011,12 +1994,11 @@ g_double_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
 
-      priv_p = get_private_pointer (gobject);
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      priv_p = get_private_pointer (property, gobject);
 
-      return (* (gdouble *) field_p);
+      return G_STRUCT_MEMBER (gdouble, priv_p, property->field_offset);
     }
   else
     {
@@ -2167,7 +2149,7 @@ g_string_property_set_value (GProperty   *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
       str = (* (gpointer *) field_p);
@@ -2221,7 +2203,7 @@ g_string_property_get_value (GProperty *property,
       gpointer priv_p, field_p;
       gchar *retval;
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
       if (property->flags & G_PROPERTY_COPY_GET)
@@ -2383,7 +2365,7 @@ g_boxed_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
       if (property->flags & G_PROPERTY_COPY_SET)
@@ -2436,7 +2418,7 @@ g_boxed_property_get_value (GProperty *property,
       gpointer priv_p, field_p;
       gpointer value;
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
       if (property->flags & G_PROPERTY_COPY_GET)
@@ -2603,7 +2585,7 @@ g_object_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
       if ((* (gpointer *) field_p) == value)
@@ -2663,22 +2645,21 @@ g_object_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
+      GObject *obj;
 
       priv_p = g_type_instance_get_private (gobject, G_OBJECT_TYPE (gobject));
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      obj = &G_STRUCT_MEMBER (GObject, priv_p, property->field_offset);
 
       if (property->flags & G_PROPERTY_COPY_GET)
         {
-          gpointer value = (* (gpointer *) field_p);
-
-          if (value != NULL)
-            return g_object_ref (value);
+          if (obj != NULL)
+            return g_object_ref (obj);
           else
             return NULL;
         }
       else
-        return (* (gpointer *) field_p);
+        return obj;
     }
   else
     {
@@ -2828,22 +2809,19 @@ g_pointer_property_set_value (GProperty *property,
 
       property_lock_internal (property, gobject);
 
-      priv_p = get_private_pointer (gobject);
+      priv_p = get_private_pointer (property, gobject);
       field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
 
-      if ((* (gpointer *) field_p) == value)
+      if ((* (gpointer *) field_p) != value)
         {
-          property_unlock_internal (property, gobject);
-          return FALSE;
+          (* (gpointer *) field_p) = value;
+          retval = TRUE;
         }
 
-      (* (gpointer *) field_p) = value;
-
       property_unlock_internal (property, gobject);
 
-      g_object_notify_by_pspec (gobject, (GParamSpec *) property);
-
-      retval = TRUE;
+      if (retval)
+        g_object_notify_by_pspec (gobject, (GParamSpec *) property);
     }
   else
     g_critical (G_STRLOC ": No setter function or field offset specified "
@@ -2871,12 +2849,11 @@ g_pointer_property_get_value (GProperty *property,
     }
   else if (property->field_offset >= 0)
     {
-      gpointer priv_p, field_p;
+      gpointer priv_p;
 
-      priv_p = get_private_pointer (gobject); 
-      field_p = G_STRUCT_MEMBER_P (priv_p, property->field_offset);
+      priv_p = get_private_pointer (property, gobject);
 
-      return (* (gpointer *) field_p);
+      return G_STRUCT_MEMBER (gpointer, priv_p, property->field_offset);
     }
   else
     {
@@ -2908,7 +2885,7 @@ _g_property_set_installed (GProperty *property,
     {
       gboolean is_interface = G_TYPE_IS_INTERFACE (class_gtype);
 
-      if (is_interface)
+      if (G_UNLIKELY (is_interface))
         {
           g_critical (G_STRLOC ": The property '%s' has a field offset value "
                       "but it is being installed on an interface of type '%s'. "
@@ -2916,7 +2893,12 @@ _g_property_set_installed (GProperty *property,
                       "access to a structure field.",
                       G_PARAM_SPEC (property)->name,
                       g_type_name (class_gtype));
+
+          property->field_offset = -1;
+          property->priv_offset = 0;
         }
+      else
+        property->priv_offset = g_type_class_get_instance_private_offset (g_class);
     }
 
   /* if the property is using the default locking, pre-compute the
@@ -4033,8 +4015,9 @@ g_property_set_va (GProperty             *property,
   GType gtype;
 
   g_return_val_if_fail (G_IS_PROPERTY (property), FALSE);
-  g_return_val_if_fail (G_IS_OBJECT (gobject), FALSE);
+  g_return_val_if_fail (g_property_is_writable (property), FALSE);
   g_return_val_if_fail (property->is_installed, FALSE);
+  g_return_val_if_fail (G_IS_OBJECT (gobject), FALSE);
 
   g_object_ref (gobject);
 
@@ -4173,8 +4156,9 @@ g_property_get_va (GProperty             *property,
   gpointer ret_p = NULL;
 
   g_return_val_if_fail (G_IS_PROPERTY (property), FALSE);
-  g_return_val_if_fail (G_IS_OBJECT (gobject), FALSE);
+  g_return_val_if_fail (g_property_is_readable (property), FALSE);
   g_return_val_if_fail (property->is_installed, FALSE);
+  g_return_val_if_fail (G_IS_OBJECT (gobject), FALSE);
 
   gtype = G_PARAM_SPEC (property)->value_type;
 
@@ -4526,9 +4510,10 @@ g_property_set_value (GProperty    *property,
   GType gtype;
 
   g_return_if_fail (G_IS_PROPERTY (property));
+  g_return_if_fail (g_property_is_writable (property));
+  g_return_if_fail (property->is_installed);
   g_return_if_fail (G_IS_OBJECT (gobject));
   g_return_if_fail (value != NULL);
-  g_return_if_fail (property->is_installed);
 
   /* do not go jump through the transformability hoops if we're getting
    * the type we expect in the first place
@@ -4579,9 +4564,10 @@ g_property_get_value (GProperty *property,
   GValue copy = { 0, };
 
   g_return_if_fail (G_IS_PROPERTY (property));
+  g_return_if_fail (g_property_is_readable (property));
+  g_return_if_fail (property->is_installed);
   g_return_if_fail (G_IS_OBJECT (gobject));
   g_return_if_fail (value != NULL);
-  g_return_if_fail (property->is_installed);
 
   gtype = G_PARAM_SPEC (property)->value_type;
 
@@ -5291,6 +5277,7 @@ property_init (GParamSpec *pspec)
   pspec->value_type = G_TYPE_INVALID;
 
   property->field_offset = -1;
+  property->priv_offset = 0;
 
   property->lock_func = NULL;
   property->unlock_func = NULL;
diff --git a/gobject/gproperty.h b/gobject/gproperty.h
index 9359eeb..8520746 100644
--- a/gobject/gproperty.h
+++ b/gobject/gproperty.h
@@ -515,6 +515,9 @@ void            _g_property_set_installed       (GProperty           *property,
  *
  * Defines a new #GProperty using the provided arguments.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * Since: 2.38
  */
 #define G_DEFINE_PROPERTY_EXTENDED(T_n, p_type, p_name, p_flags, p_setter, p_getter, _C_) \
@@ -554,7 +557,7 @@ void            _g_property_set_installed       (GProperty           *property,
 \
   g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, t_n##_get_type ()), (f_t) 0); \
 \
-  priv = g_type_instance_get_private ((GTypeInstance *) self, t_n##_get_type ()); \
+  priv = t_n##_get_private (self); \
   retval = priv->f_n; \
 \
   { /* custom code follows */
@@ -578,18 +581,6 @@ void            _g_property_set_installed       (GProperty           *property,
       } \
   } \
 \
-  if (!G_IS_PROPERTY (g_property)) \
-    { \
-      g_critical (G_STRLOC ": Property " #f_n " is not a GProperty"); \
-      return (f_t) 0; \
-    } \
-\
-  if (!g_property_is_readable (g_property)) \
-    { \
-       g_critical (G_STRLOC ": The property " #f_n " is not readable"); \
-       return (f_t) 0; \
-    } \
-\
   if (!g_property_get (g_property, self, &retval)) \
     { \
       g_property_get_default (g_property, self, &retval); \
@@ -622,18 +613,6 @@ void            _g_property_set_installed       (GProperty           *property,
       } \
   } \
 \
-  if (!G_IS_PROPERTY (g_property)) \
-    { \
-      g_critical (G_STRLOC ": Property " #f_n " is not a GProperty"); \
-      return; \
-    } \
-\
-  if (!g_property_is_writable (g_property)) \
-    { \
-       g_critical (G_STRLOC ": The property " #f_n " is not writable"); \
-       return; \
-    } \
-\
   if (!g_property_set (g_property, self, value)) \
     return; \
 \
@@ -701,9 +680,8 @@ _G_DECLARE_PROPERTY_GETTER (T_n, t_n, f_t, f_n);
  * @_C_: C code that should be called after the property has been set
  *
  * Defines the setter function for a @field_name property in the
- * class @TypeName, with the possibility of calling custom code.
- *
- * This macro should only be used in C source files.
+ * class @TypeName, with the possibility of calling custom code, for
+ * instance:
  *
  * |[
  * G_DEFINE_PROPERTY_SET_WITH_CODE (ClutterActor, clutter_actor,
@@ -711,6 +689,13 @@ _G_DECLARE_PROPERTY_GETTER (T_n, t_n, f_t, f_n);
  *                                  clutter_actor_queue_redraw (self))
  * ]|
  *
+ * This macro should only be used for properties defined using #GProperty.
+ *
+ * This macro should only be used in C source files.
+ *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * Since: 2.38
  */
 
@@ -734,10 +719,16 @@ _G_DEFINE_PROPERTY_SETTER_END
  * class @T_n, with the possibility of calling custom code.
  *
  * This macro will directly access the field on the private
- * data structure.
+ * data structure, and should only be used if the property
+ * has been defined to use an offset instead of an explicit
+ * getter. Use G_DEFINE_PROPERTY_COMPUTED_GET_WITH_CODE() if
+ * you have an internal getter function.
  *
  * This macro should only be used in C source files.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * Since: 2.38
  */
 #define G_DEFINE_PROPERTY_GET_WITH_CODE(T_n, t_n, f_t, f_n, _C_) \
@@ -763,6 +754,9 @@ _G_DEFINE_PROPERTY_GETTER_END
  *
  * This macro should only be used in C source files.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * Since: 2.38
  */
 #define G_DEFINE_PROPERTY_COMPUTED_GET_WITH_CODE(T_n, t_n, f_t, f_n, _C_) \
@@ -783,6 +777,9 @@ _G_DEFINE_PROPERTY_GETTER_END
  * Defines the setter function for a @field_name property in the
  * class @TypeName. This macro should only be used in C source files.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * See also: %G_DEFINE_PROPERTY_SET_WITH_CODE
  *
  * Since: 2.38
@@ -801,6 +798,9 @@ _G_DEFINE_PROPERTY_GETTER_END
  * Defines the getter function for a @field_name property in the
  * class @TypeName. This macro should only be used in C source files.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * See also %G_DEFINE_PROPERTY_GET_WITH_CODE.
  *
  * Since: 2.38
@@ -819,6 +819,9 @@ _G_DEFINE_PROPERTY_GETTER_END
  * Defines the getter function for a @field_name property in the
  * class @TypeName. This macro should only be used in C source files.
  *
+ * Note that this macro should be used with types defined using G_DEFINE_TYPE_*
+ * macros, as it depends on variables and functions defined by those macros.
+ *
  * See also %G_DEFINE_PROPERTY_COMPUTED_GET_WITH_CODE.
  *
  * Since: 2.38
@@ -853,22 +856,26 @@ _G_DEFINE_PROPERTY_GETTER_END
  *
  *   g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, clutter_actor_get_type ()));
  *
- *   priv = self->priv;
+ *   priv = clutter_actor_get_private (self);
  *
- *   if (priv->margin_top == value)
- *     return;
+ *   if (priv->margin_top != value)
+ *     {
+ *       priv->value = value;
  *
- *   priv->value = value;
- *
- *   g_object_notify (G_OBJECT (self), "margin-top");
+ *       g_object_notify (G_OBJECT (self), "margin-top");
+ *     }
  * }
  *
  * int
  * clutter_actor_get_margin_top (ClutterActor *self)
  * {
+ *   ClutterActorPrivate *priv;
+ *
  *   g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (self, clutter_actor_get_type ()), 0);
  *
- *   return self->priv->margin_top;
+ *   priv = clutter_actor_get_private (self);
+ *
+ *   return priv->margin_top;
  * }
  * ]|
  *
@@ -881,6 +888,10 @@ _G_DEFINE_PROPERTY_GETTER_END
  * %G_DEFINE_PROPERTY_GET_WITH_CODE and %G_DEFINE_PROPERTY_SET_WITH_CODE
  * variants.
  *
+ * Note that this macro should only be used with types defined using
+ * G_DEFINE_TYPE_* macros, as it depends on variable and functions defined
+ * by those macros.
+ *
  * Since: 2.38
  */
 #define G_DEFINE_PROPERTY_GET_SET(T_n, t_n, f_t, f_n)      \
diff --git a/gobject/tests/property.c b/gobject/tests/property.c
index 79e8a56..c32fce4 100644
--- a/gobject/tests/property.c
+++ b/gobject/tests/property.c
@@ -65,7 +65,7 @@ test_enum_get_type (void)
   return g_define_type_id__volatile;
 }
 
-G_DEFINE_TYPE (TestObject, test_object, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (TestObject, test_object, G_TYPE_OBJECT)
 
 enum
 {
@@ -120,8 +120,6 @@ test_object_class_init (TestObjectClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-  g_type_class_add_private (klass, sizeof (TestObjectPrivate));
-
   gobject_class->finalize = test_object_finalize;
 
   test_object_properties[PROP_INTEGER_VAL] =
@@ -177,8 +175,7 @@ test_object_class_init (TestObjectClass *klass)
 static void
 test_object_init (TestObject *self)
 {
-  TestObjectPrivate *priv =
-    g_type_instance_get_private ((GTypeInstance *) self, test_object_get_type ());
+  TestObjectPrivate *priv = test_object_get_private (self);
 
   priv->enum_val = TEST_ENUM_UNSET;
 


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