diff options
author | Johan Dahlin <johan@gnome.org> | 2010-09-24 10:53:12 -0300 |
---|---|---|
committer | Johan Dahlin <johan@gnome.org> | 2010-09-24 11:03:53 -0300 |
commit | 789321d97207d6989ef77805fe5fb5920b6935cc (patch) | |
tree | db11c1cea605a1eb88520c68f67b7359a5bf6f5b | |
parent | 7c3d1e7c5d6d209c262789b22ea6a99b0636771d (diff) | |
download | gobject-introspection-789321d97207d6989ef77805fe5fb5920b6935cc.tar.gz |
Add more array warnings + tests
-rw-r--r-- | giscanner/annotationparser.py | 30 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 6 | ||||
-rw-r--r-- | tests/warn/Makefile.am | 1 | ||||
-rw-r--r-- | tests/warn/invalid-array.h | 44 |
4 files changed, 75 insertions, 6 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index b8e8530c..075f227d 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -177,13 +177,33 @@ class DocTag(object): elif option == OPT_ARRAY: if value is None: continue - for v in value.all(): - if v not in [OPT_ARRAY_LENGTH, - OPT_ARRAY_ZERO_TERMINATED, - OPT_ARRAY_FIXED_SIZE]: + for name, v in value.all().iteritems(): + if name in [OPT_ARRAY_ZERO_TERMINATED, OPT_ARRAY_FIXED_SIZE]: + try: + int(v) + except (TypeError, ValueError): + if v is None: + message.warn( + 'array option %s needs a value' % ( + name, ), + positions=self.position) + else: + message.warn( + 'invalid array %s option value %r, ' + 'must be an integer' % (name, v, ), + positions=self.position) + continue + elif name == OPT_ARRAY_LENGTH: + if v is None: + message.warn( + 'array option length needs a value', + positions=self.position) + continue + else: message.warn( 'invalid array annotation value: %r' % ( - v, ), self.position) + name, ), self.position) + elif option == OPT_ATTRIBUTE: self._validate_option('attribute', value, n_params=2) elif option == OPT_CLOSURE: diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 605b1d1c..0407bbc5 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -353,7 +353,11 @@ usage is void (*_gtk_reserved1)(void);""" container_type.length_param_name = param.argname fixed = array_values.get(OPT_ARRAY_FIXED_SIZE) if fixed: - container_type.size = int(fixed) + try: + container_type.size = int(fixed) + except ValueError: + # Already warned in annotationparser.py + return node.type = container_type def _apply_annotations_element_type(self, parent, node, options): diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am index 26c2dcbb..db006e57 100644 --- a/tests/warn/Makefile.am +++ b/tests/warn/Makefile.am @@ -4,6 +4,7 @@ TESTS = \ callback-invalid-scope.h \ callback-missing-scope.h \ return-gobject.h \ + invalid-array.h \ invalid-element-type.h \ invalid-option.h \ invalid-out.h \ diff --git a/tests/warn/invalid-array.h b/tests/warn/invalid-array.h new file mode 100644 index 00000000..a4a4e47e --- /dev/null +++ b/tests/warn/invalid-array.h @@ -0,0 +1,44 @@ +#include "common.h" + +/** + * test_invalid_array: + * @out1: (array foobar): + **/ +void +test_invalid_array (char ***out1); + +// EXPECT:5: Warning: Test: invalid array annotation value: 'foobar' + +/** + * test_invalid_array_zero_terminated: + * @out1: (array zero-terminated): + * @out2: (array zero-terminated=foobar): + **/ +void +test_invalid_array_zero_terminated (char ***out1, + char ***out2); + +// EXPECT:14: Warning: Test: array option zero-terminated needs a value +// EXPECT:15: Warning: Test: invalid array zero-terminated option value 'foobar', must be an integer + +/** + * test_invalid_array_fixed_size: + * @out1: (array fixed-size): + * @out2: (array fixed-size=foobar): + **/ +void +test_invalid_array_fixed_size (char ***out1, + char ***out2); + +// EXPECT:26: Warning: Test: array option fixed-size needs a value +// EXPECT:27: Warning: Test: invalid array fixed-size option value 'foobar', must be an integer + +/** + * test_invalid_array_length: + * @out1: (array length): + **/ +void +test_invalid_array_length (char ***out1, + char ***out2); + +// EXPECT:38: Warning: Test: array option length needs a value |