GNOME Bugzilla – Bug 629080
add G_TYPE_FLAG_FINAL type flag to make un-subclassable (final) types.
Last modified: 2018-05-24 12:44:52 UTC
<ebassi> <unknown>:: Warning: Clutter: (GLibObject)BindingPool: Failed to find class structure for 'BindingPool' <walters> oh well... <ebassi> clutter-color.h:144: Warning: Clutter: clutter_param_spec_color: return value: Invalid non-constant return of bare structure or union; register as boxed type or (skip) <walters> the reason we warn is mainly because the lack of convention for interfaces <ebassi> (it returns a GParamSpec) <walters> right now we check "Iface" and "Interfaces" ebassi: well you can (skip) the latter one <ebassi> it's not an interface <walters> right <ebassi> ClutterBindingPool is a final class <walters> i can not warn but...i don't quite like having the lack of a class structure => final <ebassi> then a bunch of errors for missing wrappers <ebassi> walters: well, that's the current convention shared among gobject-based libraries <walters> can we change it? =) <ebassi> heh I knew you would say that <walters> well <ebassi> it's just - the instance struct is already opaque; if I add another opaque struct for the class, then I have to document it <walters> i'm not opposed to implementing "no class" => final, just negotiating here <ebassi> and it's just another symbol that doesn't do anything <walters> okay, i'll remove the warning <ebassi> it might even lead people to believe that they can get the pointer to the class structure using G_TYPE_INSTANCE_GET_CLASS() (which they can, but it wouldn't do them any good) it's not that I'm generally opposed, but it would have some pushback <walters> what about adding G_TYPE_FLAG_FINAL or something? <ebassi> would require having a G_DEFINE_FINAL_TYPE() and depending on glib master + 1 though it would be nicer <walters> hiding the class structure doesn't actually prevent you from subclassing, would it? <ebassi> it does because you can't use the class inside your own vtable since the compiler doesn't know the size of the struct <walters> hmm, oh right though gobject wouldn't complain if you just picked a large class size, right? we're just relying on the lack of sizeof(FooSomeClass) being unknown? <ebassi> yep <walters> i could add an annotation? FooSomeClass: (final) ? <ebassi> you could read clutter sources and do it manually, I guess yeah, a new annotation would probably be better (and maybe ask gobject devs to think about a flag for final classes as well) <walters> i'll look into adding the GType flag too but at least this way we avoid a dep on gobject+1 thanks for the discussion
<walters> hiding the class structure doesn't actually prevent you from subclassing, would it? <ebassi> it does because you can't use the class inside your own vtable since the compiler doesn't know the size of the struct Just BTW, subclassing without public instance and class structs *is* possible, and used e.g. by a11y. You just use g_type_query() to get the sizes of the parent type's instance and class structs (and use instance and class private data to extend).
I think we established that the best practise in GObject-based libraries to create "final" types is to just provide the typedefs for both instance and class structures in the header file. if we want to have a G_TYPE_FLAG_FINAL then we should re-assign this bug, as it's not really something introspection-related.
One thing G_TYPE_FLAG_FINAL might be nice for is faster type checking.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/342.