Feedback on gobject-introspection: Casting to and from GIBaseInfo*
I've been trying out the new g-i API in GLib. Compared with g-i 1.0 there is a lot more manual casting involved.
Previously, all of the GIFooInfo
types were aliases of GIBaseInfo
, so they could be used interchangeably. Now they are aliases of distinct, opaque structs.
This requires a lot more manual casting in order to use the API. For example:
GIFunctionInfo *func_info;
func_info = (GIFunctionInfo *) gi_repository_get_info (repo, namespace, idx);
g_print("%s\n", gi_base_info_get_name ((GIBaseInfo *) func_info);
gi_callable_info_invoke ((GICallableInfo *) func_info, ...);
g_clear_pointer ((GIBaseInfo **) &func_info, gi_base_info_unref);
The old way:
GIFunctionInfo *func_info;
func_info = g_irepository_get_info (repo, namespace, idx);
g_print("%s\n", g_base_info_get_name (func_info);
g_callable_info_invoke (func_info, ...);
g_clear_pointer (&func_info, g_base_info_unref);
It would be nice to at least have casting macros like GObject types do, with runtime checks when casting to a more specific info type. That is, GI_BASE_INFO()
as well as pairs of GI_FUNCTION_INFO()
/GI_IS_FUNCTION_INFO()
for each info type.
Even nicer would be to allow any info type pointer to decay to GIBaseInfo *
automatically, but I'm not sure if that's possible without the types being aliases of each other.