From cef390f65ffe9e51b103fcb29ee177882f762a0e Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 29 Aug 2011 22:17:02 -0400 Subject: scanner: Don't try to copy c:type if we're parsing (element-type) Commit 81abc2eb63317003a11d1484e84698a37e8ec035 tries harder to keep the c:type if it was overriden by a (type) annotation. However, the _resolve() function was also called for (element-type), which had undesirable effects - we'd copy the container c:type to the element type. Fix this by splitting out the c:type preservation to only happen when processing toplevel types. https://bugzilla.gnome.org/show_bug.cgi?id=656931 --- giscanner/maintransformer.py | 15 ++++-- tests/scanner/Annotation-1.0-expected.gir | 20 ++++---- tests/scanner/Foo-1.0-expected.gir | 2 +- tests/scanner/Regress-1.0-expected.gir | 82 +++++++++++++++---------------- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 3eba1e7a..29d9229d 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -300,6 +300,11 @@ usage is void (*_gtk_reserved1)(void);""" text = type_str message.warn_node(parent, "%s: Unknown type: %r" % (text, result.ctype), positions=position) + return result + + def _resolve_toplevel(self, type_str, type_node=None, node=None, parent=None): + """Like _resolve(), but attempt to preserve more attributes of original type.""" + result = self._resolve(type_str, type_node=type_node, node=node, parent=parent) # If we replace a node with a new type (such as an annotated) we # might lose the ctype from the original node. if type_node is not None: @@ -525,8 +530,8 @@ usage is void (*_gtk_reserved1)(void);""" param_type = options.get(OPT_TYPE) if param_type: - node.type = self._resolve(param_type.one(), - node.type, node, parent) + node.type = self._resolve_toplevel(param_type.one(), + node.type, node, parent) caller_allocates = False annotated_direction = None @@ -753,7 +758,7 @@ usage is void (*_gtk_reserved1)(void);""" prop.transfer = self._get_transfer_default(parent, prop) type_tag = block.get(TAG_TYPE) if type_tag: - prop.type = self._resolve(type_tag.value, prop.type, prop, parent) + prop.type = self._resolve_toplevel(type_tag.value, prop.type, prop, parent) def _apply_annotations_signal(self, parent, signal): prefix = self._get_annotation_name(parent) @@ -776,8 +781,8 @@ usage is void (*_gtk_reserved1)(void);""" options = getattr(tag, 'options', {}) param_type = options.get(OPT_TYPE) if param_type: - param.type = self._resolve(param_type.one(), param.type, - param, parent) + param.type = self._resolve_toplevel(param_type.one(), param.type, + param, parent) else: tag = None self._apply_annotations_param(signal, param, tag) diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir index 10f5e743..eae5b7c9 100644 --- a/tests/scanner/Annotation-1.0-expected.gir +++ b/tests/scanner/Annotation-1.0-expected.gir @@ -54,14 +54,14 @@ and/or use gtk-doc annotations. --> list of strings - + list of strings - + @@ -238,8 +238,8 @@ objects. hash table - - + + @@ -250,7 +250,7 @@ intentionally similar example to gtk_container_get_children list of objects - + @@ -260,7 +260,7 @@ each string needs to be freed. list of strings - + @@ -410,7 +410,7 @@ each string needs to be freed. The data - + @@ -429,7 +429,7 @@ type. The data - + @@ -725,7 +725,7 @@ detection, and fixing it via annotations. the array - + @@ -782,7 +782,7 @@ detection, and fixing it via annotations. - + diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir index ffcf2167..371250f5 100644 --- a/tests/scanner/Foo-1.0-expected.gir +++ b/tests/scanner/Foo-1.0-expected.gir @@ -1117,7 +1117,7 @@ exposed to language bindings. - + diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 156acc99..2f4b5c21 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -1145,7 +1145,7 @@ TpAccount::status-changed - + @@ -1153,12 +1153,12 @@ TpAccount::status-changed - + - + @@ -1914,7 +1914,7 @@ call and can be released on return. list of strings - + @@ -1932,7 +1932,7 @@ call and can be released on return. c:identifier="regress_test_garray_container_return"> - + @@ -1940,8 +1940,8 @@ call and can be released on return. c:identifier="regress_test_ghash_container_return"> - - + + @@ -1949,8 +1949,8 @@ call and can be released on return. c:identifier="regress_test_ghash_everything_return"> - - + + @@ -1973,8 +1973,8 @@ call and can be released on return. element-type annotation. - - + + @@ -1989,8 +1989,8 @@ element-type annotation. - - + + @@ -2003,8 +2003,8 @@ element-type annotation. - - + + @@ -2013,8 +2013,8 @@ element-type annotation. c:identifier="regress_test_ghash_nothing_return"> - - + + @@ -2022,8 +2022,8 @@ element-type annotation. c:identifier="regress_test_ghash_nothing_return2"> - - + + @@ -2035,8 +2035,8 @@ element-type annotation. - - + + @@ -2053,8 +2053,8 @@ element-type annotation. transfer-ownership="full" allow-none="1"> - - + + @@ -2063,8 +2063,8 @@ element-type annotation. c:identifier="regress_test_ghash_null_return"> - - + + @@ -2072,7 +2072,7 @@ element-type annotation. c:identifier="regress_test_glist_container_return"> - + @@ -2080,7 +2080,7 @@ element-type annotation. c:identifier="regress_test_glist_everything_return"> - + @@ -2092,7 +2092,7 @@ element-type annotation. - + @@ -2105,7 +2105,7 @@ element-type annotation. - + @@ -2114,7 +2114,7 @@ element-type annotation. c:identifier="regress_test_glist_nothing_return"> - + @@ -2122,7 +2122,7 @@ element-type annotation. c:identifier="regress_test_glist_nothing_return2"> - + @@ -2134,7 +2134,7 @@ element-type annotation. - + @@ -2151,7 +2151,7 @@ element-type annotation. transfer-ownership="full" allow-none="1"> - + @@ -2160,7 +2160,7 @@ element-type annotation. c:identifier="regress_test_gslist_container_return"> - + @@ -2168,7 +2168,7 @@ element-type annotation. c:identifier="regress_test_gslist_everything_return"> - + @@ -2180,7 +2180,7 @@ element-type annotation. - + @@ -2193,7 +2193,7 @@ element-type annotation. - + @@ -2202,7 +2202,7 @@ element-type annotation. c:identifier="regress_test_gslist_nothing_return"> - + @@ -2210,7 +2210,7 @@ element-type annotation. c:identifier="regress_test_gslist_nothing_return2"> - + @@ -2222,7 +2222,7 @@ element-type annotation. - + @@ -2239,7 +2239,7 @@ element-type annotation. transfer-ownership="full" allow-none="1"> - + -- cgit v1.2.1