GNOME Bugzilla – Bug 590987
Can't box struct's into Value
Last modified: 2010-01-18 23:20:26 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:
BTW, Vala 0.7.5.
Created attachment 140054 [details] Minimal test case
Hi, Confirmed with 0.7.9. Étienne
Created attachment 151643 [details] [review] Bug 590987 - Can't box struct's into Value
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.
Created attachment 151693 [details] New minimal test case Code as described in prior comment.
Created attachment 151719 [details] [review] Bug 590987 - Can't box struct's into Value
Created attachment 151724 [details] [review] Bug 590987 - Can't box struct's into Value
That fixes it!
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.