]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Set length_type for arrays instead of CCode.array_length_type
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 4 Jan 2022 15:20:45 +0000 (16:20 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 18 Jan 2022 14:56:08 +0000 (15:56 +0100)
See https://gitlab.gnome.org/GNOME/vala/issues/607

tests/gir/bug651773.test
tests/gir/bug788775.test
tests/gir/delegate-array-length-type.test
tests/gir/method-array-length-type.test
tests/gir/parameter-array-length-type.test
vala/valagirparser.vala

index 7f499de5b7d85c705d08bae0f2d6d29289f0b330..ff97bc290f6a3826a8afa8d9602baeeb503d768e 100644 (file)
@@ -20,5 +20,5 @@ Input:
 
 Output:
 
-[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h")]
-public static unowned uint8[] get_array ();
+[CCode (array_length_pos = 0.1, cheader_filename = "test.h")]
+public static unowned uint8[:size_t] get_array ();
index 80ae7cd212a49993f4a146ea4770635b9cba4677..08a6a90e5d0628f32914bafe33c2f21fdfbfd3e1 100644 (file)
@@ -25,5 +25,5 @@ Input:
 
 Output:
 
-[CCode (array_length = true, array_length_pos = 1.1, array_length_type = "gsize", array_null_terminated = true, cheader_filename = "test.h")]
-public static string[] get_string_list (string key);
+[CCode (array_length = true, array_length_pos = 1.1, array_null_terminated = true, cheader_filename = "test.h")]
+public static string[:size_t] get_string_list (string key);
index 127ac8a7638f6f1101ca22b4a9f4505a7dd63f4c..798955dd3349293a6264c846bbbdb89824829fe9 100644 (file)
@@ -24,5 +24,5 @@ Input:
 
 Output:
 
-[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h", instance_pos = 0.9)]
-public delegate string[] Foo ();
+[CCode (array_length_pos = 0.1, cheader_filename = "test.h", instance_pos = 0.9)]
+public delegate string[:size_t] Foo ();
index b7ebccfc540220157f371c2f87b6b8b79f9ec2e9..b13df3967ae15a09f582c923d6d06de1a0ad4ddb 100644 (file)
@@ -17,5 +17,5 @@ Input:
 
 Output:
 
-[CCode (array_length_pos = 0.1, array_length_type = "gsize", cheader_filename = "test.h")]
-public static string[] function ();
+[CCode (array_length_pos = 0.1, cheader_filename = "test.h")]
+public static string[:size_t] function ();
index 3bbbe9ec6ef4f67c969916cfb3b74085c6dcf8e5..9c2b22921f4146e6417b13227b083b336542c1cb 100644 (file)
@@ -21,4 +21,4 @@ Input:
 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);
+public static void function ([CCode (array_length_cname = "foo_length", array_length_pos = 1.1)] string[:size_t] foo);
index 3babf74241c2cda2e06e902c3e51d8cc1f319b18..b68d9d9936d4199a853e0a0defcfa7076e1b4318 100644 (file)
@@ -1195,13 +1195,7 @@ public class Vala.GirParser : CodeVisitor {
                                                        var length_field = (Field) array_length.symbol;
                                                        // array has length
                                                        field.set_attribute_string ("CCode", "array_length_cname", length_field.name);
-                                                       var length_type = length_field.variable_type.to_qualified_string ();
-                                                       if (length_type != "int") {
-                                                               var st = parser.root.lookup (length_type);
-                                                               if (st != null) {
-                                                                       field.set_attribute_string ("CCode", "array_length_type", st.get_cname ());
-                                                               }
-                                                       }
+                                                       ((ArrayType) field.variable_type).length_type = length_field.variable_type.copy ();
                                                        field.remove_attribute_argument ("CCode", "array_length");
                                                        field.remove_attribute_argument ("CCode", "array_null_terminated");
                                                }
@@ -1990,17 +1984,13 @@ public class Vala.GirParser : CodeVisitor {
 
        void set_array_ccode (Symbol sym, ParameterInfo info) {
                sym.set_attribute_double ("CCode", "array_length_pos", info.vala_idx);
+               var length_type = info.param.variable_type.copy ();
+               length_type.nullable = false;
                if (sym is Parameter) {
                        sym.set_attribute_string ("CCode", "array_length_cname", info.param.name);
-               }
-               var type_name = info.param.variable_type.to_qualified_string ();
-               if (type_name != "int") {
-                       var st = root.lookup (type_name);
-                       if (st != null) {
-                               if (sym is Callable || sym is Parameter) {
-                                       sym.set_attribute_string ("CCode", "array_length_type", st.get_cname ());
-                               }
-                       }
+                       ((ArrayType) ((Parameter) sym).variable_type).length_type = length_type;
+               } else if (sym is Callable) {
+                       ((ArrayType) ((Callable) sym).return_type).length_type = length_type;
                }
        }