From d03727c07defcf4aaec3de3382f0c00c207c61dc Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 8 Feb 2024 23:38:05 +0000 Subject: [PATCH] girwriter: Stop using gi_base_info_get_info_type() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it’s an internal API which `girwriter.c` has access to, it’s not available inside `libgirepository-internals.so`. This wasn’t spotted before commit 343027d5d landed because none of the existing users of `libgirepository-internals.so` use the relevant code in `girwriter.c`, so it got compiled out (`libgirepository-internals.so` is statically linked and can be optimised like this). Now that `gi-decompile-repository` uses the relevant code from `girwriter.c`, the problem is obvious and `gi-decompile-repository` fails to link. Fix that by no longer using `gi_base_info_get_info_type()` in `girwriter.c`. These are changes which would have eventually been made anyway in issue #3253. Signed-off-by: Philip Withnall Helps: #3253 --- girepository/girwriter.c | 66 +++++++++++++++------------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/girepository/girwriter.c b/girepository/girwriter.c index 245084d5c..b00b106b5 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -167,7 +167,7 @@ xml_free (Xml *xml) static void check_unresolved (GIBaseInfo *info) { - if (gi_base_info_get_info_type (info) != GI_INFO_TYPE_UNRESOLVED) + if (!GI_IS_UNRESOLVED_INFO (info)) return; g_critical ("Found unresolved type '%s' '%s'", @@ -442,7 +442,7 @@ write_field_info (const char *ns, } interface = gi_type_info_get_interface (type); - if (interface && gi_base_info_get_info_type (interface) == GI_INFO_TYPE_CALLBACK) + if (interface != NULL && GI_IS_CALLBACK_INFO (interface)) write_callback_info (ns, (GICallbackInfo *)interface, file); else write_type_info (ns, type, file); @@ -660,7 +660,7 @@ write_struct_info (const char *ns, type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info); - if (gi_base_info_get_info_type ((GIBaseInfo *) info) == GI_INFO_TYPE_BOXED) + if (GI_IS_BOXED_INFO (info)) { xml_start_element (file, "glib:boxed"); xml_printf (file, " glib:name=\"%s\"", name); @@ -847,7 +847,7 @@ write_enum_info (const char *ns, type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info); error_domain = gi_enum_info_get_error_domain (info); - if (gi_base_info_get_info_type ((GIBaseInfo *) info) == GI_INFO_TYPE_ENUM) + if (GI_IS_ENUM_INFO (info)) xml_start_element (file, "enumeration"); else xml_start_element (file, "bitfield"); @@ -1415,45 +1415,27 @@ gi_ir_writer_write (const char *filename, for (j = 0; j < n_infos; j++) { GIBaseInfo *info = gi_repository_get_info (repository, cur_ns, j); - switch (gi_base_info_get_info_type (info)) - { - case GI_INFO_TYPE_FUNCTION: - write_function_info (ns, (GIFunctionInfo *)info, xml); - break; - case GI_INFO_TYPE_CALLBACK: - write_callback_info (ns, (GICallbackInfo *)info, xml); - break; - - case GI_INFO_TYPE_STRUCT: - case GI_INFO_TYPE_BOXED: - write_struct_info (ns, (GIStructInfo *)info, xml); - break; - - case GI_INFO_TYPE_UNION: - write_union_info (ns, (GIUnionInfo *)info, xml); - break; - - case GI_INFO_TYPE_ENUM: - case GI_INFO_TYPE_FLAGS: - write_enum_info (ns, (GIEnumInfo *)info, xml); - break; - - case GI_INFO_TYPE_CONSTANT: - write_constant_info (ns, (GIConstantInfo *)info, xml); - break; - - case GI_INFO_TYPE_OBJECT: - write_object_info (ns, (GIObjectInfo *)info, xml); - break; - - case GI_INFO_TYPE_INTERFACE: - write_interface_info (ns, (GIInterfaceInfo *)info, xml); - break; - - default: - g_error ("unknown info type %d", gi_base_info_get_info_type (info)); - } + if (GI_IS_FUNCTION_INFO (info)) + write_function_info (ns, (GIFunctionInfo *)info, xml); + else if (GI_IS_CALLBACK_INFO (info)) + write_callback_info (ns, (GICallbackInfo *)info, xml); + else if (GI_IS_STRUCT_INFO (info) || + GI_IS_BOXED_INFO (info)) + write_struct_info (ns, (GIStructInfo *)info, xml); + else if (GI_IS_UNION_INFO (info)) + write_union_info (ns, (GIUnionInfo *)info, xml); + else if (GI_IS_ENUM_INFO (info) || + GI_IS_FLAGS_INFO (info)) + write_enum_info (ns, (GIEnumInfo *)info, xml); + else if (GI_IS_CONSTANT_INFO (info)) + write_constant_info (ns, (GIConstantInfo *)info, xml); + else if (GI_IS_OBJECT_INFO (info)) + write_object_info (ns, (GIObjectInfo *)info, xml); + else if (GI_IS_INTERFACE_INFO (info)) + write_interface_info (ns, (GIInterfaceInfo *)info, xml); + else + g_error ("unknown info type %s", g_type_name (G_TYPE_FROM_INSTANCE (info))); gi_base_info_unref (info); }