mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
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>
This commit is contained in:
parent
2a87010831
commit
d72116d8b7
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
@ -475,4 +475,8 @@
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
<interface name="Naming">
|
||||
<property name="Type" type="i" access="readwrite"/>
|
||||
</interface>
|
||||
|
||||
</node>
|
||||
|
Loading…
Reference in New Issue
Block a user