After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 653143 - Closure passed to async method loses reference to local vars
Closure passed to async method loses reference to local vars
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Async
0.13.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-06-22 00:22 UTC by Nor Jaidi Tuah
Modified: 2018-05-22 14:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
closure passed to async method (555 bytes, text/x-vala)
2011-06-22 00:22 UTC, Nor Jaidi Tuah
Details

Description Nor Jaidi Tuah 2011-06-22 00:22:05 UTC
Created attachment 190404 [details]
closure passed to async method

In this code:
  var f = etc;
  async_func ( () => { fn (f);} );

the lambda may not be able to access
f correctly, sometimes resulting in
a segmentation fault.

In the attachment, the expected output is
        hello
        hello
        hello
        bye
        
But I got:
        hello
        hello
        (null)
        bye

The bug is due to incorrect access to x
in the following:
        var x = "hello";
        f2 (() => {stdout.printf ("%s\n", x);});
Comment 1 Luca Bruno 2011-06-22 06:59:01 UTC
The problem is that x goes out of scope immediately after calling f2.
Workarounds:
1) Use owned delegate parameters.
2) Call f2 (() => {stdout.printf ("%s\n", x);}, (s,r) => { f2.end (r); stdout.printf("end %s\n", x); });

I think it could be possible for vala to keep the data alive until the async method finishes by generating an implicit async callback, like we do already for explicit async callback.
Comment 2 GNOME Infrastructure Team 2018-05-22 14:04:24 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/208.