[vala] Fix `this' access in default signal handlers
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Fix `this' access in default signal handlers
- Date: Wed, 16 Sep 2009 22:46:11 +0000 (UTC)
commit a8f55b462213540c644936fa52693f0e2d039cc0
Author: Yu Feng <rainwoodman gmail com>
Date: Mon Aug 31 20:21:45 2009 -0400
Fix `this' access in default signal handlers
Fixes bug 593734.
vala/valaclass.vala | 30 ++++++++++++++++++++++++++++++
vala/valasignal.vala | 7 ++++++-
2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index dad8b8a..bf4105e 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -361,6 +361,36 @@ public class Vala.Class : ObjectTypeSymbol {
}
/**
+ * Adds the specified method as a hidden member to this class,
+ * primarily used for default signal handlers.
+ *
+ * The hidden methods are not part of the `methods` collection.
+ *
+ * There may also be other use cases, eg, convert array.resize() to
+ * this type of method?
+ *
+ * @param m a method
+ */
+ public void add_hidden_method (Method m) {
+ if (m.binding == MemberBinding.INSTANCE) {
+ if (m.this_parameter != null) {
+ m.scope.remove (m.this_parameter.name);
+ }
+ m.this_parameter = new FormalParameter ("this", get_this_type ());
+ m.scope.add (m.this_parameter.name, m.this_parameter);
+ }
+ if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
+ if (m.result_var != null) {
+ m.scope.remove (m.result_var.name);
+ }
+ m.result_var = new LocalVariable (m.return_type.copy (), "result");
+ m.result_var.is_result = true;
+ }
+
+ scope.add (null, m);
+ }
+
+ /**
* Returns a copy of the list of methods.
*
* @return list of methods
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index f51a922..a30e112 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -247,6 +247,8 @@ public class Vala.Signal : Member, Lockable {
if (is_virtual) {
default_handler = new Method (name, return_type, source_reference);
+
+ default_handler.owner = owner;
default_handler.access = access;
default_handler.external = external;
default_handler.is_virtual = true;
@@ -254,11 +256,14 @@ public class Vala.Signal : Member, Lockable {
default_handler.signal_reference = this;
default_handler.body = body;
+
foreach (FormalParameter param in parameters) {
default_handler.add_parameter (param);
}
- parent_symbol.scope.add (null, default_handler);
+ var cl = parent_symbol as Class;
+
+ cl.add_hidden_method (default_handler);
default_handler.check (analyzer);
}
return !error;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]