On Sat, 2007-10-27 at 14:07 +0100, Phil Lello wrote: > According to the GObject tutorial, chaining-up in > constructor/dispose/finalize code should be handled as follows: > > static void > b_method_to_call (B *obj, int a) > { > BClass *klass; > AClass *parent_class; > klass = B_GET_CLASS (obj); > parent_class = g_type_class_peek_parent (klass); > > /* do stuff before chain up */ > parent_class->method_to_call (obj, a); > /* do stuff after chain up */ > }
nope, it should be handled like this for finalize and dispose: static void c_object_finalize (GObject *gobject) { CObject *c_object = C_OBJECT (gobject); /* free data or break reference cycles if this is a ::dispose */ G_OBJECT_CLASS (c_object_parent_class)->finalize (gobject); } where "c_object_parent_class" is defined using the G_DEFINE_TYPE() macro (and its relatives, like G_DEFINE_TYPE_WITH_CODE() etc.). as for the constructor implementation, the rare times you need it, it should be: static GObject * c_object_constructor (GType gtype, guint n_params, GObjectConstructParam *params) { GObjectClass *parent_class; GObject *retval; CObject *c_object; parent_class = g_type_class_peek_parent (c_object_parent_class); retval = parent_class->constructor (gtype, n_params, params); c_object = C_OBJECT (retval); /* construct your object's instance */ return retval; } unfortunately, the tutorial is lagging behind all the utility code that has been added in the past few years to reduce the boilerplate (and avoid bugs). the real mission, if you decide to accept it, is to open one of the newly added classes in GTK+, like GtkRecentAction or GtkBuilder, and adapt the code in the tutorial to use the same patterns used in those. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net _______________________________________________ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list