summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2010-05-06 18:49:28 -0400
committerOwen W. Taylor <otaylor@fishsoup.net>2010-05-07 12:06:00 -0400
commit36c1996038e41838697cea3a0d56d50dca664eb3 (patch)
treea1986f6e83f3d7019ccd24c36496215c21d2575a
parenta78f828cceab49038f4777dd85e2c898f86d51ab (diff)
downloadgobject-introspection-36c1996038e41838697cea3a0d56d50dca664eb3.tar.gz
Validate parameter references
When an annotation references another parameter, check that that parameter actually exists. Add a comment to the handling of (closure) for callbacks to explain why we don't need the same handling there despite the use of get_parameter_index(). https://bugzilla.gnome.org/show_bug.cgi?id=617978
-rw-r--r--giscanner/annotationparser.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 5fa7cfc0..3a8aa8e5 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -523,6 +523,15 @@ class AnnotationApplier(object):
tag = self._get_tag(block, TAG_RETURNS)
self._parse_param_ret_common(parent, return_, tag)
+ def _get_parameter_index(self, parent, param_name, location_name):
+ index = parent.get_parameter_index(param_name)
+ if index is None:
+ raise InvalidAnnotationError(
+ "can't find parameter %s referenced by parameter %s of %r"
+ % (param_name, parent.name, location_name))
+
+ return index
+
def _parse_param(self, parent, param, tag):
options = getattr(tag, 'options', {})
if isinstance(parent, Function):
@@ -544,14 +553,22 @@ class AnnotationApplier(object):
destroy = options.get(OPT_DESTROY)
if destroy:
- param.destroy_index = parent.get_parameter_index(destroy.one())
+ param.destroy_index = self._get_parameter_index(parent,
+ destroy.one(),
+ param.name)
self._fixup_param_destroy(parent, param)
closure = options.get(OPT_CLOSURE)
if closure:
- param.closure_index = parent.get_parameter_index(closure.one())
+ param.closure_index = self._get_parameter_index(parent,
+ closure.one(),
+ param.name)
self._fixup_param_closure(parent, param)
if isinstance(parent, Callback):
if OPT_CLOSURE in options:
+ # For callbacks, (closure) appears without an
+ # argument, and tags a parameter that is a closure. We
+ # represent it (weirdly) in the gir and typelib by
+ # setting param.closure_index to its own index.
param.closure_index = parent.get_parameter_index(param.name)
self._fixup_param_closure(parent, param)
@@ -672,7 +689,7 @@ class AnnotationApplier(object):
OPT_ARRAY_ZERO_TERMINATED) == '1'
length = array_values.get(OPT_ARRAY_LENGTH)
if length is not None:
- param_index = parent.get_parameter_index(length)
+ param_index = self._get_parameter_index(parent, length, node.name)
container_type.length_param_index = param_index
# For in parameters we're incorrectly deferring
# char/unsigned char to utf8 when a length annotation