GNOME Bugzilla – Bug 670483
[CCode (instance_pos = -1)] should be removed from boilerplate code.
Last modified: 2012-02-25 12:40:23 UTC
When creating a Vala project, the boiler plate code includes this snippet: [CCode (instance_pos = -1)] public void on_destroy (Widget window) { Gtk.main_quit(); } The [CCode (instance_pos = -1)] is unnecessary and confusing, especially for beginners. It should be removed.
Done, simply assuming that you are right and that it is unnecessary.
Thanks!
The [CCode (instance_pos = -1)] is actually needed when using Gtk.Builder.connect_signals. Even if it won't segfault in this example, trying to access either 'window' or 'this' will probably do. So it needs to be there when using GtkBuilder.
Ah, I see, that was the reason. I will revert the change and add an explanation comment.
Created attachment 208320 [details] [review] project-wizard: only add [CCode (instance_pos = -1)] when using GtkBuilder
Review of attachment 208320 [details] [review]: Thanks!
If GtkBuilder is using GModule to find a version (ie: for signal handler names specified in the builder file) then this CCode attribute is necessary. For signals that are connected manually in the code like: widget.signal.connect(func); then you don't need the attribute. The compiler is clever enough to figure it out. In the case of the sniplet, the on_destroy function is used like so: window.destroy.connect(on_destroy); and therefore never needs the attribute. btw: The commit to revert this is broken in any case because you added back the attribute to main(), not on_destroy().
Created attachment 208341 [details] [review] project-wizard: [CCode (instance_pos = -1)] should be in the signal callback @Johannes: you shouldn't be accepting patches blindly, even coming from me :-p @Ryan: Depending on whether the user chooses to use GtkBuilder or not, they get either: try { var builder = new Builder (); builder.add_from_file (UI_FILE); builder.connect_signals (this); var window = builder.get_object ("window") as Window; /* ANJUTA: Widgets initialization for [+NameHLower+].ui - DO NOT REMOVE */ window.show_all (); } catch (Error e) { stderr.printf ("Could not load UI: %s\n", e.message); } or Window window = new Window(); window.set_title ("Hello World"); window.show_all(); window.destroy.connect(on_destroy); and in the first case, the signal connection is done using GtkBuilder
@Abdrerrahim: Well, I am wrong sometimes, I have too many patches to review and I need to trust on some people's opinion.