Merge pull request #4845 from lambdageek/dev-coop-delegates
[mono.git] / mono / metadata / marshal.c
index 4eedbaae3b678ea6db9f67fa75256e977426efe4..f60de81c46bdd63387cdb457671478449335dcdb 100644 (file)
@@ -222,7 +222,10 @@ static void
 mono_icall_end (MonoThreadInfo *info, HandleStackMark *stackmark, MonoError *error);
 
 static MonoObjectHandle
-mono_icall_handle_new_full (gpointer rawobj, MonoBoolean interior);
+mono_icall_handle_new (gpointer rawobj);
+
+static MonoObjectHandle
+mono_icall_handle_new_interior (gpointer rawobj);
 
 /* Lazy class loading functions */
 static GENERATE_GET_CLASS_WITH_CACHE (string_builder, "System.Text", "StringBuilder");
@@ -397,7 +400,8 @@ mono_marshal_init (void)
                register_icall (mono_threads_detach_coop, "mono_threads_detach_coop", "void ptr ptr", TRUE);
                register_icall (mono_icall_start, "mono_icall_start", "ptr ptr ptr", TRUE);
                register_icall (mono_icall_end, "mono_icall_end", "void ptr ptr ptr", TRUE);
-               register_icall (mono_icall_handle_new_full, "mono_icall_handle_new_full", "ptr ptr bool", TRUE);
+               register_icall (mono_icall_handle_new, "mono_icall_handle_new", "ptr ptr", TRUE);
+               register_icall (mono_icall_handle_new_interior, "mono_icall_handle_new_interior", "ptr ptr", TRUE);
 
                mono_cominterop_init ();
                mono_remoting_init ();
@@ -6093,8 +6097,10 @@ emit_marshal_object (EmitMarshalContext *m, int argnum, MonoType *t,
                        mono_mb_emit_ldloc (mb, 0);
                        mono_mb_emit_icall (mb, conv_to_icall (MONO_MARSHAL_CONV_FTN_DEL, NULL));
                        mono_mb_emit_stloc (mb, 3);
-               } else if (klass == mono_defaults.stringbuilder_class){
-                       // FIXME: implement
+               } else if (klass == mono_defaults.stringbuilder_class) {
+                       // FIXME:
+                       char *msg = g_strdup_printf ("Return marshalling of stringbuilders is not implemented.");
+                       mono_mb_emit_exception_marshal_directive (mb, msg);
                } else {
                        /* set src */
                        mono_mb_emit_stloc (mb, 0);
@@ -8155,8 +8161,7 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions,
                                mono_mb_emit_byte (mb, CEE_LDARG_0);
                                /* TODO support adding wrappers to non-static struct methods */
                                g_assert (!mono_class_is_valuetype(mono_method_get_class (method)));
-                               mono_mb_emit_byte (mb, CEE_LDC_I4_0);
-                               mono_mb_emit_icall (mb, mono_icall_handle_new_full);
+                               mono_mb_emit_icall (mb, mono_icall_handle_new);
                        }
                        for (i = 0; i < sig->param_count; i++) {
                                /* load each argument. references into the managed heap get wrapped in handles */
@@ -8166,27 +8171,24 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions,
                                        mono_mb_emit_ldarg (mb, j);
                                        break;
                                case ICALL_HANDLES_WRAP_OBJ:
-                                       /* argI = mono_handle_new_full (argI_raw, FALSE) */
+                                       /* argI = mono_handle_new (argI_raw) */
                                        mono_mb_emit_ldarg (mb, j);
-                                       mono_mb_emit_byte (mb, CEE_LDC_I4_0);
-                                       mono_mb_emit_icall (mb, mono_icall_handle_new_full);
+                                       mono_mb_emit_icall (mb, mono_icall_handle_new);
                                        break;
                                case ICALL_HANDLES_WRAP_OBJ_INOUT:
-                                       /* handleI = argI = mono_handle_new_full (NULL, FALSE) */
+                                       /* handleI = argI = mono_handle_new (NULL) */
                                        mono_mb_emit_byte (mb, CEE_LDNULL);
-                                       mono_mb_emit_byte (mb, CEE_LDC_I4_0);
-                                       mono_mb_emit_icall (mb, mono_icall_handle_new_full);
+                                       mono_mb_emit_icall (mb, mono_icall_handle_new);
                                        /* tmp = argI */
                                        mono_mb_emit_byte (mb, CEE_DUP);
                                        /* handleI = tmp */
                                        mono_mb_emit_stloc (mb, handles_locals[j].handle);
                                        break;
                                case ICALL_HANDLES_WRAP_VALUETYPE_REF:
-                                       /* (void) mono_handle_new_full (argI, TRUE); argI */
+                                       /* (void) mono_handle_new (argI); argI */
                                        mono_mb_emit_ldarg (mb, j);
                                        mono_mb_emit_byte (mb, CEE_DUP);
-                                       mono_mb_emit_byte (mb, CEE_LDC_I4_1);
-                                       mono_mb_emit_icall (mb, mono_icall_handle_new_full);
+                                       mono_mb_emit_icall (mb, mono_icall_handle_new_interior);
                                        mono_mb_emit_byte (mb, CEE_POP);
 #if 0
                                        fprintf (stderr, " Method %s.%s.%s has byref valuetype argument %d\n", method->klass->name_space, method->klass->name, method->name, i);
@@ -12362,11 +12364,21 @@ mono_icall_end (MonoThreadInfo *info, HandleStackMark *stackmark, MonoError *err
 }
 
 static MonoObjectHandle
-mono_icall_handle_new_full (gpointer rawobj, MonoBoolean interior)
+mono_icall_handle_new (gpointer rawobj)
+{
+#ifdef MONO_HANDLE_TRACK_OWNER
+       return mono_handle_new (rawobj, "<marshal args>");
+#else
+       return mono_handle_new (rawobj);
+#endif
+}
+
+static MonoObjectHandle
+mono_icall_handle_new_interior (gpointer rawobj)
 {
 #ifdef MONO_HANDLE_TRACK_OWNER
-       return mono_handle_new_full (rawobj, interior, "<marshal args>");
+       return mono_handle_new_interior (rawobj, "<marshal args>");
 #else
-       return mono_handle_new_full (rawobj, interior);
+       return mono_handle_new_interior (rawobj);
 #endif
 }