[gobject-introspection] Always add a zero-terminated attribute when it cannot be implied



commit 3e0292cd66752489d5b05bed57abffec0315b3ae
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Jun 1 16:59:17 2011 +0200

    Always add a zero-terminated attribute when it cannot be implied
    
    g-ir-compiler assumes that an array is zero terminated when the
    attribute is absent and there is no other attribute (length and
    fixed-size), but g-ir-scanner only added the attribute when it is 0.
    This means that an explicit zero-terminated=1 annotation would have
    had no effect.
    Fix that and at the same time ensure that all other arrays are not
    zero-terminated by default.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646635

 giscanner/girwriter.py                    |    6 +++++
 giscanner/maintransformer.py              |    2 +
 tests/scanner/Annotation-1.0-expected.gir |   18 +++++++-------
 tests/scanner/Regress-1.0-expected.gir    |   36 +++++++++++++++-------------
 4 files changed, 36 insertions(+), 26 deletions(-)
---
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index ad601ee..4a6c47e 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -278,8 +278,14 @@ and/or use gtk-doc annotations. ''')
         elif isinstance(ntype, ast.Array):
             if ntype.array_type != ast.Array.C:
                 attrs.insert(0, ('name', ntype.array_type))
+            # we insert an explicit 'zero-terminated' attribute
+            # when it is false, or when it would not be implied
+            # by the absence of length and fixed-size
             if not ntype.zeroterminated:
                 attrs.insert(0, ('zero-terminated', '0'))
+            elif (ntype.zeroterminated
+                  and (ntype.size is not None or ntype.length_param_name is not None)):
+                attrs.insert(0, ('zero-terminated', '1'))
             if ntype.size is not None:
                 attrs.append(('fixed-size', '%d' % (ntype.size, )))
             if ntype.length_param_name is not None:
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index dd20af1..fd0cc6c 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -346,6 +346,8 @@ usage is void (*_gtk_reserved1)(void);"""
         if OPT_ARRAY_ZERO_TERMINATED in array_values:
             container_type.zeroterminated = array_values.get(
                 OPT_ARRAY_ZERO_TERMINATED) == '1'
+        else:
+            container_type.zeroterminated = False
         length = array_values.get(OPT_ARRAY_LENGTH)
         if length is not None:
             paramname = self._get_validate_parameter_name(parent, length, node)
diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir
index a760a19..f650c25 100644
--- a/tests/scanner/Annotation-1.0-expected.gir
+++ b/tests/scanner/Annotation-1.0-expected.gir
@@ -146,7 +146,7 @@ and/or use gtk-doc annotations.  -->
         <parameters>
           <parameter name="nums" transfer-ownership="none">
             <doc xml:whitespace="preserve">Sequence of numbers</doc>
-            <array c:type="int*">
+            <array zero-terminated="0" c:type="int*">
               <type name="gint" c:type="int"/>
             </array>
           </parameter>
@@ -180,7 +180,7 @@ and/or use gtk-doc annotations.  -->
         <parameters>
           <parameter name="nums" transfer-ownership="none">
             <doc xml:whitespace="preserve">Sequence of numbers that are zero-terminated</doc>
-            <array length="1" c:type="int*">
+            <array length="1" zero-terminated="1" c:type="int*">
               <type name="gint" c:type="int"/>
             </array>
           </parameter>
@@ -377,7 +377,7 @@ each string needs to be freed.</doc>
                      caller-allocates="0"
                      transfer-ownership="full">
             <doc xml:whitespace="preserve">Argument vector</doc>
-            <array length="0" c:type="char***">
+            <array length="0" zero-terminated="1" c:type="char***">
               <type name="utf8" c:type="char**"/>
             </array>
           </parameter>
@@ -391,7 +391,7 @@ each string needs to be freed.</doc>
         <parameters>
           <parameter name="data" transfer-ownership="none">
             <doc xml:whitespace="preserve">The data</doc>
-            <array length="1" c:type="guchar*">
+            <array length="1" zero-terminated="0" c:type="guchar*">
               <type name="guint8" c:type="guchar"/>
             </array>
           </parameter>
@@ -409,7 +409,7 @@ each string needs to be freed.</doc>
         <parameters>
           <parameter name="data" transfer-ownership="none">
             <doc xml:whitespace="preserve">The data</doc>
-            <array length="1" c:type="gchar*">
+            <array length="1" zero-terminated="0" c:type="gchar*">
               <type name="gint8"/>
             </array>
           </parameter>
@@ -428,7 +428,7 @@ type.</doc>
         <parameters>
           <parameter name="data" transfer-ownership="none">
             <doc xml:whitespace="preserve">The data</doc>
-            <array length="1" c:type="gpointer">
+            <array length="1" zero-terminated="0" c:type="gpointer">
               <type name="guint8"/>
             </array>
           </parameter>
@@ -687,7 +687,7 @@ detection, and fixing it via annotations.</doc>
                    caller-allocates="0"
                    transfer-ownership="full">
           <doc xml:whitespace="preserve">The arguments.</doc>
-          <array length="0" c:type="char***">
+          <array length="0" zero-terminated="0" c:type="char***">
             <type name="utf8" c:type="char**"/>
           </array>
         </parameter>
@@ -723,7 +723,7 @@ detection, and fixing it via annotations.</doc>
     <function name="return_array" c:identifier="annotation_return_array">
       <return-value transfer-ownership="full">
         <doc xml:whitespace="preserve">The return value</doc>
-        <array length="0" c:type="char**">
+        <array length="0" zero-terminated="0" c:type="char**">
           <type name="utf8"/>
         </array>
       </return-value>
@@ -765,7 +765,7 @@ detection, and fixing it via annotations.</doc>
           <type name="guint" c:type="guint"/>
         </parameter>
         <parameter name="properties" transfer-ownership="none">
-          <array length="0" c:type="gchar*">
+          <array length="0" zero-terminated="0" c:type="gchar*">
             <type name="utf8"/>
           </array>
         </parameter>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 6302579..6c5fdec 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -1104,12 +1104,14 @@ TpAccount::status-changed</doc>
         </array>
       </field>
       <field name="array2" writable="1">
-        <array c:type="RegressTestStructB**" fixed-size="5">
+        <array zero-terminated="0"
+               c:type="RegressTestStructB**"
+               fixed-size="5">
           <type name="TestStructB" c:type="RegressTestStructB*"/>
         </array>
       </field>
       <field name="array3" writable="1">
-        <array c:type="gpointer*">
+        <array zero-terminated="0" c:type="gpointer*">
           <type name="TestObj"/>
         </array>
       </field>
@@ -1337,7 +1339,7 @@ TpAccount::status-changed</doc>
       <parameters>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">a list of 5 integers</doc>
-          <array c:type="int*" fixed-size="5">
+          <array zero-terminated="0" c:type="int*" fixed-size="5">
             <type name="gint" c:type="int"/>
           </array>
         </parameter>
@@ -1354,7 +1356,7 @@ TpAccount::status-changed</doc>
                    caller-allocates="0"
                    transfer-ownership="full">
           <doc xml:whitespace="preserve">a list of 5 integers ranging from 0 to 4</doc>
-          <array c:type="int**" fixed-size="5">
+          <array zero-terminated="0" c:type="int**" fixed-size="5">
             <type name="gint" c:type="int*"/>
           </array>
         </parameter>
@@ -1364,7 +1366,7 @@ TpAccount::status-changed</doc>
               c:identifier="regress_test_array_fixed_size_int_return">
       <return-value transfer-ownership="full">
         <doc xml:whitespace="preserve">a list of 5 integers ranging from 0 to 4</doc>
-        <array c:type="int*" fixed-size="5">
+        <array zero-terminated="0" c:type="int*" fixed-size="5">
           <type name="gint" c:type="int"/>
         </array>
       </return-value>
@@ -1380,7 +1382,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of ints</doc>
-          <array length="0" c:type="gint16*">
+          <array length="0" zero-terminated="0" c:type="gint16*">
             <type name="gint16" c:type="gint16"/>
           </array>
         </parameter>
@@ -1397,7 +1399,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of ints</doc>
-          <array length="0" c:type="gint32*">
+          <array length="0" zero-terminated="0" c:type="gint32*">
             <type name="gint32" c:type="gint32"/>
           </array>
         </parameter>
@@ -1414,7 +1416,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of ints</doc>
-          <array length="0" c:type="gint64*">
+          <array length="0" zero-terminated="0" c:type="gint64*">
             <type name="gint64" c:type="gint64"/>
           </array>
         </parameter>
@@ -1431,7 +1433,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of ints</doc>
-          <array length="0" c:type="gint8*">
+          <array length="0" zero-terminated="0" c:type="gint8*">
             <type name="gint8" c:type="gint8"/>
           </array>
         </parameter>
@@ -1449,7 +1451,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="types" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of types</doc>
-          <array length="0" c:type="GType*">
+          <array length="0" zero-terminated="0" c:type="GType*">
             <type name="GType" c:type="GType"/>
           </array>
         </parameter>
@@ -1459,7 +1461,7 @@ TpAccount::status-changed</doc>
               c:identifier="regress_test_array_int_full_out">
       <return-value transfer-ownership="full">
         <doc xml:whitespace="preserve">a new array of integers.</doc>
-        <array length="0" c:type="int*">
+        <array length="0" zero-terminated="0" c:type="int*">
           <type name="gint" c:type="int"/>
         </array>
       </return-value>
@@ -1484,7 +1486,7 @@ TpAccount::status-changed</doc>
         </parameter>
         <parameter name="ints" transfer-ownership="none">
           <doc xml:whitespace="preserve">List of ints</doc>
-          <array length="0" c:type="int*">
+          <array length="0" zero-terminated="0" c:type="int*">
             <type name="gint" c:type="int"/>
           </array>
         </parameter>
@@ -1508,7 +1510,7 @@ TpAccount::status-changed</doc>
                    caller-allocates="0"
                    transfer-ownership="full">
           <doc xml:whitespace="preserve">a list of integers whose items will be increased by 1, except the first that will be dropped</doc>
-          <array length="0" c:type="int**">
+          <array length="0" zero-terminated="0" c:type="int**">
             <type name="gint" c:type="int*"/>
           </array>
         </parameter>
@@ -1518,7 +1520,7 @@ TpAccount::status-changed</doc>
               c:identifier="regress_test_array_int_none_out">
       <return-value transfer-ownership="none">
         <doc xml:whitespace="preserve">a static array of integers.</doc>
-        <array length="0" c:type="int*">
+        <array length="0" zero-terminated="0" c:type="int*">
           <type name="gint" c:type="int"/>
         </array>
       </return-value>
@@ -1539,7 +1541,7 @@ TpAccount::status-changed</doc>
       </return-value>
       <parameters>
         <parameter name="arr" transfer-ownership="none" allow-none="1">
-          <array length="1" c:type="int*">
+          <array length="1" zero-terminated="0" c:type="int*">
             <type name="gint" c:type="int"/>
           </array>
         </parameter>
@@ -1560,7 +1562,7 @@ TpAccount::status-changed</doc>
                    caller-allocates="0"
                    transfer-ownership="full"
                    allow-none="1">
-          <array length="1" c:type="int**">
+          <array length="1" zero-terminated="0" c:type="int**">
             <type name="gint" c:type="int*"/>
           </array>
         </parameter>
@@ -1591,7 +1593,7 @@ TpAccount::status-changed</doc>
                    caller-allocates="0"
                    transfer-ownership="full">
           <doc xml:whitespace="preserve">a list of 5 integers, from 0 to 4 in consecutive order</doc>
-          <array length="0" c:type="int**">
+          <array length="0" zero-terminated="0" c:type="int**">
             <type name="gint" c:type="int*"/>
           </array>
         </parameter>



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