[vala/0.50] vala: Include "stdlib.h" for Enum.to_string() (POSIX)



commit 15b34f033078c860486e75bc4e38300adb658dca
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Feb 26 19:19:54 2021 +0100

    vala: Include "stdlib.h" for Enum.to_string() (POSIX)
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1143

 tests/Makefile.am               | 1 +
 tests/posix/enum-to-string.vala | 8 ++++++++
 vala/valaenumvaluetype.vala     | 6 +++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4a65ee31b..0e1e83dc7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1179,6 +1179,7 @@ LINUX_TESTS += \
        posix/struct_only.vala \
        posix/delegate_only.vala \
        posix/enum_only.vala \
+       posix/enum-to-string.vala \
        $(NULL)
 endif
 
diff --git a/tests/posix/enum-to-string.vala b/tests/posix/enum-to-string.vala
new file mode 100644
index 000000000..b50e2fca1
--- /dev/null
+++ b/tests/posix/enum-to-string.vala
@@ -0,0 +1,8 @@
+public enum Foo {
+       BAR,
+       BAZ
+}
+
+void main () {
+       assert (Foo.BAR.to_string () == "FOO_BAR");
+}
diff --git a/vala/valaenumvaluetype.vala b/vala/valaenumvaluetype.vala
index 027c30db1..103828608 100644
--- a/vala/valaenumvaluetype.vala
+++ b/vala/valaenumvaluetype.vala
@@ -48,7 +48,11 @@ public class Vala.EnumValueType : ValueType {
                        to_string_method = new Method ("to_string", string_type);
                        to_string_method.access = SymbolAccessibility.PUBLIC;
                        to_string_method.is_extern = true;
-                       to_string_method.set_attribute_string ("CCode", "cheader_filename", "glib-object.h");
+                       if (CodeContext.get ().profile == Profile.POSIX) {
+                               to_string_method.set_attribute_string ("CCode", "cheader_filename", 
"stdlib.h");
+                       } else {
+                               to_string_method.set_attribute_string ("CCode", "cheader_filename", 
"glib-object.h");
+                       }
                        to_string_method.owner = type_symbol.scope;
                        to_string_method.this_parameter = new Parameter ("this", copy ());
                        to_string_method.scope.add (to_string_method.this_parameter.name, 
to_string_method.this_parameter);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]