[vala] codegen: Unowned delegates can't become owned when captured or in coroutine
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Unowned delegates can't become owned when captured or in coroutine
- Date: Sun, 8 May 2011 07:31:03 +0000 (UTC)
commit f7402d1d0a0ee82b2fc0eba043dcaeab7275e464
Author: Luca Bruno <lucabru src gnome org>
Date: Sun May 8 08:32:14 2011 +0200
codegen: Unowned delegates can't become owned when captured or in coroutine
From a semantic view point it's neither possible to transfer ownership
to an unowned delegate nor destroy its target.
codegen/valaccodememberaccessmodule.vala | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index fb8ed35..a6ab4d6 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -398,13 +398,15 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (param.has_array_length_cexpr) {
result.array_length_cexpr = new CCodeConstant (param.get_array_length_cexpr ());
}
- if (param.captured || is_in_coroutine ()) {
- result.value_type.value_owned = true;
- }
var array_type = result.value_type as ArrayType;
var delegate_type = result.value_type as DelegateType;
+ bool is_unowned_delegate = delegate_type != null && !param.variable_type.value_owned;
+ if ((param.captured || is_in_coroutine ()) && !is_unowned_delegate) {
+ result.value_type.value_owned = true;
+ }
+
if (param.name == "this") {
if (is_in_coroutine ()) {
// use closure
@@ -433,7 +435,9 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (param.name)));
- result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
+ if (result.value_type.value_owned) {
+ result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
+ }
}
} else if (is_in_coroutine ()) {
// use closure
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]