[runtime] Don't insta-fail when a faulty COM type is encountered. (#5616)
[mono.git] / mono / metadata / method-builder.c
index 81d16ce4b2d48aee49ea5ef811744e95cce8016b..ccff8c91a0c1573cf2f0d38174f62fb5ae5a252b 100644 (file)
@@ -67,7 +67,7 @@ mono_mb_new_base (MonoClass *klass, MonoWrapperType type)
        m->inline_info = 1;
        m->wrapper_type = type;
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        mb->code_size = 40;
        mb->code = (unsigned char *)g_malloc (mb->code_size);
        mb->init_locals = TRUE;
@@ -104,7 +104,7 @@ mono_mb_new (MonoClass *klass, const char *name, MonoWrapperType type)
 void
 mono_mb_free (MonoMethodBuilder *mb)
 {
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        GList *l;
 
        for (l = mb->locals_list; l; l = l->next) {
@@ -134,7 +134,7 @@ mono_mb_free (MonoMethodBuilder *mb)
 MonoMethod *
 mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, int max_stack)
 {
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        MonoMethodHeader *header;
 #endif
        MonoMethodWrapper *mw;
@@ -147,7 +147,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
 
        image = mb->method->klass->image;
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        if (mb->dynamic) {
                method = mb->method;
                mw = (MonoMethodWrapper*)method;
@@ -177,7 +177,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
                else
                        method->name = mono_image_strdup (image, mb->name);
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
                mw->header = header = (MonoMethodHeader *) 
                        mono_image_alloc0 (image, MONO_SIZEOF_METHOD_HEADER + mb->locals * sizeof (MonoType *));
 
@@ -190,7 +190,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
 #endif
        }
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        /* Free the locals list so mono_mb_free () doesn't free the types twice */
        g_list_free (mb->locals_list);
        mb->locals_list = NULL;
@@ -200,7 +200,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
        if (!signature->hasthis)
                method->flags |= METHOD_ATTRIBUTE_STATIC;
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        if (max_stack < 8)
                max_stack = 8;
 
@@ -236,7 +236,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
                mw->method_data = data;
        }
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
        /*{
                static int total_code = 0;
                static int total_alloc = 0;
@@ -284,7 +284,7 @@ mono_mb_add_data (MonoMethodBuilder *mb, gpointer data)
        return g_list_length ((GList *)mw->method_data);
 }
 
-#ifdef HAVE_ONLINE_VES
+#ifdef ENABLE_ILGEN
 
 /**
  * mono_mb_add_local:
@@ -653,6 +653,20 @@ mono_mb_emit_exception (MonoMethodBuilder *mb, const char *exc_name, const char
        mono_mb_emit_exception_full (mb, "System", exc_name, msg);
 }
 
+/**
+ * mono_mb_emit_exception_for_error:
+ */
+void
+mono_mb_emit_exception_for_error (MonoMethodBuilder *mb, MonoError *error)
+{
+       /*
+        * If at some point there is need to support other types of errors,
+        * the behaviour should conform with mono_error_prepare_exception().
+        */
+       g_assert (mono_error_get_error_code (error) == MONO_ERROR_GENERIC && "Unsupported error code.");
+       mono_mb_emit_exception_full (mb, "System", mono_error_get_exception_name (error), mono_error_get_message (error));
+}
+
 /**
  * mono_mb_emit_add_to_local:
  */