[pygobject] Prefix names of typeless enums and flags for GType registration



commit 571e0cb246baa4ef7db179b20da6b325f358fe5b
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun Jan 27 01:22:37 2013 -0800

    Prefix names of typeless enums and flags for GType registration
    
    Prefix names given to g_flags_register_static and g_enum_register_static
    with "Py". This avoids conflicts with GTypes of the same name being
    registered later by a library which does not provide a "get-type"
    annotation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692515

 gi/gimodule.c    |   10 ++++++++--
 tests/test_gi.py |    4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index bb5c306..23b4d9b 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -111,9 +111,12 @@ _wrap_pyg_enum_register_new_gtype_and_add (PyObject *self,
         g_base_info_unref ((GIBaseInfo *) value_info);
     }
 
+    /* Obfuscate the full_name by prefixing it with "Py" to avoid conflicts
+     * with real GTypes. See: https://bugzilla.gnome.org/show_bug.cgi?id=692515
+     */
     namespace = g_base_info_get_namespace ((GIBaseInfo *) info);
     type_name = g_base_info_get_name ((GIBaseInfo *) info);
-    full_name = g_strconcat (namespace, type_name, NULL);
+    full_name = g_strconcat ("Py", namespace, type_name, NULL);
 
     /* If enum registration fails, free all the memory allocated
      * for the values array. This needs to leak when successful
@@ -227,9 +230,12 @@ _wrap_pyg_flags_register_new_gtype_and_add (PyObject *self,
         g_base_info_unref ((GIBaseInfo *) value_info);
     }
 
+    /* Obfuscate the full_name by prefixing it with "Py" to avoid conflicts
+     * with real GTypes. See: https://bugzilla.gnome.org/show_bug.cgi?id=692515
+     */
     namespace = g_base_info_get_namespace ((GIBaseInfo *) info);
     type_name = g_base_info_get_name ((GIBaseInfo *) info);
-    full_name = g_strconcat (namespace, type_name, NULL);
+    full_name = g_strconcat ("Py", namespace, type_name, NULL);
 
     /* If enum registration fails, free all the memory allocated
      * for the values array. This needs to leak when successful
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 29a69d0..ee2f3de 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1475,7 +1475,7 @@ class TestEnum(unittest.TestCase):
 
     def test_enum_gtype_name_is_namespaced(self):
         self.assertEqual(GIMarshallingTests.Enum.__gtype__.name,
-                         'GIMarshallingTestsEnum')
+                         'PyGIMarshallingTestsEnum')
 
     def test_enum_double_registration_error(self):
         # a warning is printed for double registration and pygobject will
@@ -1627,7 +1627,7 @@ class TestNoTypeFlags(unittest.TestCase):
 
     def test_flags_gtype_name_is_namespaced(self):
         self.assertEqual(GIMarshallingTests.NoTypeFlags.__gtype__.name,
-                         'GIMarshallingTestsNoTypeFlags')
+                         'PyGIMarshallingTestsNoTypeFlags')
 
     def test_flags_double_registration_error(self):
         # a warning is printed for double registration and pygobject will



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]