Re: Chaining of dispose and finalize



Tristan Van Berkom wrote:
Russell Shaw wrote:
[...]

But how do i do that when g_object_real_dispose() and g_object_finalize()
are both declared static in gobject.c ?


the gobject code always keeps a version of the class intact
(for quick reference at instantiation and for chaining):

parent_class =
    GTKTT_ANIM_CLASS (g_type_class_peek_parent
                     (musical_class));

Usualy people keep a global like this assigned at class_init time
in order to avoid multiple calls.

Hi,
I understand that, and is what i do. What i mean is that most
objects do in class_init something like:

  gobject_class->dispose=myobject_dispose;

But this makes the original dispose code in gobject
inaccessible. Same for gobject_class->dispose=myobject_finalize.

Obviously something very basic i'm missing here;)


Maybe i should record the parent functions in static pointers
before overiding them:


static gpointer parentdispose;
static gpointer parentfinalize;

myobject_class_init(MyObjectClass *klass){
...
  parentdispose=G_OBJECT_CLASS(parent_class)->dispose;
  parentfinalize=G_OBJECT_CLASS(parent_class)->finalize;

  G_OBJECT_CLASS(parent_class)->dispose=myobject_dispose;
  G_OBJECT_CLASS(parent_class)->finalize=myobject_finalize;
...
}

myobject_dispose(MyObject *myobject)
{
  if(myobject->dispose_has_run)
    return;
  myobject->dispose_has_run=TRUE;

  parentdispose(parent_object);
}

myobject_finalize(MyObject *myobject)
{
  parentfinalize(parent_object);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]