[vala] codegen: Don't create temp var in transform_value if lvalue isn't allowed
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Don't create temp var in transform_value if lvalue isn't allowed
- Date: Mon, 17 Oct 2011 20:19:22 +0000 (UTC)
commit 4c0c5242cecef9d9e4f9c90cf934434416020524
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Oct 17 21:56:49 2011 +0200
codegen: Don't create temp var in transform_value if lvalue isn't allowed
Fixes bug 657378.
codegen/valaccodebasemodule.vala | 19 ++++++++++++-------
tests/Makefile.am | 1 +
tests/structs/bug657378.vala | 7 +++++++
3 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b4c5efd..df7af48 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5102,8 +5102,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public TargetValue transform_value (TargetValue value, DataType? target_type, CodeNode node) {
var type = value.value_type;
var result = ((GLibValue) value).copy ();
- result.value_type = target_type != null ? target_type : type;
- result.value_type = result.value_type.copy ();
var requires_temp_value = false;
if (type.value_owned
@@ -5150,11 +5148,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (target_type is PointerType) {
// manual memory management for pointers
} else if (requires_destroy (type)) {
- var temp_value = create_temp_value (type, false, node);
- temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
- store_value (temp_value, result);
- result.cvalue = get_cvalue_ (temp_value);
- requires_temp_value = false;
+ if (!is_lvalue_access_allowed (type)) {
+ // cannot assign to a temporary variable
+ temp_ref_values.insert (0, result.copy ());
+ } else {
+ var temp_value = create_temp_value (type, false, node);
+ temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
+ store_value (temp_value, result);
+ result.cvalue = get_cvalue_ (temp_value);
+ requires_temp_value = false;
+ }
}
}
@@ -5163,6 +5166,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return result;
}
+ result.value_type = target_type.copy ();
+
if (gvalue_boxing) {
// implicit conversion to GValue
var temp_value = create_temp_value (target_type, true, node, true);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2a896bd..682b128 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,6 +74,7 @@ TESTS = \
structs/bug654646.vala \
structs/bug654753.vala \
structs/bug656693.vala \
+ structs/bug657378.vala \
structs/bug658048.vala \
structs/bug660426.vala \
structs/bug661945.vala \
diff --git a/tests/structs/bug657378.vala b/tests/structs/bug657378.vala
new file mode 100644
index 0000000..5ba8263
--- /dev/null
+++ b/tests/structs/bug657378.vala
@@ -0,0 +1,7 @@
+string foo (string format, ...) {
+ return format.vprintf (va_list ());
+}
+
+void main () {
+ assert (foo ("%s", "foo") == "foo");
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]