From: Rico Tzschichholz Date: Tue, 10 Oct 2017 12:09:10 +0000 (+0200) Subject: codegen: Prioritize "array_length=true" over "array_null_terminated=true" X-Git-Tag: 0.39.1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a010511b02e165c1c84cd62a13500eaa37e161f;p=thirdparty%2Fvala.git codegen: Prioritize "array_length=true" over "array_null_terminated=true" If arrays claim to have an array-length and also are null-terminated then use and rely on the given length. Adapt the girparser for this and add "array_length = true" accordingly. https://bugzilla.gnome.org/show_bug.cgi?id=788775 --- diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index 815ec1104..090c76558 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -523,7 +523,10 @@ public class Vala.CCodeAttribute : AttributeCache { public bool array_null_terminated { get { if (_array_null_terminated == null) { - if (ccode != null && ccode.has_argument ("array_null_terminated")) { + // If arrays claim to have an array-length and also are null-terminated then rely on the given length + if (ccode != null && ccode.has_argument ("array_length") && ccode.get_bool ("array_length")) { + _array_null_terminated = false; + } else if (ccode != null && ccode.has_argument ("array_null_terminated")) { _array_null_terminated = ccode.get_bool ("array_null_terminated"); } else { _array_null_terminated = get_default_array_null_terminated (); diff --git a/tests/Makefile.am b/tests/Makefile.am index 7f5433292..337dac7a4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,6 +48,7 @@ TESTS = \ basic-types/bug772426.vala \ basic-types/bug777697.test \ basic-types/bug787152.vala \ + basic-types/bug788775.vala \ chainup/class-base.vala \ chainup/class-base-foo.vala \ chainup/class-object.vala \ @@ -298,6 +299,7 @@ TESTS = \ gir/bug651773.test \ gir/bug667751.test \ gir/bug742012.test \ + gir/bug788775.test \ gir/array-fixed-length.test \ gir/delegate-alias-without-target.test \ annotations/deprecated.vala \ diff --git a/tests/basic-types/bug788775.vala b/tests/basic-types/bug788775.vala new file mode 100644 index 000000000..bd92a946d --- /dev/null +++ b/tests/basic-types/bug788775.vala @@ -0,0 +1,10 @@ +void test_compile_only () { + try { + var file = new KeyFile (); + var list = file.get_string_list ("foo", "bar"); + } catch (KeyFileError e) { + } +} + +void main () { +} diff --git a/tests/gir/bug788775.test b/tests/gir/bug788775.test new file mode 100644 index 000000000..80ae7cd21 --- /dev/null +++ b/tests/gir/bug788775.test @@ -0,0 +1,29 @@ +GIR + +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); diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 177339a67..790a1b244 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -2505,8 +2505,8 @@ public class Vala.GirParser : CodeVisitor { if (metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) { array_length_idx = metadata.get_integer (ArgumentType.ARRAY_LENGTH_IDX); } else { - if (no_array_length) { - param.set_attribute_bool ("CCode", "array_length", false); + if (no_array_length || array_null_terminated) { + param.set_attribute_bool ("CCode", "array_length", !no_array_length); } if (array_null_terminated) { param.set_attribute_bool ("CCode", "array_null_terminated", array_null_terminated); @@ -2939,11 +2939,11 @@ public class Vala.GirParser : CodeVisitor { field.set_attribute_string ("CCode", "cname", cname); } if (type is ArrayType) { - if (!no_array_length && !array_null_terminated && array_length_idx > -1) { + if (!no_array_length && array_length_idx > -1) { current.array_length_idx = array_length_idx; } - if (no_array_length) { - field.set_attribute_bool ("CCode", "array_length", false); + if (no_array_length || array_null_terminated) { + field.set_attribute_bool ("CCode", "array_length", !no_array_length); } if (array_null_terminated) { field.set_attribute_bool ("CCode", "array_null_terminated", true); @@ -2977,8 +2977,8 @@ public class Vala.GirParser : CodeVisitor { prop.access = SymbolAccessibility.PUBLIC; prop.external = true; prop.is_abstract = is_abstract; - if (no_array_length) { - prop.set_attribute_bool ("CCode", "array_length", false); + if (no_array_length || array_null_terminated) { + prop.set_attribute_bool ("CCode", "array_length", !no_array_length); } if (array_null_terminated) { prop.set_attribute_bool ("CCode", "array_null_terminated", true); @@ -3168,8 +3168,8 @@ public class Vala.GirParser : CodeVisitor { if (return_type is ArrayType && metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) { return_array_length_idx = metadata.get_integer (ArgumentType.ARRAY_LENGTH_IDX); } else { - if (return_no_array_length) { - s.set_attribute_bool ("CCode", "array_length", false); + if (return_no_array_length || return_array_null_terminated) { + s.set_attribute_bool ("CCode", "array_length", !return_no_array_length); } if (return_array_null_terminated) { s.set_attribute_bool ("CCode", "array_null_terminated", true); diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 4b6453d9c..b68c1aa38 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -4127,7 +4127,7 @@ namespace GLib { public uint64 get_uint64 (string group_name, string key) throws KeyFileError; [Version (since = "2.12")] public double get_double (string group_name, string key) throws KeyFileError; - [CCode (array_length_type = "gsize")] + [CCode (array_length = true, array_length_type = "gsize", array_null_terminated = true)] public string[] get_string_list (string group_name, string key) throws KeyFileError; [CCode (array_length_type = "gsize")] public string[] get_locale_string_list (string group_name, string key, string? locale = null) throws KeyFileError;