GTypeInfo.instance_init vs. GObject.constructor



If I'm trying to create a type derived from GObject, and I'm not clear on
which of the instantiation/destruction methods I should be using for what.

I've looked at GtkObject for reference, but I still don't see why the
things that are done in gtk_object_init (which gets registered as
GTypeInfo.instance_init) are done there as opposed to in
GObject.constructor, and vice versa.

Also, I'm not clear on what should be done in dispose and what in finalize
and why.

Finally, I don't understand why this (from gobject.c, in
g_object_last_unref()) is safe:

  if (object->ref_count == 1)	/* may have been re-referenced meanwhile
*/
    G_OBJECT_GET_CLASS (object)->dispose (object);

#ifdef	G_ENABLE_DEBUG
  if (g_trap_object_ref == object)
    G_BREAKPOINT ();
#endif	/* G_ENABLE_DEBUG */

  object->ref_count -= 1;
  if (object->ref_count == 0)	/* may have been re-referenced meanwhile
*/
    {
      g_signal_handlers_destroy (object);
      g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
      G_OBJECT_GET_CLASS (object)->finalize (object);

If there is a possibility of object->ref_count being incremented while
g_object_last_unref() runs, shouldn't there be a lock or somehing after
the last check and before the finalize() call?

Thanks to anyone wh ocan enlighten me,

Britton Kerin
__
GNU GPL: "The Source will be with you... always."





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