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 629011 - vapi bindings for EnumValue and FlagsValue are incorrect
vapi bindings for EnumValue and FlagsValue are incorrect
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 769903 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-09-08 00:09 UTC by Jordan Yelloz
Modified: 2016-09-15 07:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
this patch fixes the bindings for EnumValue and FlagsValue (1.00 KB, patch)
2010-09-08 00:11 UTC, Jordan Yelloz
none Details | Review

Description Jordan Yelloz 2010-09-08 00:09:24 UTC
Currently, if you try to iterate over the values of an enum, the following code should work:

--------
using EnumTest;

namespace EnumTest {
    enum Blah { AAAAAA, BBBBB, ARRRR, ASDAD_MORE_WORDS }
}

void main (){

    Type t = typeof (Blah);
    assert (t.is_enum ());
    EnumClass c = (EnumClass) t.class_ref ();

    foreach (EnumValue v in c.values){
        message ("%s.%s = %s", t.name (), v.value_name, v.value_nick);
    }

}

--------

However, it does not compile because the bindings for EnumValue and FlagsValue are incorrect.  I believe they should both be structs, not classes.
Also, the values array in EnumClass is not marked as unowned.
Comment 1 Jordan Yelloz 2010-09-08 00:11:06 UTC
Created attachment 169723 [details] [review]
this patch fixes the bindings for EnumValue and FlagsValue
Comment 2 Jordan Yelloz 2010-09-08 00:15:30 UTC
For the last sentence, I meant to write that FlagsClass.values should be marked as unowned.
Comment 3 Luca Bruno 2011-08-08 11:12:18 UTC
Thanks for the bug report. I cannot reproduce it anymore. Closing the bug, please reopen if needed.
Comment 4 Michal Hruby 2011-08-08 23:00:23 UTC
@Luca: AFAICT it's fixed for Enum*, but not for Flags*.
Comment 5 Luca Bruno 2011-08-09 09:10:39 UTC
(In reply to comment #4)
> @Luca: AFAICT it's fixed for Enum*, but not for Flags*.

You can use unowned FlagsValue when iterating. Using structs would break FlagsClass.get_first_value() & co. In fact, they are broken for EnumClass.
The fix is:
1) Make EnumValue be a compact class.
2) Turn EnumValue and FlagsValue fields to be owned.
3) Turn values to be owned.

When you iterate over values, just use the unowned keyword.
Comment 6 Luca Bruno 2011-08-09 09:12:12 UTC
I'm sorry I've just forgot that nullable structs are returned as pointers from functions, so get_first_value() would work correctly.
Comment 7 Rico Tzschichholz 2016-09-15 07:10:02 UTC
commit 958ceca96d24c50cba548677976562c8f06a1443
Author: Rico Tzschichholz <ricotz@ubuntu.com>
Date:   Thu Sep 15 09:06:13 2016 +0200

    gobject-2.0: Make FlagsClass.values weak
    
    In addition to 950f081bae86a98a7918b5fc4a9c3acd15681c8e

commit 950f081bae86a98a7918b5fc4a9c3acd15681c8e
Author: Rico Tzschichholz <ricotz@ubuntu.com>
Date:   Tue Aug 30 18:35:06 2016 +0200

    gobject-2.0: Fix and make FlagsValue a struct
    
    Based on patch by therebedragons111
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769903
Comment 8 Rico Tzschichholz 2016-09-15 07:11:16 UTC
*** Bug 769903 has been marked as a duplicate of this bug. ***