+static void
+add_dynamic_interfaces(void)
+{
+ GList *li = ((Class *)class)->interfaces;
+
+ if (li) {
+ /*
+ * Hack to work around bug in g_type_module_add_interface,
+ * which will fail to add an interface to types that derive
+ * from something that also implements the same interface.
+ *
+ * The actual GType system does not have any such problem,
+ * and the GTypeModule implementation details relied upon
+ * here have not changed once since the feature was first
+ * implemented almost 20 years ago.
+ */
+ out_printf(out, "\t\tstruct _ModuleInterfaceInfo {\n"
+ "\t\t\tgboolean loaded;\n"
+ "\t\t\tGType instance_type;\n"
+ "\t\t\tGType interface_type;\n"
+ "\t\t\tGInterfaceInfo info;\n"
+ "\t\t} *modinfo;\n");
+ }
+
+ for (; li; li = li->next) {
+ char *name = replace_sep(li->data, '_');
+ char *type = make_pre_macro(li->data, "TYPE");
+
+ out_printf(out, "\n"
+ "\t\tmodinfo = g_malloc(sizeof *modinfo);\n"
+ "\t\tmodinfo->loaded = TRUE;\n"
+ "\t\tmodinfo->instance_type = %s_type_id;\n"
+ "\t\tmodinfo->interface_type = %s;\n"
+ "\t\tmodinfo->info = %s_info;\n"
+ "\t\tg_type_add_interface_dynamic\n"
+ "\t\t\t( modinfo->instance_type\n"
+ "\t\t\t, modinfo->interface_type\n"
+ "\t\t\t, G_TYPE_PLUGIN(type_module)\n"
+ "\t\t\t);\n"
+ "\t\ttype_module->interface_infos = g_slist_prepend\n"
+ "\t\t\t( type_module->interface_infos\n"
+ "\t\t\t, modinfo\n"
+ "\t\t\t);\n", funcbase, type, name);
+
+ g_free(type);
+ g_free(name);
+ }
+}
+