diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2018-09-14 15:21:24 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2018-09-14 15:21:24 +0300 |
commit | e0221129db0f2e71f13bd7cc75cf7e6efd83040e (patch) | |
tree | 899d219b90d16d874bd93353df5792fcf3d6ad66 | |
parent | fbaeba4fec17df1c730550e2355316121f309976 (diff) |
[runtime] Fix Marshal.SizeOf (typeof (void)). (#10601)
Fixes https://github.com/mono/mono/issues/10303.
-rw-r--r-- | mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs | 7 | ||||
-rw-r--r-- | mono/metadata/marshal.c | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs b/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs index 706b8f1a526..a05483f00e3 100644 --- a/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs +++ b/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs @@ -121,6 +121,13 @@ namespace MonoTests.System.Runtime.InteropServices } [Test] + public unsafe void Sizeof_Void () + { + int size = Marshal.SizeOf (typeof (void)); + Assert.AreEqual (1, size); + } + + [Test] public void PtrToStringWithNull () { Assert.IsNull (Marshal.PtrToStringAnsi (IntPtr.Zero), "A"); diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 63062a9a5c8..d7c0d782834 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -5111,6 +5111,8 @@ ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionTypeHandl if (type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR) { return sizeof (gpointer); + } else if (type->type == MONO_TYPE_VOID) { + return 1; } else if (layout == TYPE_ATTRIBUTE_AUTO_LAYOUT) { mono_error_set_argument (error, "t", "Type %s cannot be marshaled as an unmanaged structure.", m_class_get_name (klass)); return 0; |