[vala] codegen: Fix copy of fixed arrays when elements require copy
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Fix copy of fixed arrays when elements require copy
- Date: Fri, 20 May 2011 13:41:31 +0000 (UTC)
commit 3bb552a242a8dfb4bbd4f5b0ecd01a04081251ad
Author: Luca Bruno <lucabru src gnome org>
Date: Fri May 20 15:18:55 2011 +0200
codegen: Fix copy of fixed arrays when elements require copy
Fixes bug 613840.
codegen/valaccodebasemodule.vala | 12 ++++++++----
tests/Makefile.am | 1 +
tests/objects/bug613840.vala | 5 +++++
3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9fb3ca3..55ecb69 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5197,10 +5197,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (target_type.value_owned && (!type.value_owned || boxing || unboxing)) {
// need to copy value
if (requires_copy (target_type) && !(type is NullType)) {
- var decl = get_temp_variable (target_type, true, node, false);
- emit_temp_var (decl);
- ccode.add_assignment (get_variable_cexpression (decl.name), get_cvalue_ (copy_value (result, node)));
- result.cvalue = get_variable_cexpression (decl.name);
+ result = (GLibValue) copy_value (result, node);
+ // drop this assignment when target values are guaranteed to be effect-free
+ if (!(target_type is ArrayType && ((ArrayType) target_type).fixed_length)) {
+ var decl = get_temp_variable (target_type, true, node, false);
+ emit_temp_var (decl);
+ ccode.add_assignment (get_variable_cexpression (decl.name), get_cvalue_ (result));
+ result.cvalue = get_variable_cexpression (decl.name);
+ }
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3169591..1f8fec7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ TESTS = \
objects/bug597155.vala \
objects/bug597161.vala \
objects/bug613486.vala \
+ objects/bug613840.vala \
objects/bug620706.vala \
objects/bug624594.vala \
objects/bug628639.vala \
diff --git a/tests/objects/bug613840.vala b/tests/objects/bug613840.vala
new file mode 100644
index 0000000..baf7fe5
--- /dev/null
+++ b/tests/objects/bug613840.vala
@@ -0,0 +1,5 @@
+void main () {
+ Object a[1] = {new Object()};
+ Object b[1] = a;
+ assert (a[0] == b[0]);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]