GNOME Bugzilla – Bug 599487
Calling delegate functions from async functions does not work
Last modified: 2010-01-09 12:56:37 UTC
Created attachment 146171 [details] Example program that calls a delegate function from an async function Compiling the attached test program fails with the following error message: ** (valac:5121): CRITICAL **: vala_data_type_get_value_owned: assertion `self != NULL' failed /home/ph5/src/vala/async-delegate/async-owned-delegate.c:44: error: expected specifier-qualifier-list before ‘AsyncDelegateTestFunc’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c: In function ‘async_delegate_test_async_data_free’: /home/ph5/src/vala/async-delegate/async-owned-delegate.c:89: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:89: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:89: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:90: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:91: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:92: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c: In function ‘async_delegate_test_async’: /home/ph5/src/vala/async-delegate/async-owned-delegate.c:103: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:104: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c: In function ‘async_delegate_test_async_co’: /home/ph5/src/vala/async-delegate/async-owned-delegate.c:140: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:140: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:142: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:142: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:142: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:143: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:144: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target’ /home/ph5/src/vala/async-delegate/async-owned-delegate.c:145: error: ‘AsyncDelegateTestAsyncData’ has no member named ‘f_target_destroy_notify’ error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) The generated C code (also attached) has two problems: 1) The AsyncDelegateTestFunc delegate typedef appears only after the struct _AsyncDelegateTestAsyncData, in which it is referenced. 2) The struct _AsyncDelegateTestAsyncData is missing a GDestroyNotify f_target_destroy_notify member.
Created attachment 146172 [details] Code generated by vala 0.7.7 from async-owned-delegate.vala
Created attachment 146179 [details] [review] codegen: add destroy_notify function for owned delegate parameters to async methods This patch addresses the second issue only. I still do not know how to make Vala emit the delegate function's AsyncDelegateTestFunc typedef before the struct _AsyncDelegateTestAsyncData.
Created attachment 146187 [details] [review] codegen: fix async methods with delegate parameters Add GDestroyNotify function pointer for owned delegate parameters to async methods and make sure the delegate function type is declared before the async data structure. There are no more compilation errors and the result runs fine, but valac still emits this error message: ** (valac:1106): CRITICAL **: vala_data_type_get_value_owned: assertion `self != NULL' failed of which I don't know where it comes from.
I tried this with Vala master, which already adds the GDestroyNotify fields (since the fix for Bug 597294). Unfortunately, now just adding the generate_type_declaration doesn't seem to help anymore. There are no compilation warnings or errors, but two critical error messages: valac[16410]: GLIB CRITICAL ** default - vala_ccode_expression_statement_construct: assertion `expr != NULL' failed valac[16410]: GLIB CRITICAL ** default - vala_ccode_fragment_append: assertion `node != NULL' failed The resulting binary just calls the async function and starts the loop, but never returns into the async function. Program output: async enter loop
The example program works fine with master. Program output: async enter loop delegate async leave