[gobject-introspection] scanner: allow (array zero-terminated) instead of (array zero-terminated=1)



commit 50dfb465658a5c1705cac51a31f145fee8b6b168
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Sun Mar 1 21:36:12 2015 +0100

    scanner: allow (array zero-terminated) instead of (array zero-terminated=1)
    
    What we already had:
    - (array zero-terminated=1) > array which is NULL terminated
    - (array zero-terminated=0) > array which is not NULL terminated
    - (array)                   > array which is not NULL terminated
    - (array zero-terminated=X) > array which is not NULL terminated
                       where X can be anything
    
    What this patch adds:
    - (array zero-terminated)   > array which is NULL terminated
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657754

 giscanner/annotationparser.py                      |    7 ++++-
 giscanner/maintransformer.py                       |   10 ++++--
 tests/gimarshallingtests.c                         |   32 ++++++++++----------
 tests/gimarshallingtests.h                         |    2 +-
 tests/scanner/annotation.c                         |    2 +-
 .../annotationparser/gi/annotation_array.xml       |    8 ++---
 tests/warn/invalid-array.h                         |    9 ++---
 7 files changed, 38 insertions(+), 32 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index afeca9c..907039c 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -652,7 +652,7 @@ class GtkDocAnnotatable(object):
             return
 
         for option, value in options.items():
-            if option in [OPT_ARRAY_ZERO_TERMINATED, OPT_ARRAY_FIXED_SIZE]:
+            if option == OPT_ARRAY_FIXED_SIZE:
                 try:
                     int(value)
                 except (TypeError, ValueError):
@@ -663,6 +663,11 @@ class GtkDocAnnotatable(object):
                         warn('invalid "%s" annotation option "%s" value "%s", must be an integer' %
                              (ann_name, option, value),
                              position)
+            elif option == OPT_ARRAY_ZERO_TERMINATED:
+                if value is not None and value not in ['0', '1']:
+                    warn('invalid "%s" annotation option "%s" value "%s", must be 0 or 1' %
+                         (ann_name, option, value),
+                         position)
             elif option == OPT_ARRAY_LENGTH:
                 if value is None:
                     warn('"%s" annotation option "length" needs a value' % (ann_name, ),
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 4326374..df598ad 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -386,10 +386,14 @@ class MainTransformer(object):
         array_options = annotations.get(ANN_ARRAY)
         container_type = ast.Array(array_type, element_type_node, ctype=node.type.ctype,
                                    is_const=node.type.is_const)
-        if OPT_ARRAY_ZERO_TERMINATED in array_options:
-            container_type.zeroterminated = array_options.get(OPT_ARRAY_ZERO_TERMINATED) == '1'
-        else:
+        if array_options.get(OPT_ARRAY_ZERO_TERMINATED, '0') == '0':
             container_type.zeroterminated = False
+        else:
+            if (OPT_ARRAY_ZERO_TERMINATED in array_options
+            or array_options.get(OPT_ARRAY_ZERO_TERMINATED) == '1'):
+                container_type.zeroterminated = True
+            else:
+                container_type.zeroterminated = False
 
         length = array_options.get(OPT_ARRAY_LENGTH)
         if length:
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index c8f9774..76beb92 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -1332,7 +1332,7 @@ gi_marshalling_tests_array_in_len_before (gint length, const gint *ints)
 
 /**
  * gi_marshalling_tests_array_in_len_zero_terminated:
- * @ints: (array length=length zero-terminated=1):
+ * @ints: (array length=length zero-terminated):
  * @length:
  */
 void
@@ -1584,7 +1584,7 @@ gi_marshalling_tests_array_in_nonzero_nonlen (gint first, const guint8 *chars)
 /**
  * gi_marshalling_tests_array_zero_terminated_return:
  *
- * Returns: (array zero-terminated=1) (transfer none):
+ * Returns: (array zero-terminated) (transfer none):
  */
 gchar **
 gi_marshalling_tests_array_zero_terminated_return (void)
@@ -1596,7 +1596,7 @@ gi_marshalling_tests_array_zero_terminated_return (void)
 /**
  * gi_marshalling_tests_array_zero_terminated_return_null:
  *
- * Returns: (array zero-terminated=1) (transfer none):
+ * Returns: (array zero-terminated) (transfer none):
  */
 gchar **
 gi_marshalling_tests_array_zero_terminated_return_null (void)
@@ -1607,7 +1607,7 @@ gi_marshalling_tests_array_zero_terminated_return_null (void)
 /**
  * gi_marshalling_tests_array_zero_terminated_return_struct:
  *
- * Returns: (array zero-terminated=1) (transfer full):
+ * Returns: (array zero-terminated) (transfer full):
  */
 GIMarshallingTestsBoxedStruct **
 gi_marshalling_tests_array_zero_terminated_return_struct (void)
@@ -1630,7 +1630,7 @@ gi_marshalling_tests_array_zero_terminated_return_struct (void)
 
 /**
  * gi_marshalling_tests_array_zero_terminated_in:
- * @utf8s: (array zero-terminated=1) (transfer none):
+ * @utf8s: (array zero-terminated) (transfer none):
  */
 void
 gi_marshalling_tests_array_zero_terminated_in (gchar **utf8s)
@@ -1643,7 +1643,7 @@ gi_marshalling_tests_array_zero_terminated_in (gchar **utf8s)
 
 /**
  * gi_marshalling_tests_array_zero_terminated_out:
- * @utf8s: (out) (array zero-terminated=1) (transfer none):
+ * @utf8s: (out) (array zero-terminated) (transfer none):
  */
 void
 gi_marshalling_tests_array_zero_terminated_out (gchar *** utf8s)
@@ -1654,7 +1654,7 @@ gi_marshalling_tests_array_zero_terminated_out (gchar *** utf8s)
 
 /**
  * gi_marshalling_tests_array_zero_terminated_inout:
- * @utf8s: (inout) (array zero-terminated=1) (transfer none):
+ * @utf8s: (inout) (array zero-terminated) (transfer none):
  */
 void
 gi_marshalling_tests_array_zero_terminated_inout (gchar *** utf8s)
@@ -1671,9 +1671,9 @@ gi_marshalling_tests_array_zero_terminated_inout (gchar *** utf8s)
 
 /**
  * gi_marshalling_tests_array_gvariant_none_in:
- * @variants: (array zero-terminated=1) (transfer none):
+ * @variants: (array zero-terminated) (transfer none):
  *
- * Returns: (array zero-terminated=1) (transfer none):
+ * Returns: (array zero-terminated) (transfer none):
  */
 GVariant **
 gi_marshalling_tests_array_gvariant_none_in (GVariant **variants)
@@ -1697,9 +1697,9 @@ gi_marshalling_tests_array_gvariant_none_in (GVariant **variants)
 
 /**
  * gi_marshalling_tests_array_gvariant_container_in:
- * @variants: (array zero-terminated=1) (transfer container):
+ * @variants: (array zero-terminated) (transfer container):
  *
- * Returns: (array zero-terminated=1) (transfer container):
+ * Returns: (array zero-terminated) (transfer container):
  */
 GVariant **
 gi_marshalling_tests_array_gvariant_container_in (GVariant **variants)
@@ -1721,9 +1721,9 @@ gi_marshalling_tests_array_gvariant_container_in (GVariant **variants)
 
 /**
  * gi_marshalling_tests_array_gvariant_full_in:
- * @variants: (array zero-terminated=1) (transfer full):
+ * @variants: (array zero-terminated) (transfer full):
  *
- * Returns: (array zero-terminated=1) (transfer full):
+ * Returns: (array zero-terminated) (transfer full):
  */
 GVariant **
 gi_marshalling_tests_array_gvariant_full_in (GVariant **variants)
@@ -3333,7 +3333,7 @@ _marshal_INT__VOID (GClosure *closure,
 
 /**
  * gi_marshalling_tests_gclosure_return:
- * 
+ *
  * Return: a #GClosure
  */
 GClosure *
@@ -4340,7 +4340,7 @@ void gi_marshalling_tests_object_vfunc_caller_allocated_out_parameter (GIMarshal
 
 /**
  * gi_marshalling_tests_object_vfunc_array_out_parameter:
- * @a: (out) (array zero-terminated=1):
+ * @a: (out) (array zero-terminated):
  */
 void gi_marshalling_tests_object_vfunc_array_out_parameter (GIMarshallingTestsObject *self, gfloat **a)
 {
@@ -4909,7 +4909,7 @@ gi_marshalling_tests_gerror (GError **error)
 
 /**
  * gi_marshalling_tests_gerror_array_in:
- * @in_ints: (array zero-terminated=1):
+ * @in_ints: (array zero-terminated):
  */
 void
 gi_marshalling_tests_gerror_array_in (gint *in_ints, GError **error)
diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h
index 3fb9c94..fc20fd7 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -1378,7 +1378,7 @@ struct _GIMarshallingTestsObjectClass
 
     /**
      * GIMarshallingTestsObjectClass::vfunc_array_out_parameter:
-     * @a: (out) (array zero-terminated=1):
+     * @a: (out) (array zero-terminated):
      */
     void  (* vfunc_array_out_parameter) (GIMarshallingTestsObject *self, gfloat **a);
 
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index 173db97..da364e1 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -449,7 +449,7 @@ regress_annotation_object_compute_sum_n(RegressAnnotationObject *object,
 /**
  * regress_annotation_object_compute_sum_nz:
  * @object: a #RegressAnnotationObject
- * @nums: (array length=n_nums zero-terminated=1): Sequence of numbers that
+ * @nums: (array length=n_nums zero-terminated): Sequence of numbers that
  * are zero-terminated
  * @n_nums: Length of number array
  *
diff --git a/tests/scanner/annotationparser/gi/annotation_array.xml 
b/tests/scanner/annotationparser/gi/annotation_array.xml
index 3a7cbc0..8b7a62d 100644
--- a/tests/scanner/annotationparser/gi/annotation_array.xml
+++ b/tests/scanner/annotationparser/gi/annotation_array.xml
@@ -159,7 +159,7 @@ are zero-terminated</description>
  * annotation_object_parse_args:
  * @object: a #AnnotationObject
  * @argc: (inout): Length of the argument vector
- * @argv: (inout) (array length=argc zero-terminated=1): Argument vector
+ * @argv: (inout) (array length=argc zero-terminated): Argument vector
  *
  * Test taking a zero-terminated array with length parameter
  **/</input>
@@ -197,7 +197,6 @@ are zero-terminated</description>
                 </option>
                 <option>
                   <name>zero-terminated</name>
-                  <value>1</value>
                 </option>
               </options>
             </annotation>
@@ -212,7 +211,7 @@ are zero-terminated</description>
  * annotation_object_parse_args:
  * @object: a #AnnotationObject
  * @argc: (inout): Length of the argument vector
- * @argv: (inout) (array length=argc zero-terminated=1): Argument vector
+ * @argv: (inout) (array length=argc zero-terminated): Argument vector
  *
  * Test taking a zero-terminated array with length parameter
  */</output>
@@ -466,9 +465,8 @@ are zero-terminated</description>
       </tags>
     </docblock>
     <messages>
-      <message>3: Warning: Test: "array" annotation option "zero-terminated" needs a value</message>
       <message>4: Warning: Test: "array" annotation option "length" needs a value</message>
-      <message>6: Warning: Test: invalid "array" annotation option "zero-terminated" value "yes", must be an 
integer</message>
+      <message>6: Warning: Test: invalid "array" annotation option "zero-terminated" value "yes", must be 0 
or 1</message>
     </messages>
   </parser>
   <output>/**
diff --git a/tests/warn/invalid-array.h b/tests/warn/invalid-array.h
index b9b828c..97ad3e9 100644
--- a/tests/warn/invalid-array.h
+++ b/tests/warn/invalid-array.h
@@ -18,8 +18,7 @@ void
 test_invalid_array_zero_terminated (char ***out1,
                                     char ***out2);
 
-// EXPECT:14: Warning: Test: "array" annotation option "zero-terminated" needs a value
-// EXPECT:15: Warning: Test: invalid "array" annotation option "zero-terminated" value "foobar", must be an 
integer
+// EXPECT:15: Warning: Test: invalid "array" annotation option "zero-terminated" value "foobar", must be 0 
or 1
 
 /**
  * test_invalid_array_fixed_size:
@@ -30,8 +29,8 @@ void
 test_invalid_array_fixed_size (char ***out1,
                                char ***out2);
 
-// EXPECT:26: Warning: Test: "array" annotation option "fixed-size" needs a value
-// EXPECT:27: Warning: Test: invalid "array" annotation option "fixed-size" value "foobar", must be an 
integer
+// EXPECT:25: Warning: Test: "array" annotation option "fixed-size" needs a value
+// EXPECT:26: Warning: Test: invalid "array" annotation option "fixed-size" value "foobar", must be an 
integer
 
 /**
  * test_invalid_array_length:
@@ -41,4 +40,4 @@ void
 test_invalid_array_length (char ***out1,
                            char ***out2);
 
-// EXPECT:38: Warning: Test: "array" annotation option "length" needs a value
+// EXPECT:37: Warning: Test: "array" annotation option "length" needs a value


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