GNOME Bugzilla – Bug 624094
Invalid identifier generated for number of values in an EnumClass.
Last modified: 2016-09-18 11:50:57 UTC
While trying to iterate over the values of an Enumeration, invalid C code is generated. The following code enum EnumTest {TEST1, TEST2, TEST3} void main() { EnumClass enumClass = (EnumClass) typeof (EnumTest).class_ref(); unowned EnumValue[] falues = enumClass.values; for (int i = 0; i < falues.length; i++) { unowned EnumValue falue = falues[i]; stdout.printf("%s", falue.value_name); } } this produces: $ valac EnumTest.vala /home/peterpaul/projects/vala/EnumTest.vala.c: In function ‘_vala_main’: /home/peterpaul/projects/vala/EnumTest.vala.c:45: warning: assignment from incompatible pointer type /home/peterpaul/projects/vala/EnumTest.vala.c:45: error: ‘GEnumClass’ has no member named ‘values_length1’ error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) Instead of 'values_length1' it should generate: 'n_values'. The proposal is: > The GLib.EnumClass.values member in gobject-2.0.vapi needs annotation: > [CCode (array_length_cname = "n_values", array_length_type = "guint")] Details can be found in the following thread: http://mail.gnome.org/archives/vala-list/2010-July/msg00071.html
commit 0658b9c0494aeeef16118f2ad954f0c89dd3d679 Author: Jürg Billeter <j@bitron.ch> Date: Mon Jul 12 20:21:08 2010 +0200 Do not require GLib.EnumValue class in bindings Preparation to fix bug 624094. commit 74f496da3cfa4b1d011a08f785aefd8ef750a5b5 Author: Jürg Billeter <j@bitron.ch> Date: Mon Jul 12 20:18:31 2010 +0200 gobject-2.0: Fix EnumClass and FlagsClass bindings
There is still a bug with the bindings in the EnumClass. Consider the following test case: enum TestEnum { ONE, TWO, THREE } void main () { EnumClass e = (EnumClass) typeof (TestEnum).class_ref (); unowned EnumValue[] test = e.values; } The following c code would be generated (because EnumValue is a Compact class): GEnumValue** test; Looking at genums.h on my system I noticed the following: struct _GEnumClass { GTypeClass g_type_class; /*< public >*/ gint minimum; gint maximum; guint n_values; GEnumValue *values; }; There is a problem here because vala generates an array of pointers to GEnumValue's while glib is offering an array of GEnumValue's. I believe the only way to bind that array (GEnumValue *values) correctly (and without pointers in vala) would be to change GEnumValue to a Struct type, instead of a Compact class...
This looks to be fixed in the past.