On Sat, Oct 24, 2009 at 12:59 PM, Jan Hudec <b...@ucw.cz> wrote:
> On Fri, Oct 23, 2009 at 15:31:53 +0200, pHilipp Zabel wrote:
>> Hi,
>>
>> I'd like to call a delegate function from an async function, like this:
>>
>> class AsyncDelegate {
>>         delegate void TestFunc ();
>>
>>         void test_func () {
>>                 print ("delegate\n");
>>         }
>>
>>         async void test_async (TestFunc f) {
>
> Can you try it with
>
>    async void test_async (owned TestFunc f) {
>
> ?

Thanks, but that doesn't work either.
I filed a bug, details at https://bugzilla.gnome.org/show_bug.cgi?id=599487

The first problem is that the AsyncDelegateTestFunc delegate typedef
in the generated code appears only after the struct
_AsyncDelegateTestAsyncData, in which it is referenced.

The second problem is that the struct _AsyncDelegateTestAsyncData is
missing a GDestroyNotify f_target_destroy_notify member, even after I
add the owned keyword as you suggest.

>>                 print ("async enter\n");
>>                 Idle.add (test_async.callback);
>>                 yield;
>>                 f ();
>>                 print ("async leave\n");
>>         }
>>
>>         static int main (string[] args) {
>>                 var loop = new GLib.MainLoop (null, false);
>>                 var app = new AsyncDelegate ();
>>
>>                 app.test_async.begin (app.test_func);
>>                 print ("loop\n");
>>                 loop.run ();
>>
>>                 return 0;
>>         }
>> }
>>
>> But Vala 0.7.7 doesn't like that at all:
>>
>> ** (valac:7627): CRITICAL **: vala_data_type_get_value_owned:
>> assertion `self != NULL' failed
>> /home/ph5/vala/async-delegate/async-delegate.vala.c:44: error:
>> expected specifier-qualifier-list before Б─≤AsyncDelegateTestFuncБ─≥
>> [...]
>> Compilation failed: 1 error(s), 0 warning(s)
>
> It can't work with unowned delegate (add 'owned' as mentioned above), because
> vala can't guarantee the invocant will be valid by the time the async
> function gets to call it.
>
> However, vala should report an understandable error, so filing a bug would be
> appropriate.

I see. I filed a second bug for the error messages:
https://bugzilla.gnome.org/show_bug.cgi?id=599488

>> When I turn test_async into a sync function again, it works just fine.
>
> There the delegate invocant does not get a chance to go away while test_async
> runs, so the unowned delegate works fine.
>
>> Trying to turn TestFunc into an async delegate function (and call it
>> with yield f ()) on the other hand, seems to be even more critical:
>
> I don't think async delegates were ever supposed to be supported. Given that
> async function is really two functions an async delegate would be pretty
> complicated.

Ok, this test was just out of curiosity anyway :)

> That said, vala should give some sane error message.

Agreed.

cheers
Philipp
_______________________________________________
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to