[gobject-introspection/wip/transformer: 14/17] scanner: Avoid internal invalid Type instances from parents



commit 0064c296c8f5245b4b80c58881e5b0dbd9d8bfbc
Author: Colin Walters <walters verbum org>
Date:   Wed Aug 25 13:14:57 2010 -0400

    scanner: Avoid internal invalid Type instances from parents
    
    We were adding a trailing ',' in the parent string, clean that up; and
    don't attempt to create a Type from the empty string.

 girepository/gdump.c     |   16 ++++++++--------
 giscanner/gdumpparser.py |    5 +++--
 2 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/girepository/gdump.c b/girepository/gdump.c
index 3dc2172..84ac3c7 100644
--- a/girepository/gdump.c
+++ b/girepository/gdump.c
@@ -168,17 +168,17 @@ dump_object_type (GType type, const char *symbol, GOutputStream *out)
       GType parent;
       gboolean first = TRUE;
 
-      parent = type;
+      parent = g_type_parent (type);
       parent_str = g_string_new ("");
-      do
+      while (parent != G_TYPE_OBJECT && parent != G_TYPE_INVALID)
         {
-          parent = g_type_parent (parent);
           if (first)
             first = FALSE;
           else
             g_string_append_c (parent_str, ',');
           g_string_append (parent_str, g_type_name (parent));
-        } while (parent != G_TYPE_OBJECT && parent != G_TYPE_INVALID);
+          parent = g_type_parent (parent);
+        }
 
       escaped_printf (out, " parents=\"%s\"", parent_str->str);
 
@@ -299,11 +299,10 @@ dump_fundamental_type (GType type, const char *symbol, GOutputStream *out)
   if (G_TYPE_IS_INSTANTIATABLE (type))
     escaped_printf (out, " instantiatable=\"1\"");
 
-  parent = type;
+  parent = g_type_parent (type);
   parent_str = g_string_new ("");
-  do
+  while (parent != G_TYPE_INVALID)
     {
-      parent = g_type_parent (parent);
       if (first)
         first = FALSE;
       else
@@ -311,7 +310,8 @@ dump_fundamental_type (GType type, const char *symbol, GOutputStream *out)
       if (!g_type_name (parent))
         break;
       g_string_append (parent_str, g_type_name (parent));
-    } while (parent != G_TYPE_INVALID);
+      parent = g_type_parent (parent);
+    }
 
   if (parent_str->len > 0)
     escaped_printf (out, " parents=\"%s\"", parent_str->str);
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index 30f9d6a..ce6f9a2 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -362,9 +362,10 @@ blob containing data gleaned from GObject's primitive introspection."""
         node.signals = node.signals
 
     def _parse_parents(self, xmlnode, node):
-        if 'parents' in xmlnode.attrib:
+        parents_str = xmlnode.attrib.get('parents', '')
+        if parents_str != '':
             parent_types = map(lambda s: self._transformer.create_type_from_user_string(s),
-                               xmlnode.attrib['parents'].split(','))
+                               parents_str.split(','))
         else:
             parent_types = []
         node.parent_chain = parent_types



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