Skip to content

RFC: gtype: Introduce G_DECLARE_OPAQUE_TYPE()

Jonas Ådahl requested to merge jadahl/glib:wip/opaque-type into master

This works like G_DECLARE_FINAL_TYPE() and G_DECLARE_DERIVABLE_TYPE() except it expects both the instance struct and the class struct to be defined manually in the C file.

The motivation for this is to expose a non-derivable type as API, but without exposing the private type class details.

For example the following:

  • A base class MyBase with a MyBaseClass declared using G_DECLARE_DERIVABLE_TYPE(), with a MyBaseClass with private vfuncs.
  • A class MyBaseFoo that inherits MyBase and implements the MyBaseClass vfuncs.
  • A my_base_foo_new() which constructs a MyBaseFoo instance.

With G_DECLARE_OPAQUE_TYPE() one can declare the MyBaseFoo in an installed header file, without needing to expose MyBaseClass, which would be needed if one would use G_DECLARE_FINAL_TYPE().


Just some experiment I did; I want to avoid exposing the guts of the type class tree but expose sub types via.

Merge request reports