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 624094 - Invalid identifier generated for number of values in an EnumClass.
Invalid identifier generated for number of values in an EnumClass.
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
0.9.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-11 11:23 UTC by Peterpaul Klein Haneveld
Modified: 2016-09-18 11:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Peterpaul Klein Haneveld 2010-07-11 11:23:05 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
Comment 1 Jürg Billeter 2010-07-12 18:28:55 UTC
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
Comment 2 Aaron Andersen 2010-07-17 07:37:24 UTC
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...
Comment 3 Rico Tzschichholz 2016-09-18 11:50:57 UTC
This looks to be fixed in the past.