[gobject-introspection/issue-309] Support array arguments with static keyword



commit 8eb7e052952f3877cd6def1f3408d06241aa0a61
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Sep 4 19:39:25 2019 +0100

    Support array arguments with static keyword
    
    C99 allows defining an array argument with a fixed size as:
    
      void foo (int arr[static 10])
    
    Compilers conforming to the C99 specification will be able to warn if
    the function is called with NULL or with an array smaller than the
    specified length, something that does not happen when using pre-C99
    declarations like:
    
      void foo (int arr[10])
    
    As the declaration above is identical to:
    
      void foo (int arr[])
    
    Which is, in turn, identical to:
    
      void foo (int *arr)
    
    Fixes: #309

 giscanner/scannerparser.y                       | 11 +++++++++++
 tests/scanner/Regress-1.0-expected.gir          | 17 +++++++++++++++++
 tests/scanner/Regress-1.0-sections-expected.txt |  1 +
 tests/scanner/regress.c                         | 10 ++++++++++
 tests/scanner/regress.h                         |  2 ++
 5 files changed, 41 insertions(+)
---
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index 6a2ffc1d..decd0f2b 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -1091,6 +1091,12 @@ enum_keyword
           }
         ;
 
+static_keyword
+        : STATIC
+          {
+          }
+        ;
+
 enumerator_list
        :
          {
@@ -1174,6 +1180,11 @@ direct_declarator
          {
                $$ = $2;
          }
+        | direct_declarator '[' static_keyword assignment_expression ']'
+          {
+                $$ = $1;
+                gi_source_symbol_merge_type ($$, gi_source_array_new ($4));
+          }
        | direct_declarator '[' assignment_expression ']'
          {
                $$ = $1;
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index a589b82c..3ef73f8c 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -6816,6 +6816,23 @@ libgnome-keyring.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="test_array_static_in_int"
+              c:identifier="regress_test_array_static_in_int">
+      <source-position filename="regress.h" line="871"/>
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="x" transfer-ownership="none">
+          <doc xml:space="preserve"
+               filename="regress.c"
+               line="869">a list of 10 integers</doc>
+          <array zero-terminated="0" c:type="int*" fixed-size="10">
+            <type name="gint" c:type="int"/>
+          </array>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_array_struct_in_full"
               c:identifier="regress_test_array_struct_in_full">
       <doc xml:space="preserve"
diff --git a/tests/scanner/Regress-1.0-sections-expected.txt b/tests/scanner/Regress-1.0-sections-expected.txt
index 0a0bf082..b35b3a9a 100644
--- a/tests/scanner/Regress-1.0-sections-expected.txt
+++ b/tests/scanner/Regress-1.0-sections-expected.txt
@@ -73,6 +73,7 @@ regress_test_array_int_none_out
 regress_test_array_int_null_in
 regress_test_array_int_null_out
 regress_test_array_int_out
+regress_test_array_static_in_int
 regress_test_array_struct_in_full
 regress_test_array_struct_in_none
 regress_test_array_struct_out
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index bc04079c..d51bb465 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -864,6 +864,16 @@ regress_test_array_fixed_size_int_return (void)
   return ints;
 }
 
+/**
+ * regress_test_array_static_in_int
+ * @x: (in) (array fixed-size=10): a list of 10 integers
+ */
+void
+regress_test_array_static_in_int (int x[static 10])
+{
+
+}
+
 /**
  * regress_test_strv_out_c:
  *
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index cf5302e4..ca0bee90 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -867,6 +867,8 @@ void       regress_forced_method (RegressTestObj *obj);
 _GI_TEST_EXTERN
 void regress_test_array_fixed_out_objects (RegressTestObj ***objs);
 
+_GI_TEST_EXTERN
+void regress_test_array_static_in_int (int x[static 10]);
 
 _GI_TEST_EXTERN
 void regress_test_obj_torture_signature_0 (RegressTestObj    *obj,


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