[vala/0.52] codegen: Allow boxing of non-external SimpleType structs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52] codegen: Allow boxing of non-external SimpleType structs
- Date: Tue, 4 Jan 2022 11:44:32 +0000 (UTC)
commit b4bb92a420b2b1fec9adf0cff530875d9a476a9c
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 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);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]