From: Rico Tzschichholz Date: Fri, 26 Feb 2021 18:19:54 +0000 (+0100) Subject: vala: Include "stdlib.h" for Enum.to_string() (POSIX) X-Git-Tag: 0.51.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c59d83c81dfdfea55f8b6cd769a1c948b6e3aa5;p=thirdparty%2Fvala.git vala: Include "stdlib.h" for Enum.to_string() (POSIX) Fixes https://gitlab.gnome.org/GNOME/vala/issues/1143 --- 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);