+ out_printf(out, "static void ___add_interfaces(GType type)\n{\n");
+ add_interface_infos(c, TRUE);
+
+ for (li = c->interfaces; li; li = li->next) {
+ char *type = make_pre_macro(li->data, "TYPE");
+ char *name = replace_sep(li->data, '_');
+
+ out_printf(out, "\tg_type_add_interface_static\n"
+ "\t\t( type\n"
+ "\t\t, %s\n"
+ "\t\t, &%s_info\n"
+ "\t\t);\n",
+ type, name);
+
+ g_free(name);
+ g_free(type);
+ }
+
+ out_printf(out, "}\n\n");
+}
+
+static void
+define_dynamic_add_interfaces(Class *c)
+{
+ GList *li;
+
+ if (!c->interfaces)
+ return;
+
+ out_printf(out, "static void ___add_interfaces"
+ "(GTypeModule *type_module, GType type)\n"
+ "{\n");
+ add_interface_infos(c, FALSE);
+
+ /*
+ * 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, "\tstruct _ModuleInterfaceInfo {\n"
+ "\t\tgboolean loaded;\n"
+ "\t\tGType instance_type;\n"
+ "\t\tGType interface_type;\n"
+ "\t\tGInterfaceInfo info;\n"
+ "\t} *modinfo;\n");
+
+ for (li = c->interfaces; li; li = li->next) {
+ char *type = make_pre_macro(li->data, "TYPE");
+ char *name = replace_sep(li->data, '_');
+
+ out_printf(out, "\n"
+ "\tmodinfo = g_malloc(sizeof *modinfo);\n"
+ "\tmodinfo->loaded = TRUE;\n"
+ "\tmodinfo->instance_type = type;\n"
+ "\tmodinfo->interface_type = %s;\n"
+ "\tmodinfo->info = %s_info;\n"
+ "\tg_type_add_interface_dynamic\n"
+ "\t\t( modinfo->instance_type\n"
+ "\t\t, modinfo->interface_type\n"
+ "\t\t, G_TYPE_PLUGIN(type_module)\n"
+ "\t\t);\n"
+ "\ttype_module->interface_infos = g_slist_prepend\n"
+ "\t\t( type_module->interface_infos\n"
+ "\t\t, modinfo\n"
+ "\t\t);\n",
+ type, name);
+
+ g_free(name);
+ g_free(type);