summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-02-03 08:54:16 -0500
committerJasper St. Pierre <jstpierre@mecheye.net>2013-02-07 04:29:15 -0500
commit7bdc0b75872dcff2e154d05121568de54996a947 (patch)
treea1b5f0002e9173835f7ac162e05229c62a5bd305
parent71bc26058124b2b9f2e283eeb07fae5eb3e52710 (diff)
downloadgobject-introspection-7bdc0b75872dcff2e154d05121568de54996a947.tar.gz
transformer: Ensure that types aren't resolved if we can't find them
This ensures that things can't try to reference undefined/invalid types without emitting warnings, and that users need to include other GIRs at build time if they want to reference another type. https://bugzilla.gnome.org/show_bug.cgi?id=693098
-rw-r--r--giscanner/maintransformer.py2
-rw-r--r--giscanner/transformer.py30
-rw-r--r--tests/warn/invalid-element-type.h9
3 files changed, 36 insertions, 5 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index d149f30a..4eaf6401 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -306,7 +306,7 @@ usage is void (*_gtk_reserved1)(void);"""
else:
text = type_str
message.warn_node(parent, "%s: Unknown type: %r" %
- (text, result.ctype), positions=position)
+ (text, type_str), positions=position)
return result
def _resolve_toplevel(self, type_str, type_node=None, node=None, parent=None):
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 25857b73..0858b8d3 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -877,9 +877,12 @@ Note that type resolution may not succeed."""
if '.' in typestr:
container = self._create_bare_container_type(typestr)
if container:
- return container
- return self._namespace.type_from_name(typestr)
- typeval = self.create_type_from_ctype_string(typestr)
+ typeval = container
+ else:
+ typeval = self._namespace.type_from_name(typestr)
+ else:
+ typeval = self.create_type_from_ctype_string(typestr)
+
self.resolve_type(typeval)
if typeval.resolved:
# Explicitly clear out the c_type; there isn't one in this case.
@@ -924,7 +927,7 @@ Note that type resolution may not succeed."""
return True
return False
- def resolve_type(self, typeval):
+ def _resolve_type_internal(self, typeval):
if isinstance(typeval, (ast.Array, ast.List)):
return self.resolve_type(typeval.element_type)
elif isinstance(typeval, ast.Map):
@@ -938,6 +941,25 @@ Note that type resolution may not succeed."""
elif typeval.gtype_name:
return self._resolve_type_from_gtype_name(typeval)
+ def resolve_type(self, typeval):
+ if not self._resolve_type_internal(typeval):
+ return False
+
+ if typeval.target_fundamental or typeval.target_foreign:
+ return True
+
+ assert typeval.target_giname is not None
+
+ try:
+ type_ = self.lookup_giname(typeval.target_giname)
+ except KeyError:
+ typeval.target_giname = None
+
+ if type_ is None:
+ typeval.target_giname = None
+
+ return typeval.resolved
+
def _typepair_to_str(self, item):
nsname, item = item
if nsname is None:
diff --git a/tests/warn/invalid-element-type.h b/tests/warn/invalid-element-type.h
index c9ff3040..bcd9123b 100644
--- a/tests/warn/invalid-element-type.h
+++ b/tests/warn/invalid-element-type.h
@@ -65,6 +65,14 @@ void test_invalid_ptrarray_element_type(GPtrArray *p1, GPtrArray *p2);
GList* test_unresolved_element_type(void);
+/**
+ * test_unresolved_value_element_type:
+ *
+ * Returns: (element-type GLib.Value) (transfer full):
+ */
+
+GPtrArray* test_unresolved_value_element_type(void);
+
// EXPECT:5: Warning: Test: element-type annotation takes at least one option, none given
// EXPECT:6: Warning: Test: element-type annotation for a list must have exactly one option, not 2 options
@@ -78,6 +86,7 @@ GList* test_unresolved_element_type(void);
// EXPECT:51: Warning: Test: element-type annotation takes at least one option, none given
// EXPECT:52: Warning: Test: invalid (element-type) for a GPtrArray, must be a pointer
// EXPECT:63: Warning: Test: test_unresolved_element_type: Unknown type: 'Unresolved'
+// EXPECT:71: Warning: Test: test_unresolved_value_element_type: Unknown type: 'GLib.Value'
// EXPECT:4: Warning: Test: test_invalid_list_element_type: argument l1: Missing (element-type) annotation
// EXPECT:4: Warning: Test: test_invalid_list_element_type: argument l2: Missing (element-type) annotation
// EXPECT:50: Warning: Test: test_invalid_ptrarray_element_type: argument p1: Missing (element-type) annotation