[vala/0.36] girparser: Correctly set array_length_type for delegates returning an array



commit 5a15282ac4b397875da321b23e8b4da4836f90eb
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Feb 20 23:37:46 2019 +0100

    girparser: Correctly set array_length_type for delegates returning an array
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/754

 tests/Makefile.am                          |  3 +++
 tests/gir/delegate-array-length-type.test  | 28 ++++++++++++++++++++++++++++
 tests/gir/method-array-length-type.test    | 21 +++++++++++++++++++++
 tests/gir/parameter-array-length-type.test | 24 ++++++++++++++++++++++++
 vala/valagirparser.vala                    |  8 ++------
 5 files changed, 78 insertions(+), 6 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ac2e8efd7..c6c78fb6b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -379,6 +379,9 @@ TESTS = \
        gir/async-result-pos.test \
        gir/async-sync-out.test \
        gir/delegate-alias-without-target.test \
+       gir/delegate-array-length-type.test \
+       gir/method-array-length-type.test \
+       gir/parameter-array-length-type.test \
        annotations/deprecated.vala \
        annotations/description.vala \
        annotations/noaccessormethod.test \
diff --git a/tests/gir/delegate-array-length-type.test b/tests/gir/delegate-array-length-type.test
new file mode 100644
index 000000000..127ac8a76
--- /dev/null
+++ b/tests/gir/delegate-array-length-type.test
@@ -0,0 +1,28 @@
+GIR
+
+Input:
+
+<callback name="Foo" c:type="TestFoo">
+  <return-value transfer-ownership="full">
+    <array length="0" c:type="gchar**">
+      <type name="utf8"/>
+    </array>
+  </return-value>
+  <parameters>
+    <parameter name="result_length" direction="out" transfer-ownership="none">
+      <type name="gsize" c:type="gsize*"/>
+    </parameter>
+    <parameter name="user_data"
+               transfer-ownership="none"
+               nullable="1"
+               allow-none="1"
+               closure="1">
+      <type name="gpointer" c:type="gpointer"/>
+    </parameter>
+  </parameters>
+</callback>
+
+Output:
+
+[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h", instance_pos = 
0.9)]
+public delegate string[] Foo ();
diff --git a/tests/gir/method-array-length-type.test b/tests/gir/method-array-length-type.test
new file mode 100644
index 000000000..b7ebccfc5
--- /dev/null
+++ b/tests/gir/method-array-length-type.test
@@ -0,0 +1,21 @@
+GIR
+
+Input:
+
+<function name="function" c:identifier="test_function">
+  <return-value transfer-ownership="full">
+    <array length="0" c:type="gchar**">
+      <type name="utf8"/>
+    </array>
+  </return-value>
+  <parameters>
+    <parameter name="result_length" direction="out" transfer-ownership="none">
+      <type name="gsize" c:type="gsize*"/>
+    </parameter>
+  </parameters>
+</function>
+
+Output:
+
+[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h")]
+public static string[] function ();
diff --git a/tests/gir/parameter-array-length-type.test b/tests/gir/parameter-array-length-type.test
new file mode 100644
index 000000000..3bbbe9ec6
--- /dev/null
+++ b/tests/gir/parameter-array-length-type.test
@@ -0,0 +1,24 @@
+GIR
+
+Input:
+
+<function name="function" c:identifier="test_function">
+  <return-value transfer-ownership="none">
+    <type name="none"/>
+  </return-value>
+  <parameters>
+    <parameter name="foo" transfer-ownership="none">
+      <array length="1" c:type="gchar**">
+        <type name="utf8"/>
+      </array>
+    </parameter>
+    <parameter name="foo_length" transfer-ownership="none">
+      <type name="gsize" c:type="gsize"/>
+    </parameter>
+  </parameters>
+</function>
+
+Output:
+
+[CCode (cheader_filename = "test.h")]
+public static void function ([CCode (array_length_cname = "foo_length", array_length_pos = 1.1, 
array_length_type = "gsize")] string[] foo);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index ca99e3eca..40d0efb04 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1855,12 +1855,8 @@ public class Vala.GirParser : CodeVisitor {
                if (type_name != "int") {
                        var st = root.lookup (type_name);
                        if (st != null) {
-                               if (sym is Method) {
-                                       var m = (Method) sym;
-                                       m.set_attribute_string ("CCode", "array_length_type", st.get_cname 
());
-                               } else {
-                                       var param = (Parameter) sym;
-                                       param.set_attribute_string ("CCode", "array_length_type", 
st.get_cname ());
+                               if (sym is Callable || sym is Parameter) {
+                                       sym.set_attribute_string ("CCode", "array_length_type", st.get_cname 
());
                                }
                        }
                }


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