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 670483 - [CCode (instance_pos = -1)] should be removed from boilerplate code.
[CCode (instance_pos = -1)] should be removed from boilerplate code.
Status: RESOLVED FIXED
Product: anjuta
Classification: Applications
Component: plugins: project-wizard
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Sébastien Granjoux
Anjuta maintainers
Depends on:
Blocks:
 
 
Reported: 2012-02-20 20:38 UTC by Tiffany Antopolski
Modified: 2012-02-25 12:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
project-wizard: only add [CCode (instance_pos = -1)] when using GtkBuilder (928 bytes, patch)
2012-02-24 09:03 UTC, Abderrahim Kitouni
committed Details | Review
project-wizard: [CCode (instance_pos = -1)] should be in the signal callback (1.15 KB, patch)
2012-02-24 13:10 UTC, Abderrahim Kitouni
none Details | Review

Description Tiffany Antopolski 2012-02-20 20:38:35 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.
Comment 1 Johannes Schmid 2012-02-20 21:02:19 UTC
Done, simply assuming that you are right and that it is unnecessary.
Comment 2 Tiffany Antopolski 2012-02-20 21:35:28 UTC
Thanks!
Comment 3 Abderrahim Kitouni 2012-02-22 17:00:42 UTC
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.
Comment 4 Johannes Schmid 2012-02-23 20:21:06 UTC
Ah, I see, that was the reason. I will revert the change and add an explanation comment.
Comment 5 Abderrahim Kitouni 2012-02-24 09:03:58 UTC
Created attachment 208320 [details] [review]
project-wizard: only add [CCode (instance_pos = -1)] when using GtkBuilder
Comment 6 Johannes Schmid 2012-02-24 10:22:38 UTC
Review of attachment 208320 [details] [review]:

Thanks!
Comment 7 Allison Karlitskaya (desrt) 2012-02-24 12:47:31 UTC
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().
Comment 8 Abderrahim Kitouni 2012-02-24 13:10:47 UTC
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
Comment 9 Johannes Schmid 2012-02-25 12:40:23 UTC
@Abdrerrahim: Well, I am wrong sometimes, I have too many patches to review and I need to trust on some people's opinion.