[gobject-introspection] Add more array warnings + tests



commit 789321d97207d6989ef77805fe5fb5920b6935cc
Author: Johan Dahlin <johan gnome org>
Date:   Fri Sep 24 10:53:12 2010 -0300

    Add more array warnings + tests

 giscanner/annotationparser.py |   30 +++++++++++++++++++++++----
 giscanner/maintransformer.py  |    6 ++++-
 tests/warn/Makefile.am        |    1 +
 tests/warn/invalid-array.h    |   44 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 6 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index b8e8530..075f227 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 605b1d1..0407bbc 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 26c2dcb..db006e5 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 0000000..a4a4e47
--- /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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]