"%s_get_type (void)\n"
"{\n"
"\tstatic GType type = 0;\n\n"
- "\tif (type == 0) {\n"
+ "\tif ___GOB_UNLIKELY(type == 0) {\n"
"\t\tstatic const GTypeInfo info = {\n"
"\t\t\tsizeof (%sClass),\n"
"\t\t\t(GBaseInitFunc) NULL,\n"
"%s_get_type (void)\n" /* 1 */
"{\n"
"\tstatic GType type = 0;\n\n"
- "\tif (type == 0) {\n"
+ "\tif ___GOB_UNLIKELY(type == 0) {\n"
"\t\tstatic const GTypeInfo info = {\n"
"\t\t\tsizeof (%sClass),\n" /* 2 */
"\t\t\t(GBaseInitFunc) NULL,\n"
! is_none) {
GList *gl, *al;
const char *sep = "";
- out_printf(out, "\tif(");
+ out_printf(out, "\tif ___GOB_UNLIKELY(");
if(strcmp(m->gtktypes->data, "NONE") != 0) {
out_printf(out, "%s sizeof(", sep);
print_type(out, m->mtype, FALSE);
}
}
+static void
+clear_signal_args (Method *m)
+{
+ GList *li;
+ int i;
+
+ out_printf (out, "\n\tg_value_unset (&___param_values[0]);\n");
+
+ if (m->args->next == NULL)
+ return;
+
+ for (li = m->args->next, i = 1;
+ li != NULL;
+ li = li->next, i++) {
+ out_printf (out,
+ "\tg_value_unset (&___param_values[%d]);\n", i);
+ }
+}
+
static char *
get_arg_names_for_macro (Method *m)
{
g_free (s);
+ clear_signal_args (m);
+
if (strcmp (m->gtktypes->data, "NONE") != 0) {
char *cast = g_strdup (get_cast (m->gtktypes->data, FALSE));
char *getfunc;
+ /* Hack because glib is very very braindead */
+ gboolean do_dup =
+ (strcmp ((char *)m->gtktypes->data, "STRING") == 0 ||
+ strcmp ((char *)m->gtktypes->data, "BOXED") == 0 ||
+ strcmp ((char *)m->gtktypes->data, "OBJECT") == 0 ||
+ strcmp ((char *)m->gtktypes->data, "PARAM") == 0);
if (strcmp (m->gtktypes->data, "UNICHAR") == 0)
/* hack because glib is braindamaged */
getfunc = g_strdup ("g_value_get_uint");
else
- getfunc = g_strdup_printf ("g_value_get_%s",
+ getfunc = g_strdup_printf ("g_value_%s_%s",
+ do_dup ? "dup" : "get",
(char *)m->gtktypes->data);
g_strdown (getfunc);
if (cast == NULL)
cast = get_type (m->mtype, TRUE);
- out_printf (out, "\n\treturn (%s) %s (&___return_val);\n",
+ out_printf (out,
+ "\n\t{\n"
+ "\t\t");
+ print_type (out, m->mtype, TRUE);
+ out_printf (out,
+ " ___ret = (%s) %s (&___return_val);\n"
+ "\t\tg_value_unset (&___return_val);\n"
+ "\t\treturn ___ret;\n"
+ "\t}\n",
cast, getfunc);
g_free (cast);
" */\n");
if ( ! overrode_get_type) {
- out_printf (outh, "GType\t%s_get_type\t(void);", funcbase);
+ out_printf (outh, "GType\t%s_get_type\t(void);\n", funcbase);
}
for(li = c->nodes; li != NULL; li = li->next) {
out_printf (out, "#define selfp (self->_priv)\n\n");
}
+static void
+print_more_useful_macros (void)
+{
+ if (no_gnu) {
+ out_printf (out, "#define ___GOB_LIKELY(expr) (expr)\n");
+ out_printf (out, "#define ___GOB_UNLIKELY(expr) (expr)\n");
+ } else {
+ out_printf (out, "#ifdef G_LIKELY\n");
+ out_printf (out, "#define ___GOB_LIKELY(expr) G_LIKELY(expr)\n");
+ out_printf (out, "#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)\n");
+ out_printf (out, "#else /* ! G_LIKELY */\n");
+ out_printf (out, "#define ___GOB_LIKELY(expr) (expr)\n");
+ out_printf (out, "#define ___GOB_UNLIKELY(expr) (expr)\n");
+ out_printf (out, "#endif /* G_LIKELY */\n");
+ }
+}
+
static void
print_file_comments(void)
{
"GType\n%s_get_type (void)\n"
"{\n"
"\tstatic GType type = 0;\n"
- "\tif (type == 0)\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
"\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
"\treturn type;\n"
"}\n\n",
"GType\n%s_get_type (void)\n"
"{\n"
"\tstatic GType type = 0;\n"
- "\tif (type == 0)\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
"\t\ttype = g_flags_register_static (\"%s\", _%s_values);\n"
"\treturn type;\n"
"}\n\n",
"GType\n%s_get_type (void)\n"
"{\n"
"\tstatic GType type = 0;\n"
- "\tif (type == 0)\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
"\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
"\treturn type;\n"
"}\n\n",
print_includes();
+ print_more_useful_macros ();
+
for (li = nodes; li != NULL; li = li->next) {
Node *node = li->data;
if (node->type == CCODE_NODE) {