[vala] GAsync: Fix returning out parameters from async methods
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] GAsync: Fix returning out parameters from async methods
- Date: Tue, 28 Jun 2011 10:52:17 +0000 (UTC)
commit 9b22a27ed5ca78b74f56df7456ab321fd535d405
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 28 12:09:04 2011 +0200
GAsync: Fix returning out parameters from async methods
Fixes bug 640721.
codegen/valaccodebasemodule.vala | 9 ++++++++-
codegen/valagasyncmodule.vala | 4 ++--
tests/Makefile.am | 1 +
tests/asynchronous/bug640721.vala | 8 ++++++++
4 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 84d7b30..39adeb4 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3162,11 +3162,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return false;
}
- void return_out_parameter (Parameter param) {
+ public void return_out_parameter (Parameter param) {
var delegate_type = param.variable_type as DelegateType;
var value = load_parameter (param);
+ var old_coroutine = is_in_coroutine ();
+ current_method.coroutine = false;
+
ccode.open_if (get_variable_cexpression (param.name));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (param.name)), get_cvalue_ (value));
@@ -3179,7 +3182,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (param.variable_type.is_disposable ()){
ccode.add_else ();
+ current_method.coroutine = old_coroutine;
ccode.add_expression (destroy_parameter (param));
+ current_method.coroutine = false;
}
ccode.close ();
@@ -3191,6 +3196,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.close ();
}
}
+
+ current_method.coroutine = old_coroutine;
}
public override void visit_return_statement (ReturnStatement stmt) {
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 68469d1..c6843ed 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -371,7 +371,7 @@ public class Vala.GAsyncModule : GSignalModule {
void generate_finish_function (Method m) {
- push_context (new EmitContext ());
+ push_context (new EmitContext (m));
string dataname = Symbol.lower_case_to_camel_case (m.get_cname ()) + "Data";
@@ -418,7 +418,7 @@ public class Vala.GAsyncModule : GSignalModule {
foreach (Parameter param in m.get_parameters ()) {
if (param.direction != ParameterDirection.IN) {
- ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)));
+ return_out_parameter (param);
if (!(param.variable_type is ValueType) || param.variable_type.nullable) {
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), new CCodeConstant ("NULL"));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e3d6a5a..309c72c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -114,6 +114,7 @@ TESTS = \
asynchronous/bug613484.vala \
asynchronous/bug620740.vala \
asynchronous/bug639591.vala \
+ asynchronous/bug640721.vala \
asynchronous/bug641182.vala \
asynchronous/bug646945.vala \
asynchronous/bug652252.vala \
diff --git a/tests/asynchronous/bug640721.vala b/tests/asynchronous/bug640721.vala
new file mode 100644
index 0000000..d7ff612
--- /dev/null
+++ b/tests/asynchronous/bug640721.vala
@@ -0,0 +1,8 @@
+async void foo (out int i) {
+}
+
+void main () {
+ var loop = new MainLoop ();
+ foo ((s,r) => { foo.end (r, null); loop.quit (); });
+ loop.run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]