[marshal] delay dummy string allocation
authorBernhard Urban <bernhard.urban@xamarin.com>
Fri, 2 Jun 2017 08:24:28 +0000 (10:24 +0200)
committerBernhard Urban <bernhard.urban@xamarin.com>
Fri, 2 Jun 2017 15:18:45 +0000 (17:18 +0200)
mono/metadata/marshal.c

index f60de81c46bdd63387cdb457671478449335dcdb..1553ca1d1642cdcb870f1da03d6a19d21c24f2ba 100644 (file)
@@ -4027,12 +4027,6 @@ emit_invoke_call (MonoMethodBuilder *mb, MonoMethod *method,
        gboolean void_ret = FALSE;
        gboolean string_ctor = method && method->string_ctor;
 
-       /* to make it work with our special string constructors */
-       if (!string_dummy) {
-               MONO_GC_REGISTER_ROOT_SINGLE (string_dummy, MONO_ROOT_SOURCE_MARSHAL, "dummy marshal string");
-               string_dummy = mono_string_new_wrapper ("dummy");
-       }
-
        if (virtual_) {
                g_assert (sig->hasthis);
                g_assert (method->flags & METHOD_ATTRIBUTE_VIRTUAL);
@@ -4040,6 +4034,12 @@ emit_invoke_call (MonoMethodBuilder *mb, MonoMethod *method,
 
        if (sig->hasthis) {
                if (string_ctor) {
+                       /* to make it work with our special string constructors */
+                       if (!string_dummy) {
+                               MONO_GC_REGISTER_ROOT_SINGLE (string_dummy, MONO_ROOT_SOURCE_MARSHAL, "dummy marshal string");
+                               string_dummy = mono_string_new_wrapper ("dummy");
+                       }
+
                        if (mono_gc_is_moving ()) {
                                mono_mb_emit_ptr (mb, &string_dummy);
                                mono_mb_emit_byte (mb, CEE_LDIND_REF);