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 533977 - non-gobject class with no fields not constructed
non-gobject class with no fields not constructed
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.3.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-05-20 06:05 UTC by Jared Moore
Modified: 2008-05-28 19:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
simple fix (1.78 KB, patch)
2008-05-20 06:55 UTC, Jared Moore
committed Details | Review

Description Jared Moore 2008-05-20 06:05:18 UTC
Test case:


using GLib;

public class NoFields {
	public void do_something() {
		stdout.printf("hello\n");
	}

	public static int main(string[] args) {
		new NoFields().do_something();
		return 0;
	}
}

Expected:
"hello"

Actual:
** (process:9592): CRITICAL **: no_fields_do_something: assertion `self != NULL' failed

The problem is that sizeof(NoFields) == 0, so g_slice_new0 returns NULL.

Possible solution: add a dummy char field to struct in code generation if the struct has no other fields.
Comment 1 Jared Moore 2008-05-20 06:55:09 UTC
Created attachment 111203 [details] [review]
simple fix

And here is the fix. Test case added.
Comment 2 Jared Moore 2008-05-20 11:15:21 UTC
Similarly, there is a C compiler error for structs with no fields:

struct.c: In function ‘_main’:
struct.c:22: warning: excess elements in struct initialiser
struct.c:22: warning: (near initialisation for ‘_tmp0’)
Comment 3 Jürg Billeter 2008-05-28 19:33:33 UTC
Confirming, thanks for the patch.
Comment 4 Jürg Billeter 2008-05-28 19:35:17 UTC
2008-05-28  Jürg Billeter  <j@bitron.ch>

	* gobject/valaccodeclassbinding.vala:

	Ensure to not generate empty C structs,
	patch by Jared Moore, fixes bug 533977

Fixed in r1468.