[bcl] Allow Marshal.SizeOf () to work on pointer types. Fixes #17587.
authorZoltan Varga <vargaz@gmail.com>
Wed, 26 Feb 2014 20:14:39 +0000 (15:14 -0500)
committerZoltan Varga <vargaz@gmail.com>
Wed, 26 Feb 2014 20:14:39 +0000 (15:14 -0500)
mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs
mono/metadata/marshal.c

index e0fa0691844f3ed6b7753e3be6861ece7893165f..259361854b9b85299b3d4d780c1d79010002287b 100644 (file)
@@ -114,6 +114,13 @@ namespace MonoTests.System.Runtime.InteropServices
                        }
                }
 
+               [Test]
+               public unsafe void Sizeof_Pointer ()
+               {
+                       int size = Marshal.SizeOf (typeof (char*));
+                       Assert.IsTrue (size == 4 || size == 8);
+               }
+
                [Test]
                public void PtrToStringWithNull ()
                {
index b638b8fcd88042b9e73d6d391a72b96cd4f369b2..84f20bd86d91c5b87431b6cb9c9b1e66dd5b54d6 100644 (file)
@@ -11800,7 +11800,9 @@ ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionType *rty
 
        layout = (klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK);
 
-       if (layout == TYPE_ATTRIBUTE_AUTO_LAYOUT) {
+       if (type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR) {
+               return sizeof (gpointer);
+       } else if (layout == TYPE_ATTRIBUTE_AUTO_LAYOUT) {
                gchar *msg;
                MonoException *exc;