[vala/0.14] GVariant: Fix unboxing of Variant to a real non-null struct
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.14] GVariant: Fix unboxing of Variant to a real non-null struct
- Date: Wed, 30 Nov 2011 14:24:20 +0000 (UTC)
commit 998358cc7444a1917ff8e371292bf106ea393888
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Oct 17 12:48:55 2011 +0200
GVariant: Fix unboxing of Variant to a real non-null struct
Fixes bug 661945.
codegen/valaccodebasemodule.vala | 14 ++++++++++++--
tests/Makefile.am | 1 +
tests/structs/bug661945.vala | 11 +++++++++++
3 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 41c0c52..a1565c6 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4549,6 +4549,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (to.is_real_non_null_struct_type ()) {
// structs are returned via out parameter
cfunc.add_parameter (new CCodeParameter ("result", get_ccode_name (to) + "*"));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue_ (result)));
} else if (to is ArrayType) {
// return array length if appropriate
// tmp = _variant_get (variant, &tmp_length);
@@ -4560,11 +4561,20 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- ccode.add_assignment (get_cvalue_ (result), ccall);
+ if (!to.is_real_non_null_struct_type ()) {
+ ccode.add_assignment (get_cvalue_ (result), ccall);
+ } else {
+ ccode.add_expression (ccall);
+ }
push_function (cfunc);
- ccode.add_return (deserialize_expression (to, new CCodeIdentifier ("value"), new CCodeIdentifier ("*result")));
+ CCodeExpression func_result = deserialize_expression (to, new CCodeIdentifier ("value"), new CCodeIdentifier ("*result"));
+ if (to.is_real_non_null_struct_type ()) {
+ ccode.add_assignment (new CCodeIdentifier ("*result"), func_result);
+ } else {
+ ccode.add_return (func_result);
+ }
pop_function ();
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f2384c2..9646dc3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ TESTS = \
structs/bug656693.vala \
structs/bug658048.vala \
structs/bug660426.vala \
+ structs/bug661945.vala \
delegates/delegates.vala \
delegates/bug539166.vala \
delegates/bug595610.vala \
diff --git a/tests/structs/bug661945.vala b/tests/structs/bug661945.vala
new file mode 100644
index 0000000..98ec4a9
--- /dev/null
+++ b/tests/structs/bug661945.vala
@@ -0,0 +1,11 @@
+struct Foo {
+ int a;
+ int b;
+}
+
+void main () {
+ Variant a = Foo() { a=2, b=3 };
+ Foo b = (Foo) a;
+ assert (b.a == 2);
+ assert (b.b == 3);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]