From: Rico Tzschichholz Date: Sat, 30 Jan 2021 20:17:25 +0000 (+0100) Subject: codegen: Handle NoWrapper attribute of async methods on caller side X-Git-Tag: 0.51.1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d59cc224337b68d6fad2ebe5a58dda196e901b80;p=thirdparty%2Fvala.git codegen: Handle NoWrapper attribute of async methods on caller side --- diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 74e22fb64..7506e6a52 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 f92314361..0395d0a4e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -643,6 +643,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 (); +}