GNOME Bugzilla – Bug 700563
[PATCH] anjuta-tags: fix scope information parsing in the Vala parser
Last modified: 2013-05-27 12:16:06 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.
(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.
Version 0.20.1, and it does not working here, why is that?
And it seems not just me have this problem, see https://github.com/majutsushi/tagbar/issues/121.
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.
(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.
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.
Hey, any updates on this one?
(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.
> 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?
Thanks.