+ 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);
+ }
+
+ out_printf(out, "}\n\n");
+}
+
+static void define_add_privates(Class *c)
+{
+ const char *addprivate = c->dynamic
+ ? "G_ADD_PRIVATE_DYNAMIC"
+ : "G_ADD_PRIVATE";
+
+ if (!privates)
+ return;
+
+ out_printf(out, "#ifdef %s\n"
+ "#define ___add_privates() %s(%s)\n"
+ "#else\n"
+ "#define ___add_privates()\n"
+ "#endif\n\n",
+ addprivate, addprivate, typebase);
+}
+
+static void add_type_info(void)
+{
+ out_printf(out, "\tstatic const GTypeInfo info = {\n"
+ "\t\tsizeof (%sClass),\n"
+ "\t\t(GBaseInitFunc) NULL,\n"
+ "\t\t(GBaseFinalizeFunc) NULL,\n"
+ "\t\t(GClassInitFunc) %s_class_init,\n"
+ "\t\t(GClassFinalizeFunc) NULL,\n"
+ "\t\tNULL /* class_data */,\n"
+ "\t\tsizeof (%s),\n"
+ "\t\t%d /* n_preallocs */,\n"
+ "\t\t(GInstanceInitFunc) %s_init,\n"
+ "\t\tNULL\n"
+ "\t};\n\n",
+ typebase, funcbase, typebase, prealloc, funcbase);
+}