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



commit 0c59d83c81dfdfea55f8b6cd769a1c948b6e3aa5
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 449171ca2..5454911e6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1198,6 +1198,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]