Hide some more methods
[mono.git] / mono / metadata / icall.c
index 40a7dbd61e0f23648d351826e140815c2a93eb58..41b3ee3f809a72dc95fffb3679a063b0a74d96d7 100644 (file)
@@ -1474,9 +1474,9 @@ ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *ob
 
                /* Convert the Nullable structure into a boxed vtype */
                if (is_static)
-                       buf = (char*)vtable->data + cf->offset;
+                       buf = (guint8*)vtable->data + cf->offset;
                else
-                       buf = (char*)obj + cf->offset;
+                       buf = (guint8*)obj + cf->offset;
 
                return mono_nullable_box (buf, nklass);
        }
@@ -1552,7 +1552,7 @@ ves_icall_FieldInfo_SetValueInternal (MonoReflectionField *field, MonoObject *ob
 
                                mono_nullable_init (buf, value, nklass);
 
-                               v = buf;
+                               v = (gchar*)buf;
                        }
                        else 
                                if (gclass->container_class->valuetype && (v != NULL))
@@ -2823,7 +2823,7 @@ write_enum_value (char *mem, int type, guint64 value)
        switch (type) {
        case MONO_TYPE_U1:
        case MONO_TYPE_I1: {
-               guint8 *p = mem;
+               guint8 *p = (guint8*)mem;
                *p = value;
                break;
        }
@@ -2868,9 +2868,10 @@ ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
        enumc = mono_class_from_mono_type (type->type);
        objc = obj->vtable->klass;
 
-       MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
-       MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
-                                                 objc->byval_arg.type <= MONO_TYPE_U8));
+       if (!enumc->enumtype)
+               mono_raise_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
+       if (!((objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 && objc->byval_arg.type <= MONO_TYPE_U8)))
+               mono_raise_exception (mono_get_exception_argument ("value", "The value passed in must be an enum base or an underlying type for an enum, such as an Int32."));
 
        res = mono_object_new (domain, enumc);
        val = read_enum_value ((char *)obj + sizeof (MonoObject), objc->enumtype? objc->enum_basetype->type: objc->byval_arg.type);
@@ -3125,7 +3126,7 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
        MonoMethod *method;
        gpointer iter;
        MonoObject *member;
-       int i, len, match;
+       int i, len, match, nslots;
        guint32 method_slots_default [8];
        guint32 *method_slots;
        gchar *mname = NULL;
@@ -3146,8 +3147,9 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
 
        mono_class_setup_vtable (klass);
 
-       if (klass->vtable_size >= sizeof (method_slots_default) * 8) {
-               method_slots = g_new0 (guint32, klass->vtable_size / 32 + 1);
+       nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
+       if (nslots >= sizeof (method_slots_default) * 8) {
+               method_slots = g_new0 (guint32, nslots / 32 + 1);
        } else {
                method_slots = method_slots_default;
                memset (method_slots, 0, sizeof (method_slots_default));
@@ -3188,6 +3190,7 @@ handle_parent:
                
                match = 0;
                if (method->slot != -1) {
+                       g_assert (method->slot < nslots);
                        if (method_slots [method->slot >> 5] & (1 << (method->slot & 0x1f)))
                                continue;
                        method_slots [method->slot >> 5] |= 1 << (method->slot & 0x1f);
@@ -3289,7 +3292,7 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
        MonoArray *res;
        MonoMethod *method;
        MonoProperty *prop;
-       int i, match;
+       int i, match, nslots;
        int len = 0;
        guint32 flags;
        guint32 method_slots_default [8];
@@ -3313,8 +3316,11 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
                compare_func = (ignore_case) ? g_strcasecmp : strcmp;
        }
 
-       if (klass->vtable_size >= sizeof (method_slots_default) * 8) {
-               method_slots = g_new0 (guint32, klass->vtable_size / 32 + 1);
+       mono_class_setup_vtable (klass);
+
+       nslots = MONO_CLASS_IS_INTERFACE (klass) ? mono_class_num_methods (klass) : klass->vtable_size;
+       if (nslots >= sizeof (method_slots_default) * 8) {
+               method_slots = g_new0 (guint32, nslots / 32 + 1);
        } else {
                method_slots = method_slots_default;
                memset (method_slots, 0, sizeof (method_slots_default));
@@ -3704,6 +3710,14 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
        MONO_ARCH_SAVE_REGS;
 
        absolute = g_build_filename (mass->basedir, mass->image->module_name, NULL);
+#if PLATFORM_WIN32
+       {
+               gint i;
+               for (i = strlen (absolute) - 1; i >= 0; i--)
+                       if (absolute [i] == '\\')
+                               absolute [i] = '/';
+       }
+#endif
        if (escaped) {
                uri = g_filename_to_uri (absolute, NULL, NULL);
        } else {
@@ -4373,7 +4387,7 @@ ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname,
        filename = mono_string_to_utf8 (fname);
 
        image = mono_image_open (filename, &status);
-       
+
        if (!image){
                MonoException *exc;
 
@@ -4382,6 +4396,8 @@ ves_icall_System_Reflection_Assembly_InternalGetAssemblyName (MonoString *fname,
                mono_raise_exception (exc);
        }
 
+       /* So we can call mono_image_close () later */
+       mono_image_addref (image);
        res = mono_assembly_fill_assembly_name (image, &name);
        if (!res) {
                mono_image_close (image);
@@ -5529,6 +5545,36 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
        return names;
 }
 
+/*
+ * If your platform lacks setenv/unsetenv, you must upgrade your glib.
+ */
+#if !GLIB_CHECK_VERSION(2,4,0)
+#define g_setenv(a,b,c)   setenv(a,b,c)
+#define g_unsetenv(a) unsetenv(a)
+#endif
+
+static void
+ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
+{
+       gchar *utf8_name, *utf8_value;
+
+       MONO_ARCH_SAVE_REGS;
+
+       utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
+
+       if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
+               g_unsetenv (utf8_name);
+               return;
+       }
+
+       utf8_value = mono_string_to_utf8 (value);
+
+       g_setenv (utf8_name, utf8_value, TRUE);
+
+       g_free (utf8_name);
+       g_free (utf8_value);
+}
+
 /*
  * Returns: the number of milliseconds elapsed since the system started.
  */
@@ -6463,6 +6509,7 @@ static const IcallEntry environment_icalls [] = {
        {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
        {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
        {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
+       {"InternalSetEnvironmentVariable", ves_icall_System_Environment_InternalSetEnvironmentVariable},
        {"get_ExitCode", mono_environment_exitcode_get},
        {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},
        {"get_MachineName", ves_icall_System_Environment_get_MachineName},
@@ -6543,7 +6590,7 @@ static const IcallEntry monoio_icalls [] = {
        {"GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath},
        {"Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock},
        {"MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile},
-       {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
+       {"Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.FileOptions,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open},
        {"Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read},
        {"RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory},
        {"Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek},