]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Allow boxing of non-external SimpleType structs
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 3 Jan 2022 08:07:00 +0000 (09:07 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 4 Jan 2022 11:28:44 +0000 (12:28 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1273

codegen/valaccodeattribute.vala
tests/Makefile.am
tests/structs/simple-type-boxed.vala [new file with mode: 0644]

index 052001aedb48dfab3ef0d7ab7a6b41b3761dda66..67c537b09694144c39e89e81b380df51a77773fa 100644 (file)
@@ -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);
                        }
                }
index d58df130a88f2f991ea4f5f1b4c969dab509792e..432ecfeb9761b0c5c57099c04268cddaa8e2e2a5 100644 (file)
@@ -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 (file)
index 0000000..a2bae93
--- /dev/null
@@ -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);
+}