Re: Class initialization process





On 11/7/06, David Nečas (Yeti) <yeti physics muni cz> wrote:
On Tue, Nov 07, 2006 at 06:56:41PM -0500, a dc wrote:
> I have a question regarding class initialization process. When we initialize
> and create GtkButton, it's class structure,  GtkButtonClass, needs to be
> initialized. Also its parent class structures(GtkBinClass, GtkContainerClass
> etc.) have to be initialized. Where all this class initialization take place
> in gtk+ source code? Thanks.

gtk_foo_new() creates the new object with
g_object_new(GTK_TYPE_FOO, ...);.

  GTK_TYPE_FOO is defined as gtk_foo_get_type().

  So gtk_foo_get_type() is called and it calls
  g_type_register_static() that passes the type information
  (as the class init function) to GObject.

  But before that gtk_foo_get_type() also uses
  GTK_TYPE_FOO_PARENT, so all parent type information is
  recursively registered.

Now we get into g_object_new().  It takes a reference on the
type class with g_type_class_ref().

g_type_class_ref() recursively references parent classes and
calls [an internal function that in turn calls] class_init()
method of the class.

Notes:
- Most of this of course occurs only the first time and
  subsequent uses of the type go the fast code path.
- This is just the typical case.

Yeti


Thanks Yeti.

--DC



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