mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-13 09:23:13 +02:00
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.
This commit is contained in:
parent
d2bb019533
commit
ca6b93d093
@ -180,11 +180,16 @@ static void type_name##_class_init (TypeName##Class *klass); \
|
|||||||
static void type_name##_class_finalize (TypeName##Class *klass); \
|
static void type_name##_class_finalize (TypeName##Class *klass); \
|
||||||
static gpointer type_name##_parent_class = NULL; \
|
static gpointer type_name##_parent_class = NULL; \
|
||||||
static GType type_name##_type_id = 0; \
|
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); \
|
return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
|
||||||
type_name##_class_init ((TypeName##Class*) klass); \
|
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
GType \
|
GType \
|
||||||
type_name##_get_type (void) \
|
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); \
|
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
|
GLIB_AVAILABLE_IN_ALL
|
||||||
GType g_type_module_get_type (void) G_GNUC_CONST;
|
GType g_type_module_get_type (void) G_GNUC_CONST;
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user