GNOME Bugzilla – Bug 616600
Structs without initializers cause invalid C code
Last modified: 2011-04-09 08:00:20 UTC
The following vapi results in a valac assertion failure and invalid C code: uuid.vapi: namespace UUid { [SimpleType] [CCode (cname = "uuid_t", cheader_filename = "uuid.h")] struct Uuid { public void clear(); } } Here's what I use to create the object: main.vala: using UUid; static void main() { Uuid uuid = Uuid(); uuid.clear(); } Compiling results in the following: darrenw@washington:~/src/uuid$ valac --vapidir=. --pkg=uuid main.vala ** (valac:16872): CRITICAL **: vala_ccode_unary_expression_construct: assertion `expr != NULL' failed ** (valac:16872): CRITICAL **: vala_ccode_function_call_add_argument: assertion `expr != NULL' failed /home/darrenw/src/uuid/main.vala.c: In function ‘_vala_main’: /home/darrenw/src/uuid/main.vala.c:19: error: too few arguments to function ‘memset’ error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) As far as I can debug this, in CCodeBaseModule.visit_object_creation_expression(), not all code paths result in a value being assigned to 'instance'. When a new CCodeUnaryExpression is later constructed, the null instance value is passed and results in the exception.
Created attachment 166248 [details] [review] Don't create an invalid memset if there is no instance This patch has been working for me for several months now. I don't know enough about valac internals to know if it's the correct solution overall but it doesn't hurt anything either.
commit 77a6580be0000e23ff99f6aba5b2e8aba1decfdc Author: Luca Bruno <lucabru@src.gnome.org> Date: Sat Apr 9 09:49:28 2011 +0200 Forbid implicit construction for SimpleType structs Fixes bug 616600. You can just use "UUid uuid;" if there's no constructor.