GNOME Bugzilla – Bug 533977
non-gobject class with no fields not constructed
Last modified: 2008-05-28 19:35:17 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.
Created attachment 111203 [details] [review] simple fix And here is the fix. Test case added.
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’)
Confirming, thanks for the patch.
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.