[vala] codegen: Distinguish between Enum and Flags for their to_string()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Distinguish between Enum and Flags for their to_string()
- Date: Fri, 16 Sep 2016 16:44:35 +0000 (UTC)
commit de38563e742fcf4041779ea19ec9458f57fa3879
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Sep 16 18:37:25 2016 +0200
codegen: Distinguish between Enum and Flags for their to_string()
This fixes a GLib-critical while using g_enum_get_value() on a GFlagsClass.
Therefore use g_flags_get_first_value() if needed.
Patch by therebedragons111
https://bugzilla.gnome.org/show_bug.cgi?id=763831
codegen/valagtypemodule.vala | 6 ++++--
tests/Makefile.am | 1 +
tests/enums/bug763831.vala | 13 +++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index f4d3ea2..b732886 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -2185,13 +2185,15 @@ public class Vala.GTypeModule : GErrorModule {
}
// to_string() on a gtype enum
+ bool is_flags = ((Enum) ((EnumValueType) ma.inner.value_type).type_symbol).is_flags;
+
push_line (expr.source_reference);
- var temp_var = get_temp_variable (new CType ("GEnumValue*"), false, expr, false);
+ var temp_var = get_temp_variable (new CType (is_flags ? "GFlagsValue*" : "GEnumValue*"),
false, expr, false);
emit_temp_var (temp_var);
var class_ref = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_ref"));
class_ref.add_argument (new CCodeIdentifier (get_ccode_type_id (ma.inner.value_type)));
- var get_value = new CCodeFunctionCall (new CCodeIdentifier ("g_enum_get_value"));
+ var get_value = new CCodeFunctionCall (new CCodeIdentifier (is_flags ?
"g_flags_get_first_value" : "g_enum_get_value"));
get_value.add_argument (class_ref);
get_value.add_argument ((CCodeExpression) get_ccodenode (((MemberAccess) expr.call).inner));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 58104cb..ca2a52c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -86,6 +86,7 @@ TESTS = \
enums/enums.vala \
enums/flags.vala \
enums/bug673879.vala \
+ enums/bug763831.vala \
structs/structs.vala \
structs/gvalue.vala \
structs/bug530605.vala \
diff --git a/tests/enums/bug763831.vala b/tests/enums/bug763831.vala
new file mode 100644
index 0000000..519fdf3
--- /dev/null
+++ b/tests/enums/bug763831.vala
@@ -0,0 +1,13 @@
+[Flags]
+enum Foo {
+ TEST = 1 << 0;
+}
+
+enum Bar {
+ TEST = 1 << 0;
+}
+
+void main() {
+ Foo.TEST.to_string ();
+ Bar.TEST.to_string ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]