GNOME Bugzilla – Bug 629011
vapi bindings for EnumValue and FlagsValue are incorrect
Last modified: 2016-09-15 07:11:43 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.
Created attachment 169723 [details] [review] this patch fixes the bindings for EnumValue and FlagsValue
For the last sentence, I meant to write that FlagsClass.values should be marked as unowned.
Thanks for the bug report. I cannot reproduce it anymore. Closing the bug, please reopen if needed.
@Luca: AFAICT it's fixed for Enum*, but not for Flags*.
(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.
I'm sorry I've just forgot that nullable structs are returned as pointers from functions, so get_first_value() would work correctly.
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
*** Bug 769903 has been marked as a duplicate of this bug. ***