[glib] gdbus-codegen: Don't generate invalid GObject property names
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gdbus-codegen: Don't generate invalid GObject property names
- Date: Fri, 6 Jul 2012 13:26:53 +0000 (UTC)
commit d72116d8b7c802895be6b02093342fd9e770813d
Author: David Zeuthen <zeuthen gmail com>
Date: Fri Jul 6 09:19:48 2012 -0400
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 <zeuthen gmail com>
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 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/dbustypes.py b/gio/gdbus-2.0/codegen/dbustypes.py
index 110ca9f..5fdb9a1 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 9cf7367..b4cfbc8 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 b78def0..9c6f957 100644
--- a/gio/tests/test-codegen.xml
+++ b/gio/tests/test-codegen.xml
@@ -475,4 +475,8 @@
</method>
</interface>
+ <interface name="Naming">
+ <property name="Type" type="i" access="readwrite"/>
+ </interface>
+
</node>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]