Skip to content

girepository: Rearrange type hierarchy and add type casting and checking macros

Philip Withnall requested to merge pwithnall/glib:3216-girepository-casting into main

(This is based on !3833 (merged), so not all the commits in this MR need to be reviewed.)

This MR rearranges the type hierarchy in libgirepository so that it matches what was expected at runtime previously (when all the *Info types were aliases of each other). In particular:

  • GICallableInfo is now abstract, and GIFunctionInfo, GICallbackInfo, GISignalInfo and GIVFuncInfo are subtypes of it (previously they were all just plain subtypes of GIBaseInfo)
  • GIRegisteredTypeInfo is now abstract, and GIStructInfo, GIUnionInfo, GIEnumInfo, GIObjectInfo, GIInterfaceInfo and GIBoxedInfo are subtypes of it (similarly)
  • GIFlagsInfo now exists as a subtype of GIEnumInfo
  • GIBoxedInfo now exists as a tag type

One question I was wondering about was whether it makes more sense to have GICallableInfo and/or GIRegisteredTypeInfo as abstract base types, or as interfaces. I’ve gone with abstract base types in this MR because it was straightforward.

In addition, type checking macros (GI_IS_FUNCTION_INFO()) and casting macros (GI_FUNCTION_INFO()) have been added, and conform to GObject/GType conventions.

Also, gi_base_info_{ref,unref}() have been modified to take a void* argument rather than GIBaseInfo*. This should remove the need for casting when calling them, as they are called often. (This is the same as is done with g_object_{ref,unref}().)

Overall, this should fix #3216 (closed) by reducing the need for casting, and making casting more robust (with runtime checks) when it is needed.

It also aligns the GType type hierarchy with the old GIInfoType hierarchy. I may remove the latter in a follow-up MR (basically: drop gi_base_info_get_info_type() in favour of using GTypes instead), but I’ve not done that in this MR to avoid it getting too large.

Finally, it includes a few new tests to smoketest the changes. The tests are not comprehensive though; there’s a good week of work in writing a comprehensive set of tests for libgirepository.

Helps: #3155 (closed) Closes #3216 (closed)

Merge request reports