From f2649abe84a3a8af2dc5ab115f0410068ee4518f Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Tue, 2 May 2006 13:00:52 +0000 Subject: [PATCH] split up G_DEFINE_*TYPE macro definitions so C CODE arguments are not Tue May 2 14:51:03 2006 Tim Janik * gtype.h: split up G_DEFINE_*TYPE macro definitions so C CODE arguments are not passed on to nested macro calls. patch mostly courtesy of Behdad Esfahbod, fixes #337128. --- gobject/ChangeLog | 6 ++++++ gobject/gtype.h | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gobject/ChangeLog b/gobject/ChangeLog index 521ddde30..621d50182 100644 --- a/gobject/ChangeLog +++ b/gobject/ChangeLog @@ -1,3 +1,9 @@ +Tue May 2 14:51:03 2006 Tim Janik + + * gtype.h: split up G_DEFINE_*TYPE macro definitions so C CODE arguments + are not passed on to nested macro calls. patch mostly courtesy of Behdad + Esfahbod, fixes #337128. + 2006-04-23 Matthias Clasen * gobject.symbols: Fix a typo. diff --git a/gobject/gtype.h b/gobject/gtype.h index 828aebcf2..1efc36754 100644 --- a/gobject/gtype.h +++ b/gobject/gtype.h @@ -333,10 +333,11 @@ gpointer g_type_instance_get_private (GTypeInstance *instance, * example: G_DEFINE_TYPE_WITH_CODE (GtkGadget, gtk_gadget, GTK_TYPE_WIDGET, * g_print ("GtkGadget-id: %lu\n", g_define_type_id)); */ -#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) -#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, _C_) -#define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {}) -#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, _C_) +#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) +#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() +#define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {}) +#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() +#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() /* convenience macro to ease interface addition in the CODE * section of G_DEFINE_TYPE_WITH_CODE() (this macro relies on @@ -353,7 +354,7 @@ gpointer g_type_instance_get_private (GTypeInstance *instance, g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ } -#define G_DEFINE_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \ +#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \ \ static void type_name##_init (TypeName *self); \ static void type_name##_class_init (TypeName##Class *klass); \ @@ -378,10 +379,13 @@ type_name##_get_type (void) \ sizeof (TypeName), \ (GInstanceInitFunc)type_name##_init, \ (GTypeFlags) flags); \ - { CODE ; } \ - } \ - return g_define_type_id; \ -} + { /* custom code follows */ +#define _G_DEFINE_TYPE_EXTENDED_END() \ + /* following custom code */ \ + } \ + } \ + return g_define_type_id; \ +} /* closes type_name##_get_type() */ /* --- protected (for fundamental type implementations) --- */