From e6fc4c1bcba459dfd56f2d2019e24bfbaf29a493 Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Fri, 3 Jan 2014 16:16:35 -0800 Subject: scanner: Replace GInitiallyUnowned field sharing with generic solution Remove GInitiallyUnowned special case in gdumpparser where fields are copied from GObject. Add generic solution where anytime we have multiple typedef structs, the fields become shared: typedef struct _Foo Foo; typedef struct _Foo Bar; struct _Foo {...}; https://bugzilla.gnome.org/show_bug.cgi?id=581525 --- giscanner/gdumpparser.py | 11 ----------- giscanner/transformer.py | 13 +++++++------ tests/scanner/test_transformer.py | 8 ++++---- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py index e5490b1b..e1fc9358 100644 --- a/giscanner/gdumpparser.py +++ b/giscanner/gdumpparser.py @@ -326,17 +326,6 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide self._introspect_signals(node, xmlnode) self._introspect_implemented_interfaces(node, xmlnode) self._add_record_fields(node) - - if node.name == 'InitiallyUnowned': - # http://bugzilla.gnome.org/show_bug.cgi?id=569408 - # GInitiallyUnowned is actually a typedef for GObject, but - # that's not reflected in the GIR, where it appears as a - # subclass (as it appears in the GType hierarchy). So - # what we do here is copy all of the GObject fields into - # GInitiallyUnowned so that struct offset computation - # works correctly. - node.fields = self._namespace.get('Object').fields - self._namespace.append(node, replace=True) def _introspect_interface(self, xmlnode): diff --git a/giscanner/transformer.py b/giscanner/transformer.py index b540a8c1..80265dd8 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -752,14 +752,15 @@ raise ValueError.""" # prior typedef struct. If we get here it means this is another # typedef of that struct. Instead of creating an alias to the # primary typedef that has been promoted, we create a new Record - # which is forced as a disguised struct. This handles the case - # where we want to give GInitiallyUnowned its own Record: + # with shared fields. This handles the case where we want to + # give structs like GInitiallyUnowned its own Record: # typedef struct _GObject GObject; # typedef struct _GObject GInitiallyUnowned; - # GInitiallyUnowned is also special cased in gdumpparser.py to - # copy fields which may eventually be avoided by doing it here - # generically. - compound = compound_class(name, symbol.ident, disguised=True, tag_name=tag_name) + # See: http://bugzilla.gnome.org/show_bug.cgi?id=569408 + new_compound = compound_class(name, symbol.ident, tag_name=tag_name) + new_compound.fields = compound.fields + new_compound.add_symbol_reference(symbol) + return new_compound else: # If the struct does not have its name set, it exists only in # the tag namespace. Set it here and return it which will diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py index 7f4f98de..39c54a4d 100644 --- a/tests/scanner/test_transformer.py +++ b/tests/scanner/test_transformer.py @@ -157,8 +157,8 @@ class TestStructTypedefs(unittest.TestCase): shared = self.namespace.get('StructAlias') self.assertTrue(shared is not None) self.assertTrue(isinstance(shared, ast.Record)) - self.assertTrue(shared.disguised) - self.assertEqual(len(shared.fields), 0) + self.assertFalse(shared.disguised) + self.assertEqual(len(shared.fields), 1) self.assertEqual(shared.ctype, 'TestStructAlias') def test_struct_tag_aliases_after(self): @@ -181,8 +181,8 @@ class TestStructTypedefs(unittest.TestCase): shared = self.namespace.get('StructAlias') self.assertTrue(shared is not None) self.assertTrue(isinstance(shared, ast.Record)) - self.assertTrue(shared.disguised) - self.assertEqual(len(shared.fields), 0) + self.assertFalse(shared.disguised) + self.assertEqual(len(shared.fields), 1) self.assertEqual(shared.ctype, 'TestStructAlias') def test_struct_pointer(self): -- cgit v1.2.1