From ca6b93d0936e6864d374d3e8f2a795c1702b28b3 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 26 Jul 2013 16:45:48 +0100 Subject: [PATCH] Add macros and symbols for private data on dynamic types We need a TypeName_private_offset variable defined by the macros used to register dynamic types. We also need to call the adjust_private_offset() function inside class_init(). G_ADD_PRIVATE_DYNAMIC only sets the size of the private data structure, and relies on the behaviour of the g_type_class_adjuset_private_offset() function to register the private data structure at class init time if passed a value greater than zero. This allows using G_PRIVATE_OFFSET with dynamic types. --- gobject/gtypemodule.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gobject/gtypemodule.h b/gobject/gtypemodule.h index cc42bdd5a..22cbdafa3 100644 --- a/gobject/gtypemodule.h +++ b/gobject/gtypemodule.h @@ -180,11 +180,16 @@ static void type_name##_class_init (TypeName##Class *klass); \ static void type_name##_class_finalize (TypeName##Class *klass); \ static gpointer type_name##_parent_class = NULL; \ static GType type_name##_type_id = 0; \ -static void type_name##_class_intern_init (gpointer klass) \ +static gint TypeName##_private_offset; \ +\ +_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ +\ +static inline gpointer \ +type_name##_get_instance_private (TypeName *self) \ { \ - type_name##_parent_class = g_type_class_peek_parent (klass); \ - type_name##_class_init ((TypeName##Class*) klass); \ + return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ } \ +\ GType \ type_name##_get_type (void) \ { \ @@ -237,6 +242,10 @@ type_name##_register_type (GTypeModule *type_module) \ g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ } +#define G_ADD_PRIVATE_DYNAMIC(TypeName) { \ + TypeName##_private_offset = sizeof (TypeNamePrivate); \ +} + GLIB_AVAILABLE_IN_ALL GType g_type_module_get_type (void) G_GNUC_CONST; GLIB_AVAILABLE_IN_ALL