Re: g_type_query necessary



Oskar Liljeblad <osk hem passagen se> writes:

> On Saturday, September 16, 2000 at 15:20, Owen Taylor wrote:
> > > A g_type_query (as in gtk_type_query) is necessary for the Java bindings
> > > of GTK+. This is because the size of a class is used when replacing the
> > > class structure (to allow subclassing).
> > 
> > (Though I don't really understand how you can subclass the class
> > structure very well without knowing details about the class like where
> > the function pointers for the virtual functions are.) 
> 
> I know those details, at least they are hard-coded into the Java
> classes. Using something like sizeof(GtkXXXClass) is probably not
> good, since some Gtk classes may store extra data outside the
> class struct (yielding class_size != sizeof(GtkXXXClass)).

If a class did that you wouldn't be able to derive from the class in C!
 
> By the way, I am assuming that once you know the class size, you
> can do something like this
> 
>   GObject* obj;
>   GTypeClass* oldclass = obj->g_type_instance->g_class;
>   GTypeClass* newclass = g_malloc(class_size);
> 
>   memcpy(newclass, oldclass, class_size);
>   obj->g_type_instance->g_class = newclass;
> 
> without creating a new type for the class. Is this OK?

Well, no. What are you trying to do that you can't do in
a more normal fashion?

(Nobody should assign to the class pointer for an instance
except for the GObject internals; note that with gobject
classes are even refcounted so they can be unloaded.)

Regards,
                                        Owen




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