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 590987 - Can't box struct's into Value
Can't box struct's into Value
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
0.7.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-08-06 19:20 UTC by Jim Nelson
Modified: 2010-01-18 23:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal test case (115 bytes, text/x-vala)
2009-08-06 19:21 UTC, Jim Nelson
  Details
Bug 590987 - Can't box struct's into Value (1.06 KB, patch)
2010-01-18 00:26 UTC, Marc-Andre Lureau
none Details | Review
New minimal test case (175 bytes, text/x-vala)
2010-01-18 18:36 UTC, Jim Nelson
  Details
Bug 590987 - Can't box struct's into Value (1.97 KB, patch)
2010-01-18 22:04 UTC, Marc-Andre Lureau
none Details | Review
Bug 590987 - Can't box struct's into Value (2.51 KB, patch)
2010-01-18 22:56 UTC, Marc-Andre Lureau
none Details | Review

Description Jim Nelson 2009-08-06 19:20:43 UTC
Please describe the problem:
Boxing a struct into a Value generates bad C code.  Test case:

struct Simple {
    public int a;
}

void main() {
    Simple s = Simple();
    s.a = 64;
    
    Value v = s;
}

valac generates a warning for an unused variable and gcc reports an error:

test.vala:10.11-10.15: warning: local variable `v' declared but never used
    Value v = s;
          ^^^^^
/home/jim/prj/test/test.c: In function ‘_main’:
/home/jim/prj/test/test.c:52: error: incompatible type for argument 2 of ‘g_value_set_boxed’
error: cc exited with status 256

The C line in question is this:

	v = (g_value_init (&_tmp1_, TYPE_SIMPLE), g_value_set_boxed (&_tmp1_, s), _tmp1_);

... where 's' passed to g_value_set_boxed is a struct.  It should be passing the addess of the struct.

Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Jim Nelson 2009-08-06 19:21:12 UTC
BTW, Vala 0.7.5.
Comment 2 Jim Nelson 2009-08-06 19:21:50 UTC
Created attachment 140054 [details]
Minimal test case
Comment 3 Étienne Bersac 2010-01-06 13:30:33 UTC
Hi,

Confirmed with 0.7.9.

Étienne
Comment 4 Marc-Andre Lureau 2010-01-18 00:26:23 UTC
Created attachment 151643 [details] [review]
Bug 590987 - Can't box struct's into Value
Comment 5 Jim Nelson 2010-01-18 18:35:40 UTC
This is closer, but now I can't convert from the boxed struct back to the struct.  I'm testing this with a patched version of trunk.

The original code works:

struct Simple {
    public int a;
}

void main() {
    Simple s = Simple();
    s.a = 64;

    Value v = s;
}

(Except for an unused variable warning -- no big deal.)

However, the next logical step won't compile:

struct Simple {
    public int a;
}

void main() {
    Simple s = Simple();
    s.a = 64;

    Value v = s;
    
    Simple s2 = (Simple) v;
    stdout.printf("%d", s2.a);
}

/home/jim/prj/test/test.c: In function ‘_main’:
/home/jim/prj/test/test.c:58: error: incompatible types when assigning to type ‘Simple’ from type ‘gpointer’
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)

It's this line of C code:

	s2 = g_value_get_boxed (&v);

s2 is declared as Simple (not Simple*), hence the error.
Comment 6 Jim Nelson 2010-01-18 18:36:40 UTC
Created attachment 151693 [details]
New minimal test case

Code as described in prior comment.
Comment 7 Marc-Andre Lureau 2010-01-18 22:04:30 UTC
Created attachment 151719 [details] [review]
Bug 590987 - Can't box struct's into Value
Comment 8 Marc-Andre Lureau 2010-01-18 22:56:01 UTC
Created attachment 151724 [details] [review]
Bug 590987 - Can't box struct's into Value
Comment 9 Jim Nelson 2010-01-18 23:09:56 UTC
That fixes it!
Comment 10 Jürg Billeter 2010-01-18 23:20:26 UTC
commit 20c007d53cdcfb84da9e75243a9cdd8aea914399
Author: Marc-André Lureau <marcandre.lureau@gmail.com>
Date:   Mon Jan 18 01:26:20 2010 +0100

    GValue: Fix boxing and unboxing structs
    
    Fixes bug 590987.