[vala/0.48] codegen: Allow boxing of non-external SimpleType structs



commit 650ad5d02ed87433b0ccff66cdb0f1f582245129
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jan 3 09:07:00 2022 +0100

    codegen: Allow boxing of non-external SimpleType structs
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1273

 codegen/valaccodeattribute.vala      |  5 +++--
 tests/Makefile.am                    |  1 +
 tests/structs/simple-type-boxed.vala | 11 +++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index b1e84583e..8fc998711 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 a3a62c22e..9c5796cce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -365,6 +365,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);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]