Merge pull request #2341 from ludovic-henry/fix-threadpool-max-worker
[mono.git] / mono / metadata / method-builder.c
index 0ed15e721aa12dcc9a4d4241a92bd082d4f65fd5..23f8d5990952d0a176d19cbb1e26e1a0f305114a 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "config.h"
 #include "loader.h"
+#include "mono/metadata/abi-details.h"
 #include "mono/metadata/method-builder.h"
 #include "mono/metadata/tabledefs.h"
 #include "mono/metadata/exception.h"
@@ -66,7 +67,7 @@ mono_mb_new_base (MonoClass *klass, MonoWrapperType type)
 
 #ifndef DISABLE_JIT
        mb->code_size = 40;
-       mb->code = g_malloc (mb->code_size);
+       mb->code = (unsigned char *)g_malloc (mb->code_size);
 #endif
        /* placeholder for the wrapper always at index 1 */
        mono_mb_add_data (mb, NULL);
@@ -154,7 +155,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
        {
                /* Realloc the method info into a mempool */
 
-               method = mono_image_alloc0 (image, sizeof (MonoMethodWrapper));
+               method = (MonoMethod *)mono_image_alloc0 (image, sizeof (MonoMethodWrapper));
                memcpy (method, mb->method, sizeof (MonoMethodWrapper));
                mw = (MonoMethodWrapper*) method;
 
@@ -167,11 +168,11 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
                mw->header = header = (MonoMethodHeader *) 
                        mono_image_alloc0 (image, MONO_SIZEOF_METHOD_HEADER + mb->locals * sizeof (MonoType *));
 
-               header->code = mono_image_alloc (image, mb->pos);
+               header->code = (const unsigned char *)mono_image_alloc (image, mb->pos);
                memcpy ((char*)header->code, mb->code, mb->pos);
 
                for (i = 0, l = mb->locals_list; l; l = l->next, i++) {
-                       header->locals [i] = (MonoType *)l->data;
+                       header->locals [i] = mono_metadata_type_dup (NULL, (MonoType*)l->data);
                }
 #endif
        }
@@ -196,15 +197,15 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
        method->skip_visibility = mb->skip_visibility;
 #endif
 
-       i = g_list_length (mw->method_data);
+       i = g_list_length ((GList *)mw->method_data);
        if (i) {
                GList *tmp;
                void **data;
-               l = g_list_reverse (mw->method_data);
-               if (method->dynamic)
-                       data = g_malloc (sizeof (gpointer) * (i + 1));
+               l = g_list_reverse ((GList *)mw->method_data);
+               if (method_is_dynamic (method))
+                       data = (void **)g_malloc (sizeof (gpointer) * (i + 1));
                else
-                       data = mono_image_alloc (image, sizeof (gpointer) * (i + 1));
+                       data = (void **)mono_image_alloc (image, sizeof (gpointer) * (i + 1));
                /* store the size in the first element */
                data [0] = GUINT_TO_POINTER (i);
                i = 1;
@@ -231,7 +232,7 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
 #endif
 
        if (mb->param_names) {
-               char **param_names = mono_image_alloc0 (image, signature->param_count * sizeof (gpointer));
+               char **param_names = (char **)mono_image_alloc0 (image, signature->param_count * sizeof (gpointer));
                for (i = 0; i < signature->param_count; ++i)
                        param_names [i] = mono_image_strdup (image, mb->param_names [i]);
 
@@ -256,9 +257,9 @@ mono_mb_add_data (MonoMethodBuilder *mb, gpointer data)
        mw = (MonoMethodWrapper *)mb->method;
 
        /* one O(n) is enough */
-       mw->method_data = g_list_prepend (mw->method_data, data);
+       mw->method_data = g_list_prepend ((GList *)mw->method_data, data);
 
-       return g_list_length (mw->method_data);
+       return g_list_length ((GList *)mw->method_data);
 }
 
 #ifndef DISABLE_JIT
@@ -298,7 +299,7 @@ mono_mb_emit_byte (MonoMethodBuilder *mb, guint8 op)
 {
        if (mb->pos >= mb->code_size) {
                mb->code_size += mb->code_size >> 1;
-               mb->code = g_realloc (mb->code, mb->code_size);
+               mb->code = (unsigned char *)g_realloc (mb->code, mb->code_size);
        }
 
        mb->code [mb->pos++] = op;
@@ -321,19 +322,32 @@ mono_mb_emit_i4 (MonoMethodBuilder *mb, gint32 data)
 {
        if ((mb->pos + 4) >= mb->code_size) {
                mb->code_size += mb->code_size >> 1;
-               mb->code = g_realloc (mb->code, mb->code_size);
+               mb->code = (unsigned char *)g_realloc (mb->code, mb->code_size);
        }
 
        mono_mb_patch_addr (mb, mb->pos, data);
        mb->pos += 4;
 }
 
+void
+mono_mb_emit_i8 (MonoMethodBuilder *mb, gint64 data)
+{
+       if ((mb->pos + 8) >= mb->code_size) {
+               mb->code_size += mb->code_size >> 1;
+               mb->code = (unsigned char *)g_realloc (mb->code, mb->code_size);
+       }
+
+       mono_mb_patch_addr (mb, mb->pos, data);
+       mono_mb_patch_addr (mb, mb->pos + 4, data >> 32);
+       mb->pos += 8;
+}
+
 void
 mono_mb_emit_i2 (MonoMethodBuilder *mb, gint16 data)
 {
        if ((mb->pos + 2) >= mb->code_size) {
                mb->code_size += mb->code_size >> 1;
-               mb->code = g_realloc (mb->code, mb->code_size);
+               mb->code = (unsigned char *)g_realloc (mb->code, mb->code_size);
        }
 
        mb->code [mb->pos] = data & 0xff;
@@ -439,6 +453,13 @@ mono_mb_emit_icon (MonoMethodBuilder *mb, gint32 value)
        }
 }
 
+void
+mono_mb_emit_icon8 (MonoMethodBuilder *mb, gint64 value)
+{
+       mono_mb_emit_byte (mb, CEE_LDC_I8);
+       mono_mb_emit_i8 (mb, value);
+}
+
 int
 mono_mb_get_label (MonoMethodBuilder *mb)
 {
@@ -536,7 +557,7 @@ mono_mb_emit_exception_full (MonoMethodBuilder *mb, const char *exc_nspace, cons
        mono_mb_emit_op (mb, CEE_NEWOBJ, ctor);
        if (msg != NULL) {
                mono_mb_emit_byte (mb, CEE_DUP);
-               mono_mb_emit_ldflda (mb, G_STRUCT_OFFSET (MonoException, message));
+               mono_mb_emit_ldflda (mb, MONO_STRUCT_OFFSET (MonoException, message));
                mono_mb_emit_ldstr (mb, (char*)msg);
                mono_mb_emit_byte (mb, CEE_STIND_REF);
        }