Fixed warning in MSVC: 'different types for formal and actual parameter'.
[mono.git] / mono / metadata / object.c
index 2c6ea2b68429083a131526041831ea1292f7593b..7434a69448beab806976b14cc789f8a6c3406e5a 100644 (file)
@@ -1311,6 +1311,7 @@ build_imt_slots (MonoClass *klass, MonoVTable *vt, MonoDomain *domain, gpointer*
                if (mono_class_has_variant_generic_params (iface))
                        has_variant_iface = TRUE;
 
+               mono_class_setup_methods (iface);
                vt_slot = interface_offset;
                for (method_slot_in_interface = 0; method_slot_in_interface < iface->method.count; method_slot_in_interface++) {
                        MonoMethod *method;
@@ -2969,7 +2970,7 @@ handle_enum:
                        MonoClass *class = mono_class_from_mono_type (type);
                        int size = mono_class_value_size (class, NULL);
                        if (value == NULL)
-                               mono_gc_bzero (dest, size);
+                               mono_gc_bzero_atomic (dest, size);
                        else
                                mono_gc_wbarrier_value_copy (dest, value, 1, class);
                }
@@ -3341,7 +3342,7 @@ mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *
 void
 mono_field_static_get_value (MonoVTable *vt, MonoClassField *field, void *value)
 {
-       return mono_field_static_get_value_for_thread (mono_thread_internal_current (), vt, field, value);
+       mono_field_static_get_value_for_thread (mono_thread_internal_current (), vt, field, value);
 }
 
 /**
@@ -3418,9 +3419,9 @@ mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass)
                if (param_class->has_references)
                        mono_gc_wbarrier_value_copy (buf + klass->fields [0].offset - sizeof (MonoObject), mono_object_unbox (value), 1, param_class);
                else
-                       mono_gc_memmove (buf + klass->fields [0].offset - sizeof (MonoObject), mono_object_unbox (value), mono_class_value_size (param_class, NULL));
+                       mono_gc_memmove_atomic (buf + klass->fields [0].offset - sizeof (MonoObject), mono_object_unbox (value), mono_class_value_size (param_class, NULL));
        } else {
-               mono_gc_bzero (buf + klass->fields [0].offset - sizeof (MonoObject), mono_class_value_size (param_class, NULL));
+               mono_gc_bzero_atomic (buf + klass->fields [0].offset - sizeof (MonoObject), mono_class_value_size (param_class, NULL));
        }
 }
 
@@ -3448,7 +3449,7 @@ mono_nullable_box (guint8 *buf, MonoClass *klass)
                if (param_class->has_references)
                        mono_gc_wbarrier_value_copy (mono_object_unbox (o), buf + klass->fields [0].offset - sizeof (MonoObject), 1, param_class);
                else
-                       mono_gc_memmove (mono_object_unbox (o), buf + klass->fields [0].offset - sizeof (MonoObject), mono_class_value_size (param_class, NULL));
+                       mono_gc_memmove_atomic (mono_object_unbox (o), buf + klass->fields [0].offset - sizeof (MonoObject), mono_class_value_size (param_class, NULL));
                return o;
        }
        else
@@ -3539,7 +3540,7 @@ mono_runtime_delegate_invoke (MonoObject *delegate, void **params, MonoObject **
 }
 
 static char **main_args = NULL;
-static int num_main_args;
+static int num_main_args = 0;
 
 /**
  * mono_runtime_get_main_args:
@@ -3553,9 +3554,6 @@ mono_runtime_get_main_args (void)
        int i;
        MonoDomain *domain = mono_domain_get ();
 
-       if (!main_args)
-               return NULL;
-
        res = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, num_main_args);
 
        for (i = 0; i < num_main_args; ++i)
@@ -3572,6 +3570,41 @@ free_main_args (void)
        for (i = 0; i < num_main_args; ++i)
                g_free (main_args [i]);
        g_free (main_args);
+       num_main_args = 0;
+       main_args = NULL;
+}
+
+/**
+ * mono_runtime_set_main_args:
+ * @argc: number of arguments from the command line
+ * @argv: array of strings from the command line
+ *
+ * Set the command line arguments from an embedding application that doesn't otherwise call
+ * mono_runtime_run_main ().
+ */
+int
+mono_runtime_set_main_args (int argc, char* argv[])
+{
+       int i;
+
+       free_main_args ();
+       main_args = g_new0 (char*, argc);
+       num_main_args = argc;
+
+       for (i = 0; i < argc; ++i) {
+               gchar *utf8_arg;
+
+               utf8_arg = mono_utf8_from_external (argv[i]);
+               if (utf8_arg == NULL) {
+                       g_print ("\nCannot determine the text encoding for argument %d (%s).\n", i, argv [i]);
+                       g_print ("Please add the correct encoding to MONO_EXTERNAL_ENCODINGS and try again.\n");
+                       exit (-1);
+               }
+
+               main_args [i] = utf8_arg;
+       }
+
+       return 0;
 }
 
 /**
@@ -4590,7 +4623,7 @@ mono_object_clone (MonoObject *obj)
        } else {
                int size = obj->vtable->klass->instance_size;
                /* do not copy the sync state */
-               mono_gc_memmove ((char*)o + sizeof (MonoObject), (char*)obj + sizeof (MonoObject), size - sizeof (MonoObject));
+               mono_gc_memmove_atomic ((char*)o + sizeof (MonoObject), (char*)obj + sizeof (MonoObject), size - sizeof (MonoObject));
        }
        if (G_UNLIKELY (profile_allocs))
                mono_profiler_allocation (o, obj->vtable->klass);
@@ -4625,12 +4658,12 @@ mono_array_full_copy (MonoArray *src, MonoArray *dest)
                if (klass->element_class->has_references)
                        mono_value_copy_array (dest, 0, mono_array_addr_with_size_fast (src, 0, 0), mono_array_length (src));
                else
-                       mono_gc_memmove (&dest->vector, &src->vector, size);
+                       mono_gc_memmove_atomic (&dest->vector, &src->vector, size);
        } else {
                mono_array_memcpy_refs (dest, 0, src, 0, mono_array_length (src));
        }
 #else
-       mono_gc_memmove (&dest->vector, &src->vector, size);
+       mono_gc_memmove_atomic (&dest->vector, &src->vector, size);
 #endif
 }
 
@@ -4662,12 +4695,12 @@ mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array)
                        if (klass->element_class->has_references)
                                mono_value_copy_array (o, 0, mono_array_addr_with_size_fast (array, 0, 0), mono_array_length (array));
                        else
-                               mono_gc_memmove (&o->vector, &array->vector, size);
+                               mono_gc_memmove_atomic (&o->vector, &array->vector, size);
                } else {
                        mono_array_memcpy_refs (o, 0, array, 0, mono_array_length (array));
                }
 #else
-               mono_gc_memmove (&o->vector, &array->vector, size);
+               mono_gc_memmove_atomic (&o->vector, &array->vector, size);
 #endif
                return o;
        }
@@ -4685,12 +4718,12 @@ mono_array_clone_in_domain (MonoDomain *domain, MonoArray *array)
                if (klass->element_class->has_references)
                        mono_value_copy_array (o, 0, mono_array_addr_with_size_fast (array, 0, 0), mono_array_length (array));
                else
-                       mono_gc_memmove (&o->vector, &array->vector, size);
+                       mono_gc_memmove_atomic (&o->vector, &array->vector, size);
        } else {
                mono_array_memcpy_refs (o, 0, array, 0, mono_array_length (array));
        }
 #else
-       mono_gc_memmove (&o->vector, &array->vector, size);
+       mono_gc_memmove_atomic (&o->vector, &array->vector, size);
 #endif
 
        return o;
@@ -4758,7 +4791,7 @@ mono_array_calc_byte_len (MonoClass *class, uintptr_t len, uintptr_t *res)
 MonoArray*
 mono_array_new_full (MonoDomain *domain, MonoClass *array_class, uintptr_t *lengths, intptr_t *lower_bounds)
 {
-       uintptr_t byte_len, len, bounds_size;
+       uintptr_t byte_len = 0, len, bounds_size;
        MonoObject *o;
        MonoArray *array;
        MonoArrayBounds *bounds;
@@ -4956,12 +4989,15 @@ mono_string_new_size (MonoDomain *domain, gint32 len)
 {
        MonoString *s;
        MonoVTable *vtable;
-       size_t size = (sizeof (MonoString) + ((len + 1) * 2));
+       size_t size;
 
-       /* overflow ? can't fit it, can't allocate it! */
-       if (len > size)
+       /* check for overflow */
+       if (len < 0 || len > ((SIZE_MAX - sizeof (MonoString) - 2) / 2))
                mono_gc_out_of_memory (-1);
 
+       size = (sizeof (MonoString) + ((len + 1) * 2));
+       g_assert (size > 0);
+
        vtable = mono_class_vtable (domain, mono_defaults.string_class);
        g_assert (vtable);
 
@@ -5107,7 +5143,7 @@ mono_value_box (MonoDomain *domain, MonoClass *class, gpointer value)
        mono_gc_wbarrier_value_copy ((char *)res + sizeof (MonoObject), value, 1, class);
 #else
 #if NO_UNALIGNED_ACCESS
-       mono_gc_memmove ((char *)res + sizeof (MonoObject), value, size);
+       mono_gc_memmove_atomic ((char *)res + sizeof (MonoObject), value, size);
 #else
        switch (size) {
        case 1:
@@ -5123,7 +5159,7 @@ mono_value_box (MonoDomain *domain, MonoClass *class, gpointer value)
                *(guint64 *)((guint8 *) res + sizeof (MonoObject)) = *(guint64 *) value;
                break;
        default:
-               mono_gc_memmove ((char *)res + sizeof (MonoObject), value, size);
+               mono_gc_memmove_atomic ((char *)res + sizeof (MonoObject), value, size);
        }
 #endif
 #endif
@@ -6290,10 +6326,10 @@ mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoAr
                                        if (class->has_references)
                                                mono_gc_wbarrier_value_copy (*((gpointer *)params [i]), arg + sizeof (MonoObject), 1, class);
                                        else
-                                               mono_gc_memmove (*((gpointer *)params [i]), arg + sizeof (MonoObject), size);
+                                               mono_gc_memmove_atomic (*((gpointer *)params [i]), arg + sizeof (MonoObject), size);
                                } else {
                                        size = mono_class_value_size (mono_class_from_mono_type (pt), NULL);
-                                       mono_gc_bzero (*((gpointer *)params [i]), size);
+                                       mono_gc_bzero_atomic (*((gpointer *)params [i]), size);
                                }
                        }