From: Stefan Kost Date: Wed, 22 Feb 2006 14:41:14 +0000 (+0000) Subject: add @since: for _add_private, _GET_PRIVATE fix example to use ->priv and X-Git-Tag: GLIB_2_10_0~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee57c76a435787f314d8434266304d4e00bd2467;p=platform%2Fupstream%2Fglib.git add @since: for _add_private, _GET_PRIVATE fix example to use ->priv and * gobject/tmpl/gtype.sgml: add @since: for _add_private, _GET_PRIVATE * gobject/tut_gobject.xml: fix example to use ->priv and not ->private * gobject/tut_howto.xml: fix g_type_class_add_private example --- diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index c81f452..d4e1516 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,12 @@ +2006-02-22 Stefan Kost + + * gobject/tmpl/gtype.sgml: + add @since: for _add_private, _GET_PRIVATE + * gobject/tut_gobject.xml: + fix example to use ->priv and not ->private + * gobject/tut_howto.xml: + fix g_type_class_add_private example + 2006-02-14 Tor Lillqvist * glib/tmpl/iochannels.sgml: Document some Windows-specific issues. diff --git a/docs/reference/gobject/tmpl/gtype.sgml b/docs/reference/gobject/tmpl/gtype.sgml index 9ca599c..a2cb496 100644 --- a/docs/reference/gobject/tmpl/gtype.sgml +++ b/docs/reference/gobject/tmpl/gtype.sgml @@ -240,10 +240,6 @@ A structure that provides information to the type system which is used specifically for managing interface types. -@interface_init: Location of the function that initializes the interface. -@interface_finalize: Location of the function that finalizes the interface. -@interface_data: Location of user data passed to the @interface_init and - @interface_finalize functions (optional). @@ -511,6 +507,7 @@ This macro should only be used in type implementations. @instance: the instance of a type deriving from @private_type. @g_type: the type identifying which private data to retrieve. @c_type: The C type for the private structure. +@Since: 2.4 @@ -827,6 +824,7 @@ my_object_get_some_field (MyObject *my_object) @g_class: class structure for an instantiatable type @private_size: size of private structure. +@Since: 2.4 diff --git a/docs/reference/gobject/tut_gobject.xml b/docs/reference/gobject/tut_gobject.xml index 7a76154..e790251 100644 --- a/docs/reference/gobject/tut_gobject.xml +++ b/docs/reference/gobject/tut_gobject.xml @@ -547,14 +547,14 @@ maman_bar_set_property (GObject *object, switch (property_id) { case MAMAN_BAR_CONSTRUCT_NAME: { - g_free (self->private->name); - self->private->name = g_value_dup_string (value); - g_print ("maman: %s\n",self->private->name); + g_free (self->priv->name); + self->priv->name = g_value_dup_string (value); + g_print ("maman: %s\n",self->priv->name); } break; case MAMAN_BAR_PAPA_NUMBER: { - self->private->papa_number = g_value_get_uchar (value); - g_print ("papa: %u\n",self->private->papa_number); + self->priv->papa_number = g_value_get_uchar (value); + g_print ("papa: %u\n",self->priv->papa_number); } break; default: @@ -574,11 +574,11 @@ maman_bar_get_property (GObject *object, switch (property_id) { case MAMAN_BAR_CONSTRUCT_NAME: { - g_value_set_string (value, self->private->name); + g_value_set_string (value, self->priv->name); } break; case MAMAN_BAR_PAPA_NUMBER: { - g_value_set_uchar (value, self->private->papa_number); + g_value_set_uchar (value, self->priv->papa_number); } break; default: diff --git a/docs/reference/gobject/tut_howto.xml b/docs/reference/gobject/tut_howto.xml index 03e5c2d..6212b2b 100644 --- a/docs/reference/gobject/tut_howto.xml +++ b/docs/reference/gobject/tut_howto.xml @@ -168,15 +168,17 @@ struct _MamanBar { The private structure is then defined in the .c file, instantiated in the object's init function and destroyed in the object's finalize function. -static void maman_bar_finalize(GObject *object) { +static void +maman_bar_finalize (GObject *object) { MamanBar *self = MAMAN_BAR (object); /* do stuff */ g_free (self->priv); } -static void maman_bar_init(GTypeInstance *instance, gpointer g_class) { +static void +maman_bar_init (GTypeInstance *instance, gpointer g_class) { MamanBar *self = MAMAN_BAR (instance); - self->priv = g_new0(MamanBarPrivate,1); + self->priv = g_new0 (MamanBarPrivate,1); /* do stuff */ } @@ -184,10 +186,14 @@ static void maman_bar_init(GTypeInstance *instance, gpointer g_class) { A similar alternative, available since Glib version 2.4, is to define a private structure in the .c file, - declare it as a private structure in class_init using - g_type_class_add_private and declare a macro to allow convenient access to this structure. + declare it as a private structure in maman_bar_class_init using + g_type_class_add_private. + Instead of allocating memory in maman_bar_init a pointer to the private memory area is + stored in the instance to allow convenient access to this structure. A private structure will then be attached to each newly created object by the GObject system. You dont need to free or allocate the private structure, only the objects or pointers that it may contain. + Another advantage of this to the previous version is that is lessens memory fragmentation, + as the public and private parts of the instance memory are allocated at once. typedef struct _MamanBarPrivate MamanBarPrivate; @@ -195,8 +201,6 @@ struct _MamanBarPrivate { int private_field; }; -#define MAMAN_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MAMAN_BAR_TYPE, MamanBarPrivate)) - static void maman_bar_class_init (MamanBarClass *klass) { @@ -205,12 +209,11 @@ maman_bar_class_init (MamanBarClass *klass) ... } -static int -maman_bar_get_private_field (MamanBar *self) -{ - MamanBarPrivate *priv = MAMAN_BAR_GET_PRIVATE (self); - - return priv->private_field; +static void +maman_bar_init (GTypeInstance *instance, gpointer g_class) { + MamanBar *self = MAMAN_BAR (instance); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MAMAN_BAR_TYPE, MamanBarPrivate); + /* do stuff */ }