Merge pull request #1631 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mono / metadata / marshal.c
index 99e34e2c4b90fd31cf7b9dfd18084e6be6a10109..db333b21334d7b869291f04e5b7ec76f6f5feef3 100644 (file)
@@ -8138,7 +8138,7 @@ mono_marshal_get_isinst_with_cache (void)
        mono_mb_emit_ldloc (mb, 1);
        mono_mb_emit_byte (mb, CEE_LDC_I4);
        mono_mb_emit_i4 (mb, ~0x1);
-       mono_mb_emit_byte (mb, CEE_CONV_U);
+       mono_mb_emit_byte (mb, CEE_CONV_I);
        mono_mb_emit_byte (mb, CEE_AND);
        mono_mb_emit_ldloc (mb, 0);
        /*if ((cached_vtable & ~0x1)== obj_vtable)*/
@@ -10341,11 +10341,16 @@ ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal (void *ptr)
 void*
 ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem (int size)
 {
+       void *res;
+
 #ifdef HOST_WIN32
-       return CoTaskMemAlloc (size);
+       res = CoTaskMemAlloc (size);
 #else
-       return g_try_malloc ((gulong)size);
+       res = g_try_malloc ((gulong)size);
 #endif
+       if (!res)
+               mono_gc_out_of_memory ((gulong)size);
+       return res;
 }
 
 void
@@ -10361,11 +10366,16 @@ ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem (void *ptr)
 gpointer
 ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem (gpointer ptr, int size)
 {
+       void *res;
+
 #ifdef HOST_WIN32
-       return CoTaskMemRealloc (ptr, size);
+       res = CoTaskMemRealloc (ptr, size);
 #else
-       return g_try_realloc (ptr, (gulong)size);
+       res = g_try_realloc (ptr, (gulong)size);
 #endif
+       if (!res)
+               mono_gc_out_of_memory ((gulong)size);
+       return res;
 }
 
 void*