Re: Another version of instance-private-data [really!]
- From: Tim Janik <timj gtk org>
- To: Owen Taylor <otaylor redhat com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: Another version of instance-private-data [really!]
- Date: Mon, 10 Mar 2003 03:27:04 +0100 (CET)
On Wed, 5 Mar 2003, Owen Taylor wrote:
> On Tue, 2003-03-04 at 23:04, Tim Janik wrote:
> > > +
> > > + return (gpointer)((gchar *)instance + ALIGN_STRUCT (offset));
> >
> > glib has a macro for this, so the code should read:
> >
> > return G_STRUCT_MEMBER_P (instance, offset);
> > (ALIGN_STRUCT() not needed with the above if (parent_node) branch)
>
> OK, changed.
>
> New patch attached. I've also fixed some bugs in the preallocs > 0 case;
> there is a subtlety there ... if instance size is, say 8 and private
> size 1, then it's fine to malloc 9 bytes if we are malloc'ing a single
> instance, but if we have an array of structures, then we need to malloc
> ALIGN_STRUCT(9) bytes for each or the later elements in the array won't
> be properly aligned.
ah, good catch, didn't occour to me.
> Index: docs/reference/gobject/tmpl/gtype.sgml
> ===================================================================
> RCS file: /cvs/gnome/glib/docs/reference/gobject/tmpl/gtype.sgml,v
> retrieving revision 1.22
> diff -u -p -r1.22 gtype.sgml
> --- docs/reference/gobject/tmpl/gtype.sgml 7 Feb 2003 22:08:53 -0000 1.22
> +++ docs/reference/gobject/tmpl/gtype.sgml 5 Mar 2003 16:32:10 -0000
> @@ -462,6 +462,17 @@ Returns the interface structure for inte
> @c_type: The corresponding C type of @g_type.
>
>
> +<!-- ##### MACRO G_TYPE_INSTANCE_GET_PRIVATE ##### -->
> +<para>
> +Gets the private structure for a particular type.
> +The private structure must have added from the class_init
wouldn't "must have been registered in the class_init"... here
sound better?
> +function with g_type_class_add_private().
> +</para>
> +
> + 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.
> +
> ===================================================================
> RCS file: /cvs/gnome/glib/gobject/testgobject.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 testgobject.c
> --- gobject/testgobject.c 12 Oct 2002 20:04:58 -0000 1.6
> +++ gobject/testgobject.c 5 Mar 2003 16:32:10 -0000
> @@ -126,8 +126,10 @@ iface_print_string (TestIface *tiobj,
> #define TEST_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TEST_TYPE_OBJECT))
> #define TEST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_OBJECT))
> #define TEST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_OBJECT, TestObjectClass))
> -typedef struct _TestObject TestObject;
> -typedef struct _TestObjectClass TestObjectClass;
> +#define TEST_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_OBJECT, TestObjectPrivate))
> +typedef struct _TestObject TestObject;
> +typedef struct _TestObjectClass TestObjectClass;
> +typedef struct _TestObjectPrivate TestObjectPrivate;
[...]
> -typedef struct _TestObject DerivedObject;
> -typedef struct _TestObjectClass DerivedObjectClass;
> +#define DERIVED_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DERIVED_TYPE_OBJECT, DerivedObjectPrivate))
> +typedef struct _TestObject DerivedObject;
> +typedef struct _TestObjectClass DerivedObjectClass;
> +typedef struct _DerivedObjectPrivate DerivedObjectPrivate;
[...]
the rest looks pretty good to me now. and thanks for extending
the test case to check for private data at multiple inheritance
levels.
>
> Regards,
> Owen
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]