diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-02-26 19:19:54 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-02-26 19:19:54 +0100 |
commit | 0c59d83c81dfdfea55f8b6cd769a1c948b6e3aa5 (patch) | |
tree | 5af23c77113eeb354924bd8346342ba9e08ba727 | |
parent | 51584fe317612f552a891547133d9dbc14e7ec97 (diff) | |
download | vala-0c59d83c81dfdfea55f8b6cd769a1c948b6e3aa5.tar.gz |
vala: Include "stdlib.h" for Enum.to_string() (POSIX)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1143
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/posix/enum-to-string.vala | 8 | ||||
-rw-r--r-- | vala/valaenumvaluetype.vala | 6 |
3 files changed, 14 insertions, 1 deletions
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); |