Utf8 (#3776)
authorMiguel de Icaza <miguel@gnome.org>
Thu, 20 Oct 2016 13:19:09 +0000 (08:19 -0500)
committerGitHub <noreply@github.com>
Thu, 20 Oct 2016 13:19:09 +0000 (08:19 -0500)
commitb313769878e1d96c2b50fb1c96be229282d74a30
tree13f7d0133f6c67f8bf5fd7308cb864f71e4ab62b
parent7d40fd72f65b952d492bcd2fd45f95e0569a48d3
Utf8 (#3776)

* UTF8 Marshaling APIs  (#3736)

Adds support for the new UTF8 marshaling functionality in .NET, there
is support for the new MarshalAs(UnmanagedType.LPUTF8St) as well as a
handful of convenience methods in Marshal.cs

In Mono, this is mostly a pass-through as we have historically only
done UTF8, so this merely adds the constant processing to the runtime.

This fixes a few bugs that the new test suite exhibited: when we
marshaled UTF8 strings, we assumed Chars() == Bytes() and we would end
up chopping when marshaling out, and marshaling in.

There is also an additional behavioral bug that was fixed in
Marshal.cs, unlike the rest of the runtime that treated Ansi as Utf8,
StringToCoTaskMemAnsi behaved as ascii. This brings the API in line
with the rest of the runtime.

The equivalent CoreCLR changes were:

dotnet/coreclr#4793
dotnet/coreclr#6561

This has also surfaced two limitations in Mono's marshaling code,
which is why two sets of tests are disabled: StringBuilder return
types are not handled specially (char * needs to be turned into a new
StringBuilder when present) and StringBuilders with an Out attribute
should update the StringBuilder in place, not make a new copy of it.
12 files changed:
mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
mcs/class/referencesource/mscorlib/system/runtime/interopservices/attributes.cs
mcs/class/referencesource/mscorlib/system/string.cs
mono/metadata/icall-def.h
mono/metadata/marshal.c
mono/metadata/marshal.h
mono/metadata/metadata.c
mono/metadata/metadata.h
mono/tests/Makefile.am
mono/tests/libtest.c
mono/tests/pinvoke-utf8.cs [new file with mode: 0644]