From d72116d8b7c802895be6b02093342fd9e770813d Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Fri, 6 Jul 2012 09:19:48 -0400 Subject: [PATCH] gdbus-codegen: Don't generate invalid GObject property names For a D-Bus property with name "Type" (fairly common), we used to generate a GObject property with name "type-" and C accessors get_type_() (to avoid clashing with the GType getter), set_type_() (for symmetri). However, the rules for GObject property names are fairly rigid and specifically prohibit names ending in a dash. Therefore change things so the chosen GObject property name is "type" but preserve the naming rules for the C getter and setter (for the same reasons: avoiding name clashing and symmetri). This change does break the API of generated code (but only on the GObject property level, the C symbols are not changed) but strictly speaking the behavior was undefined since "type-" was an invalid GObject property name. Also add a test case for this. Bug 679473. https://bugzilla.gnome.org/show_bug.cgi?id=679473 Signed-off-by: David Zeuthen --- gio/gdbus-2.0/codegen/dbustypes.py | 3 ++- gio/tests/gdbus-test-codegen.c | 28 ++++++++++++++++++++++++++++ gio/tests/test-codegen.xml | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gio/gdbus-2.0/codegen/dbustypes.py b/gio/gdbus-2.0/codegen/dbustypes.py index 110ca9f9c..5fdb9a169 100644 --- a/gio/gdbus-2.0/codegen/dbustypes.py +++ b/gio/gdbus-2.0/codegen/dbustypes.py @@ -333,9 +333,10 @@ class Property: if overridden_name: name = overridden_name self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_') + self.name_hyphen = self.name_lower.replace('_', '-') + # don't clash with the GType getter, e.g.: GType foo_bar_get_type (void); G_GNUC_CONST if self.name_lower == 'type': self.name_lower = 'type_' - self.name_hyphen = self.name_lower.replace('_', '-') # recalculate arg self.arg.annotations = self.annotations diff --git a/gio/tests/gdbus-test-codegen.c b/gio/tests/gdbus-test-codegen.c index 9cf73675e..b4cfbc865 100644 --- a/gio/tests/gdbus-test-codegen.c +++ b/gio/tests/gdbus-test-codegen.c @@ -2321,6 +2321,33 @@ test_interface_stability (void) /* ---------------------------------------------------------------------------------------------------- */ +/* property naming + * + * - check that a property with name "Type" is mapped into g-name "type" + * with C accessors get_type_ (to avoid clashing with the GType accessor) + * and set_type_ (for symmetri) + * (see https://bugzilla.gnome.org/show_bug.cgi?id=679473 for details) + * + * - (could add more tests here) + */ + +static void +test_property_naming (void) +{ + gpointer c_getter_name = foo_igen_naming_get_type_; + gpointer c_setter_name = foo_igen_naming_set_type_; + FooiGenNaming *skel; + + (void) c_getter_name; + (void) c_setter_name; + + skel = foo_igen_naming_skeleton_new (); + g_assert (g_object_class_find_property (G_OBJECT_GET_CLASS (skel), "type") != NULL); + g_object_unref (skel); +} + +/* ---------------------------------------------------------------------------------------------------- */ + int main (int argc, char *argv[]) @@ -2335,6 +2362,7 @@ main (int argc, g_test_add_func ("/gdbus/codegen/annotations", test_annotations); g_test_add_func ("/gdbus/codegen/interface_stability", test_interface_stability); g_test_add_func ("/gdbus/codegen/object-manager", test_object_manager); + g_test_add_func ("/gdbus/codegen/property-naming", test_property_naming); ret = g_test_run(); diff --git a/gio/tests/test-codegen.xml b/gio/tests/test-codegen.xml index b78def038..9c6f9577e 100644 --- a/gio/tests/test-codegen.xml +++ b/gio/tests/test-codegen.xml @@ -475,4 +475,8 @@ + + + +