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 616600 - Structs without initializers cause invalid C code
Structs without initializers cause invalid C code
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
0.8.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-04-23 07:22 UTC by Darren Warner
Modified: 2011-04-09 08:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't create an invalid memset if there is no instance (666 bytes, patch)
2010-07-21 01:29 UTC, Darren Warner
none Details | Review

Description Darren Warner 2010-04-23 07:22:06 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.
Comment 1 Darren Warner 2010-07-21 01:29:53 UTC
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.
Comment 2 Luca Bruno 2011-04-09 08:00:20 UTC
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.