X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/9b591a326d98245379213aecaf39d1f44f4ff5a7..c3ec2de25a739b8afec1d19a950ba5bc399c1dcb:/src/main.c diff --git a/src/main.c b/src/main.c index 61125d8..783e46e 100644 --- a/src/main.c +++ b/src/main.c @@ -1252,7 +1252,19 @@ add_get_type(void) define_add_interfaces(c); - out_printf(out, "GType %s_get_type(void)\n" + out_printf(out, "#ifdef G_DEFINE_TYPE_EXTENDED\n\n" + "G_DEFINE_TYPE_EXTENDED(%s, %s, %s,\n" + "\t(GTypeFlags)%s,\n", + typebase, funcbase, pmacrotype, + c->abstract ? "G_TYPE_FLAG_ABSTRACT" : "0"); + + if (c->interfaces) + out_printf(out, "\t___add_interfaces(g_define_type_id);\n"); + + /* Fallback for GLib < 2.4 */ + out_printf(out, ");\n\n" + "#else\n\n" + "GType %s_get_type(void)\n" "{\n" "\tstatic GType type = 0;\n", funcbase); @@ -1274,7 +1286,8 @@ add_get_type(void) out_printf(out, "\t}\n\n" "\treturn type;\n" - "}\n\n"); + "}\n\n" + "#endif\n\n"); } static void @@ -1284,7 +1297,37 @@ add_dynamic_get_type(void) define_dynamic_add_interfaces(c); - out_printf(out, "static GType %s_type_id;\n\n" + /* + * G_DEFINE_DYNAMIC_TYPE_EXTENDED is usable if available, except for + * some reason it defines an xxx_register_type function with internal + * linkage. This is kind of weird so we have to work around that. + */ + out_printf(out, "#ifdef G_DEFINE_DYNAMIC_TYPE_EXTENDED\n\n" + "static void %s_class_finalize(%sClass *c) { }\n\n" + "#define %s_register_type ___register_type\n", + funcbase, typebase, funcbase); + + out_printf(out, "G_DEFINE_DYNAMIC_TYPE_EXTENDED(%s, %s, %s,\n" + "\t(GTypeFlags)%s,\n", + typebase, funcbase, pmacrotype, + c->abstract ? "G_TYPE_FLAG_ABSTRACT" : "0"); + + if (c->interfaces) { + out_printf(out, "\t___add_interfaces" + "(type_module, %s_type_id);\n", funcbase); + } + + out_printf(out, ");\n" + "#undef %s_register_type\n\n" + "void %s_register_type(GTypeModule *type_module)\n" + "{\n" + "\t___register_type(type_module);\n" + "}\n\n", + funcbase, funcbase); + + /* Fallback for GLib < 2.14 */ + out_printf(out, "#else\n\n" + "static GType %s_type_id;\n\n" "GType %s_get_type(void)\n" "{\n" "\treturn %s_type_id;\n" @@ -1313,7 +1356,8 @@ add_dynamic_get_type(void) funcbase); } - out_printf(out, "}\n\n"); + out_printf(out, "}\n\n" + "#endif\n\n"); } static void