UTF8 Marshaling APIs (#3736)
authorMiguel de Icaza <miguel@gnome.org>
Fri, 14 Oct 2016 18:23:23 +0000 (14:23 -0400)
committerGitHub <noreply@github.com>
Fri, 14 Oct 2016 18:23:23 +0000 (14:23 -0400)
commit4056e80006ee934ec024215cf998baf66aa8d6ae
treebfcd752caa623e41000455f3c860b5eda08cb722
parentfbc8e9daafe5cb81c7415a21e250251732d1757b
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.
13 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]
scripts/mono-package-runtime [changed mode: 0644->0755]