]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Include "stdlib.h" for Enum.to_string() (POSIX)
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 26 Feb 2021 18:19:54 +0000 (19:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 27 Feb 2021 19:26:43 +0000 (20:26 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1143

tests/Makefile.am
tests/posix/enum-to-string.vala [new file with mode: 0644]
vala/valaenumvaluetype.vala

index 4a65ee31bae18533bfa786f822a216f933083dca..0e1e83dc7796f446dc046cb81bc710a829a7cf4c 100644 (file)
@@ -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 (file)
index 0000000..b50e2fc
--- /dev/null
@@ -0,0 +1,8 @@
+public enum Foo {
+       BAR,
+       BAZ
+}
+
+void main () {
+       assert (Foo.BAR.to_string () == "FOO_BAR");
+}
index 027c30db13b02b00a12ebac4785552c756ece1f8..1038286087afaeab445683b1e5a41ec46d7904fc 100644 (file)
@@ -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);