]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Correctly set array_length_type for delegates returning an array
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 20 Feb 2019 22:37:46 +0000 (23:37 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 26 Feb 2019 16:53:41 +0000 (17:53 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/754

tests/Makefile.am
tests/gir/delegate-array-length-type.test [new file with mode: 0644]
tests/gir/method-array-length-type.test [new file with mode: 0644]
tests/gir/parameter-array-length-type.test [new file with mode: 0644]
vala/valagirparser.vala

index b44a03fe0f946e84643a51ee4f9241fbe8e2adab..e5489adb832e55f1f4d2b8a07eb8092199ac1791 100644 (file)
@@ -436,9 +436,12 @@ TESTS = \
        gir/async-sync-out.test \
        gir/class.test \
        gir/delegate-alias-without-target.test \
+       gir/delegate-array-length-type.test \
        gir/delegate-closure-destroy-index-conflict.test \
        gir/enum.test \
        gir/errordomain.test \
+       gir/method-array-length-type.test \
+       gir/parameter-array-length-type.test \
        gir/parameter-nullable-out-simple-type.test \
        gir/property-non-readable.test \
        annotations/deprecated.vala \
diff --git a/tests/gir/delegate-array-length-type.test b/tests/gir/delegate-array-length-type.test
new file mode 100644 (file)
index 0000000..127ac8a
--- /dev/null
@@ -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 (file)
index 0000000..b7ebccf
--- /dev/null
@@ -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 (file)
index 0000000..3bbbe9e
--- /dev/null
@@ -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);
index eac90147e042ee4315451c3f0af85eb95000dbe9..080f8f735cf808ad90a60f9a57fb420fef39f3f6 100644 (file)
@@ -1875,12 +1875,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 ());
                                }
                        }
                }