[vala/0.48] codegen: Handle NoWrapper attribute of async methods on caller side



commit 6c6fe9bbcb52e6a55f50421aabb9677bfbf49dba
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Jan 30 21:17:25 2021 +0100

    codegen: Handle NoWrapper attribute of async methods on caller side

 codegen/valaccodemethodcallmodule.vala | 22 ++++++++++++++++++++++
 tests/Makefile.am                      |  1 +
 tests/asynchronous/nowrapper.vala      | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 2d10ad046..358a9896b 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -108,6 +108,28 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                        async_call.call = new CCodeMemberAccess.pointer (vcast, 
get_ccode_vfunc_name (m));
                                        finish_call.call = new CCodeMemberAccess.pointer (vcast, 
get_ccode_finish_vfunc_name (m));
                                }
+                       } else if (m != null && m.get_attribute ("NoWrapper") != null && m.binding == 
MemberBinding.INSTANCE && !(m is CreationMethod)) {
+                               var instance_value = ma.inner.target_value;
+                               if ((ma.member_name == "begin" || ma.member_name == "end") && 
ma.inner.symbol_reference == ma.symbol_reference) {
+                                       var inner_ma = (MemberAccess) ma.inner;
+                                       instance_value = inner_ma.inner.target_value;
+                               }
+                               var pub_inst = get_cvalue_ (instance_value);
+
+                               CCodeFunctionCall? vcast = null;
+                               if (m.parent_symbol is Class) {
+                                       unowned Class base_class = (Class) m.parent_symbol;
+                                       vcast = new CCodeFunctionCall (new CCodeIdentifier 
(get_ccode_type_get_function (base_class)));
+                                       vcast.add_argument (pub_inst);
+                               } else if (m.parent_symbol is Interface) {
+                                       unowned Interface base_iface = (Interface) m.parent_symbol;
+                                       vcast = new CCodeFunctionCall (new CCodeIdentifier 
(get_ccode_type_get_function (base_iface)));
+                                       vcast.add_argument (pub_inst);
+                               }
+                               if (vcast != null) {
+                                       async_call.call = new CCodeMemberAccess.pointer (vcast, 
get_ccode_vfunc_name (m));
+                                       finish_call.call = new CCodeMemberAccess.pointer (vcast, 
get_ccode_finish_vfunc_name (m));
+                               }
                        }
 
                        if (ma.member_name == "begin" && ma.inner.symbol_reference == ma.symbol_reference) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7adde9fd5..b51dff7a2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -630,6 +630,7 @@ TESTS = \
        asynchronous/constructor-argument-check.vala \
        asynchronous/finish-name.vala \
        asynchronous/generator.vala \
+       asynchronous/nowrapper.vala \
        asynchronous/out-parameter-free-on-error.vala \
        asynchronous/out-parameter-invalid.test \
        asynchronous/params-array-invalid.test \
diff --git a/tests/asynchronous/nowrapper.vala b/tests/asynchronous/nowrapper.vala
new file mode 100644
index 000000000..9f199d500
--- /dev/null
+++ b/tests/asynchronous/nowrapper.vala
@@ -0,0 +1,32 @@
+interface IFoo : Object {
+       [NoWrapper]
+       public abstract async int manam ();
+}
+
+class Foo : Object, IFoo {
+       [NoWrapper]
+       public virtual async int bar () {
+               return 23;
+       }
+
+       public async int manam () {
+               return 42;
+       }
+}
+
+MainLoop loop;
+
+void main () {
+       loop = new MainLoop ();
+
+       var foo = new Foo ();
+       foo.bar.begin ((o,r) => {
+               assert (foo.bar.end (r) == 23);
+       });
+       foo.manam.begin ((o,r) => {
+               assert (foo.manam.end (r) == 42);
+               loop.quit ();
+       });
+
+       loop.run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]