From: Rico Tzschichholz Date: Mon, 3 Jan 2022 08:07:00 +0000 (+0100) Subject: codegen: Allow boxing of non-external SimpleType structs X-Git-Tag: 0.52.9~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4bb92a420b2b1fec9adf0cff530875d9a476a9c;p=thirdparty%2Fvala.git codegen: Allow boxing of non-external SimpleType structs Fixes https://gitlab.gnome.org/GNOME/vala/issues/1273 --- diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index 052001aed..67c537b09 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -249,7 +249,8 @@ public class Vala.CCodeAttribute : AttributeCache { if (ccode != null) { _dup_function = ccode.get_string ("dup_function"); } - if (_dup_function == null && !sym.external_package && sym is Struct) { + if (_dup_function == null && !sym.external_package + && sym is Struct && !((Struct) sym).is_simple_type ()) { _dup_function = "%sdup".printf (lower_case_prefix); } dup_function_set = true; @@ -1012,7 +1013,7 @@ public class Vala.CCodeAttribute : AttributeCache { } return "%sfree".printf (lower_case_prefix); } else if (sym is Struct) { - if (!sym.external_package) { + if (!sym.external_package && !((Struct) sym).is_simple_type ()) { return "%sfree".printf (lower_case_prefix); } } diff --git a/tests/Makefile.am b/tests/Makefile.am index d58df130a..432ecfeb9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -369,6 +369,7 @@ TESTS = \ structs/gvalue-implicit-comparison.vala \ structs/properties.vala \ structs/simple-type-constructor.vala \ + structs/simple-type-boxed.vala \ structs/simple-type-disposable.test \ structs/bug530605.vala \ structs/bug572091.vala \ diff --git a/tests/structs/simple-type-boxed.vala b/tests/structs/simple-type-boxed.vala new file mode 100644 index 000000000..a2bae9311 --- /dev/null +++ b/tests/structs/simple-type-boxed.vala @@ -0,0 +1,11 @@ +[SimpleType] +struct Foo { + public int i; + public uint j; +} + +void main () { + Foo? foo = { 42, 4711U }; + assert (foo.i == 42); + assert (foo.j == 4711U); +}