[vala] codegen: Fix critical on delegate cast
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Fix critical on delegate cast
- Date: Thu, 21 Oct 2010 20:31:54 +0000 (UTC)
commit b872fc19f9f83d4ffa51f2ac3e5802413674c1fb
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 21 22:13:55 2010 +0200
codegen: Fix critical on delegate cast
codegen/valaccodebasemodule.vala | 15 ++++++++++-
codegen/valaccodememberaccessmodule.vala | 42 ++++++++++++++---------------
2 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 267a6f4..9a53fc2 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4634,6 +4634,19 @@ public class Vala.CCodeBaseModule : CodeGenerator {
innercexpr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, innercexpr);
}
set_cvalue (expr, new CCodeCastExpression (innercexpr, expr.type_reference.get_cname ()));
+
+ if (expr.type_reference is DelegateType) {
+ if (get_delegate_target (expr.inner) != null) {
+ set_delegate_target (expr, get_delegate_target (expr.inner));
+ } else {
+ set_delegate_target (expr, new CCodeConstant ("NULL"));
+ }
+ if (get_delegate_target_destroy_notify (expr.inner) != null) {
+ set_delegate_target_destroy_notify (expr, get_delegate_target_destroy_notify (expr.inner));
+ } else {
+ set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
+ }
+ }
}
}
@@ -5868,7 +5881,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return glib_value.delegate_target_destroy_notify_cvalue;
}
- public void set_delegate_target_destroy_notify (Expression expr, CCodeExpression destroy_notify) {
+ public void set_delegate_target_destroy_notify (Expression expr, CCodeExpression? destroy_notify) {
var glib_value = (GLibValue) expr.target_value;
if (glib_value == null) {
glib_value = new GLibValue (expr.value_type);
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 6f57813..499819a 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -91,29 +91,27 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
set_cvalue (expr, new CCodeIdentifier (m.get_cname ()));
}
- if (expr.target_type is DelegateType) {
- set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
- if (m.binding == MemberBinding.STATIC) {
- set_delegate_target (expr, new CCodeConstant ("NULL"));
- } else if (m.is_async_callback) {
- if (current_method.closure) {
- var block = ((Method) m.parent_symbol).body;
- set_delegate_target (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), "_async_data_"));
- } else {
- set_delegate_target (expr, new CCodeIdentifier ("data"));
- }
- } else if (expr.inner != null) {
- // expr.inner is null in the special case of referencing the method in a constant initializer
- var delegate_target = (CCodeExpression) get_ccodenode (expr.inner);
- var delegate_type = expr.target_type as DelegateType;
- if ((expr.value_type.value_owned || (delegate_type != null && delegate_type.is_called_once)) && expr.inner.value_type.data_type != null && expr.inner.value_type.data_type.is_reference_counting ()) {
- var ref_call = new CCodeFunctionCall (get_dup_func_expression (expr.inner.value_type, expr.source_reference));
- ref_call.add_argument (delegate_target);
- delegate_target = ref_call;
- set_delegate_target_destroy_notify (expr, get_destroy_func_expression (expr.inner.value_type));
- }
- set_delegate_target (expr, delegate_target);
+ set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
+ if (m.binding == MemberBinding.STATIC) {
+ set_delegate_target (expr, new CCodeConstant ("NULL"));
+ } else if (m.is_async_callback) {
+ if (current_method.closure) {
+ var block = ((Method) m.parent_symbol).body;
+ set_delegate_target (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), "_async_data_"));
+ } else {
+ set_delegate_target (expr, new CCodeIdentifier ("data"));
+ }
+ } else if (expr.inner != null) {
+ // expr.inner is null in the special case of referencing the method in a constant initializer
+ var delegate_target = (CCodeExpression) get_ccodenode (expr.inner);
+ var delegate_type = expr.target_type as DelegateType;
+ if ((expr.value_type.value_owned || (delegate_type != null && delegate_type.is_called_once)) && expr.inner.value_type.data_type != null && expr.inner.value_type.data_type.is_reference_counting ()) {
+ var ref_call = new CCodeFunctionCall (get_dup_func_expression (expr.inner.value_type, expr.source_reference));
+ ref_call.add_argument (delegate_target);
+ delegate_target = ref_call;
+ set_delegate_target_destroy_notify (expr, get_destroy_func_expression (expr.inner.value_type));
}
+ set_delegate_target (expr, delegate_target);
}
} else if (expr.symbol_reference is ArrayLengthField) {
if (expr.value_type is ArrayType && !(expr.parent_node is ElementAccess)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]