From: Rico Tzschichholz Date: Sun, 26 Nov 2023 12:23:18 +0000 (+0100) Subject: girparser: Don't blindly translate utf8 to string and check the ctype too X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d724d6d96f8e59fe8714a4b2a9cf47b8d04b0161;p=thirdparty%2Fvala.git girparser: Don't blindly translate utf8 to string and check the ctype too This fixes array out-parameters with ctype "char**" and array return values with ctype "char*". --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 2fb805f89..0b4a8396d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -899,9 +899,11 @@ TESTS = \ gir/gtype-struct-name.gir \ gir/instance-parameter-owned.gir \ gir/method-array-length-type.gir \ + gir/method-array-return.gir \ gir/method-class.gir \ gir/method-nowrapper.gir \ gir/parameter-array-length-type.gir \ + gir/parameter-array-out.gir \ gir/parameter-nullable-out-simple-type.gir \ gir/property-non-readable.gir \ gir/signal-virtual.gir \ diff --git a/tests/gir/method-array-return.gir b/tests/gir/method-array-return.gir new file mode 100644 index 000000000..3c961aab2 --- /dev/null +++ b/tests/gir/method-array-return.gir @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/gir/method-array-return.vapi-expected b/tests/gir/method-array-return.vapi-expected new file mode 100644 index 000000000..a9c9ef890 --- /dev/null +++ b/tests/gir/method-array-return.vapi-expected @@ -0,0 +1,5 @@ +[CCode (cprefix = "Test", gir_namespace = "Test", gir_version = "1.0", lower_case_cprefix = "test_")] +namespace Test { + [CCode (array_length_pos = 0.1, array_length_type = "guint", cheader_filename = "test.h")] + public static char[] function (); +} diff --git a/tests/gir/parameter-array-out.gir b/tests/gir/parameter-array-out.gir new file mode 100644 index 000000000..c48575603 --- /dev/null +++ b/tests/gir/parameter-array-out.gir @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/gir/parameter-array-out.vapi-expected b/tests/gir/parameter-array-out.vapi-expected new file mode 100644 index 000000000..ea15a47e6 --- /dev/null +++ b/tests/gir/parameter-array-out.vapi-expected @@ -0,0 +1,5 @@ +[CCode (cprefix = "Test", gir_namespace = "Test", gir_version = "1.0", lower_case_cprefix = "test_")] +namespace Test { + [CCode (cheader_filename = "test.h")] + public static void function ([CCode (array_length_cname = "size", array_length_pos = 0.5, array_length_type = "guint")] out char[] text); +} diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 3f5cc8424..ed685cd7f 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -2870,7 +2870,12 @@ public class Vala.GirParser : CodeVisitor { } else { bool known_type = true; if (type_name == "utf8") { - type_name = "string"; + if (ctype == null || ctype.has_suffix ("*") || ctype == "gpointer" || ctype == "gconstpointer") { + type_name = "string"; + } else { + //FIXME Work around a g-ir-scanner bug + type_name = "char"; + } } else if (type_name == "gboolean") { type = new BooleanType ((Struct) context.root.scope.lookup ("bool")); } else if (type_name == "gchar") {