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 700563 - [PATCH] anjuta-tags: fix scope information parsing in the Vala parser
[PATCH] anjuta-tags: fix scope information parsing in the Vala parser
Status: RESOLVED FIXED
Product: anjuta
Classification: Applications
Component: plugins: symbol-db
git master
Other Linux
: Normal normal
: ---
Assigned To: Massimo Cora'
Anjuta maintainers
Depends on:
Blocks:
 
 
Reported: 2013-05-18 02:16 UTC by Techlive Zheng
Modified: 2013-05-27 12:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Version 1: anjuta-tags: fix scope information parsing in the Vala parser (4.97 KB, patch)
2013-05-18 02:16 UTC, Techlive Zheng
committed Details | Review

Description Techlive Zheng 2013-05-18 02:16:58 UTC
Created attachment 244595 [details] [review]
Version 1: anjuta-tags: fix scope information parsing in the Vala parser

In Vala, structs member is passed by value not by reference, so previous scope information can not be passed out.
Comment 1 Carl-Anton Ingmarsson 2013-05-18 13:57:12 UTC
(In reply to comment #0)
> Created an attachment (id=244595) [details] [review]
> Version 1: anjuta-tags: fix scope information parsing in the Vala parser
> 
> In Vala, structs member is passed by value not by reference, so previous scope
> information can not be passed out.

Which version of valac are you using? Looking at the generated C code it seems like the current code works as it is supposed to, eg. ctags_visitor_scope() gets a pointer to the scope array in the CTagsEntry which it then changes in place.
Comment 2 Techlive Zheng 2013-05-18 14:56:15 UTC
Version 0.20.1, and it does not working here, why is that?
Comment 3 Techlive Zheng 2013-05-18 15:00:25 UTC
And it seems not just me have this problem, see https://github.com/majutsushi/tagbar/issues/121.
Comment 4 Techlive Zheng 2013-05-18 19:11:14 UTC
Here is a portion of generated C code that related to the Vala code `scope (m, entry.scope);`

> CTagsEntry entry = {0};
>
> ...
>
> CTagsEntry _tmp16_;
>
> ...
>
> _tmp16_ = entry;
> ctags_visitor_scope ((ValaSymbol*) _tmp15_, _tmp16_.scope, 2);

As you can see from the above, "scope" is a member of a struct, and the struct is passed by copy not by reference, so the inside change to the scope array has no effect to the outside entry struct.

It is also noted in the [Vala/Tutorial][1], that 

> Structs are stack/inline allocated and copied on assignment.

[1]: https://live.gnome.org/Vala/Tutorial#Structs

I don't know since when this was changed in Vala, but it definitely broke the code.
Comment 5 Carl-Anton Ingmarsson 2013-05-19 09:59:37 UTC
(In reply to comment #4)
> Here is a portion of generated C code that related to the Vala code `scope (m,
> entry.scope);`
> 
> > CTagsEntry entry = {0};
> >
> > ...
> >
> > CTagsEntry _tmp16_;
> >
> > ...
> >
> > _tmp16_ = entry;
> > ctags_visitor_scope ((ValaSymbol*) _tmp15_, _tmp16_.scope, 2);
> 
> As you can see from the above, "scope" is a member of a struct, and the struct
> is passed by copy not by reference, so the inside change to the scope array has
> no effect to the outside entry struct.
> 
> It is also noted in the [Vala/Tutorial][1], that 
> 
> > Structs are stack/inline allocated and copied on assignment.
> 
> [1]: https://live.gnome.org/Vala/Tutorial#Structs
> 
> I don't know since when this was changed in Vala, but it definitely broke the
> code.

You're right, kind of weird though that vala copies the struct before passing one of its members to another function.

Looking at the generated code after the patch it seems that it introduces a leak of the returned array.

> _tmp21_ = ctags_visitor_scope ((ValaSymbol*) _tmp19_, &_tmp20_);
> _vala_array_destroy (entry.scope, 2, (GDestroyNotify) g_free);
> memcpy (entry.scope, _tmp21_, 2 * sizeof (gchar*));

_tmp21_ is then never freed. But I guess memory leaks doesn't matter that much since anjuta-tags is not long running anyway.
Comment 6 Techlive Zheng 2013-05-19 19:34:17 UTC
Is this memory leak related to the Vala compiler or the actual Vala code? If it is the second one, it should be able to be improved. I am not sure though, as a novice to Vala.
Comment 7 Techlive Zheng 2013-05-27 07:53:14 UTC
Hey, any updates on this one?
Comment 8 Carl-Anton Ingmarsson 2013-05-27 11:41:43 UTC
(In reply to comment #6)
> Is this memory leak related to the Vala compiler or the actual Vala code? If it
> is the second one, it should be able to be improved. I am not sure though, as a
> novice to Vala.

I think it's a problem with the vala compiler, anyway I don't think it matters that much so you can go ahead and commit it if you have commit access.
Comment 9 Techlive Zheng 2013-05-27 11:48:25 UTC
> I think it's a problem with the vala compiler, anyway I don't think it matters
> that much so you can go ahead and commit it if you have commit access.

Actually, that is the exactly thing I do not have. Carl, you are the developer, aren't you?
Comment 10 Techlive Zheng 2013-05-27 12:15:48 UTC
Thanks.