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 771594 - check lifetime assigment to unowned and weak reference
check lifetime assigment to unowned and weak reference
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Semantic Analyzer
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-09-17 16:11 UTC by Michele Dionisio
Modified: 2018-05-22 15:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch for detect possible lifetime error (2.44 KB, patch)
2016-09-17 16:11 UTC, Michele Dionisio
none Details | Review

Description Michele Dionisio 2016-09-17 16:11:35 UTC
Created attachment 335769 [details] [review]
patch for detect possible lifetime error

In my opition it is usefull that vala raise an error (or as minimum) a warning if someone try to assign un an unowned reference something that have reduced lifetime.

for example a code like:
  unowned string a;

  {

    string shorta = "sa";
    a = shorta;
  }
  stdout.printf (a);

has to be detected and raise an error or warning on
a = shorta;

I'm working on a patch for that detection. There is 2 possible scenarious:
1. assigment like in the example before
2. call async function with .begin() syntax where you start executing an async function without wait the end, so the unowned parameter of the async function can became invalid.

for schenario 1. I have the patch attached
Comment 1 Rico Tzschichholz 2016-09-18 15:51:40 UTC
This is quite an if-clause cascade and the changes of codegen/valaccodebasemodule.vala are superfluous.
Comment 2 Michele Dionisio 2016-09-18 16:17:15 UTC
About changes in codegen/valaccodebasemodule.vala. It is true. I fix 2 patch in one. Sorry. But I think it is coninient to apply the patch of codegen/valaccodebasemodule.vala because it only add 'static' on method that can be static so it is not possible to introduce regression and increase speed and code mantenibility.

About the patch itself, have you any comment? Is it for you usefull to coninue to works on in to fully support these type of bug detection and if it is safe replace the warning with an error?

I have some doubus about all the if clauses. The idea was only to detect unowned reference to not null or constant. The other idea was also to alert about 'unown' used on type like int that is surelly copied.

Have you any ideas, suggestions? I will appreciate a lot.

regards
Comment 3 Nor Jaidi Tuah 2016-09-18 23:53:48 UTC
I don't know enough to comment on that deeply nested ifs.
However, I suggest that one patch should only deal with
one issue. In this patch, in addition to trying to fix
the bug, you also made two functions static (unless making
them static is part of the bug fix).
Comment 4 Nor Jaidi Tuah 2016-09-19 00:02:09 UTC
Sorry for my unnecessary comment as the issue was already
noted. I should have read the other comments first before
commenting on the patch.
Comment 5 Rico Tzschichholz 2016-09-19 18:44:02 UTC
@michele, I will try to take a look soon.
Comment 6 GNOME Infrastructure Team 2018-05-22 15:38:32 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/553.