* Paolo Molaro (lupus@ximian.com)
* Patrik Torstensson (patrik.torstensson@labs2.com)
* Marek Safar (marek.safar@gmail.com)
+ * Aleksey Kliger (aleksey@xamarin.com)
*
* Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
* Copyright 2004-2009 Novell, Inc (http://www.novell.com)
- * Copyright 2011-2014 Xamarin Inc (http://www.xamarin.com).
+ * Copyright 2011-2015 Xamarin Inc (http://www.xamarin.com).
*/
#include <config.h>
if (ac->element_class->valuetype)
return mono_value_box (arr->obj.vtable->domain, ac->element_class, ea);
else
- return *ea;
+ return (MonoObject *)*ea;
}
ICALL_EXPORT MonoObject *
aklass = mono_bounded_array_class_get (klass, mono_array_length (lengths), bounded);
- sizes = alloca (aklass->rank * sizeof(intptr_t) * 2);
+ sizes = (uintptr_t *)alloca (aklass->rank * sizeof(intptr_t) * 2);
for (i = 0; i < aklass->rank; ++i) {
sizes [i] = mono_array_get (lengths, guint32, i);
if (bounds)
aklass = mono_bounded_array_class_get (klass, mono_array_length (lengths), bounded);
- sizes = alloca (aklass->rank * sizeof(intptr_t) * 2);
+ sizes = (uintptr_t *)alloca (aklass->rank * sizeof(intptr_t) * 2);
for (i = 0; i < aklass->rank; ++i) {
sizes [i] = mono_array_get (lengths, guint64, i);
if (bounds)
if (MONO_TYPE_IS_REFERENCE (&ec->byval_arg)) {
g_assert (esize == sizeof (gpointer));
- mono_gc_wbarrier_generic_store (ea, *(gpointer*)value);
+ mono_gc_wbarrier_generic_store (ea, *(MonoObject **)value);
} else {
g_assert (ec->inited);
g_assert (esize == mono_class_value_size (ec, NULL));
ICALL_EXPORT MonoObject*
ves_icall_ModuleBuilder_GetRegisteredToken (MonoReflectionModuleBuilder *mb, guint32 token)
{
- gpointer obj;
+ MonoObject *obj;
mono_loader_lock ();
- obj = mono_g_hash_table_lookup (mb->dynamic_image->tokens, GUINT_TO_POINTER (token));
+ obj = (MonoObject *)mono_g_hash_table_lookup (mb->dynamic_image->tokens, GUINT_TO_POINTER (token));
mono_loader_unlock ();
return obj;
static gboolean
get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
{
- MonoMethod **dest = data;
+ MonoMethod **dest = (MonoMethod **)data;
/* skip unmanaged frames */
if (!managed)
static gboolean
get_executing (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
{
- MonoMethod **dest = data;
+ MonoMethod **dest = (MonoMethod **)data;
/* skip unmanaged frames */
if (!managed)
static gboolean
get_caller_no_reflection (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
{
- MonoMethod **dest = data;
+ MonoMethod **dest = (MonoMethod **)data;
/* skip unmanaged frames */
if (!managed)
*/
nullable = mono_object_new (mono_domain_get (), nklass);
- mono_nullable_init (mono_object_unbox (nullable), value, nklass);
+ mono_nullable_init ((guint8 *)mono_object_unbox (nullable), value, nklass);
- v = mono_object_unbox (nullable);
+ v = (gchar *)mono_object_unbox (nullable);
}
else
if (gclass->container_class->valuetype && (v != NULL))
static void
fill_iface_array (gpointer key, gpointer value, gpointer user_data)
{
- FillIfaceArrayData *data = user_data;
- MonoClass *ic = key;
+ FillIfaceArrayData *data = (FillIfaceArrayData *)user_data;
+ MonoClass *ic = (MonoClass *)key;
MonoType *ret = &ic->byval_arg, *inflated = NULL;
if (!mono_error_ok (data->error))
tb = mono_class_get_ref_info (generic_class);
if (generic_class->wastypebuilder && tb)
- return tb;
+ return (MonoReflectionType *)tb;
else
return mono_type_get_object (mono_object_domain (type), &generic_class->byval_arg);
}
types = g_new0 (MonoType *, count);
for (i = 0; i < count; i++) {
- MonoReflectionType *t = mono_array_get (type_array, gpointer, i);
+ MonoReflectionType *t = (MonoReflectionType *)mono_array_get (type_array, gpointer, i);
types [i] = t->type;
}
{
g_assert (IS_MONOTYPE (type));
g_assert (is_generic_parameter (type->type));
- return mono_generic_param_info (type->type->data.generic_param)->flags;
+ return (GenericParameterAttributes)mono_generic_param_info (type->type->data.generic_param)->flags;
}
ICALL_EXPORT MonoArray *
if (image_is_dynamic (image)) {
MonoReflectionMethodAux *method_aux =
- g_hash_table_lookup (((MonoDynamicImage*)image)->method_aux_hash, method->method);
+ (MonoReflectionMethodAux *)g_hash_table_lookup (((MonoDynamicImage*)image)->method_aux_hash, method->method);
if (method_aux) {
import = method_aux->dllentry;
scope = method_aux->dll;
* the dynamic case as well ?
*/
mono_image_lock ((MonoImage*)image);
- res = mono_g_hash_table_lookup (image->generic_def_objects, imethod);
+ res = (MonoReflectionMethod *)mono_g_hash_table_lookup (image->generic_def_objects, imethod);
mono_image_unlock ((MonoImage*)image);
if (res)
uintptr_t *lengths;
intptr_t *lower_bounds;
pcount = mono_array_length (params);
- lengths = alloca (sizeof (uintptr_t) * pcount);
+ lengths = (uintptr_t *)alloca (sizeof (uintptr_t) * pcount);
/* Note: the synthetized array .ctors have int32 as argument type */
for (i = 0; i < pcount; ++i)
lengths [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
} else {
g_assert (pcount == (m->klass->rank * 2));
/* The arguments are lower-bound-length pairs */
- lower_bounds = g_alloca (sizeof (intptr_t) * pcount);
+ lower_bounds = (intptr_t *)g_alloca (sizeof (intptr_t) * pcount);
for (i = 0; i < pcount / 2; ++i) {
lower_bounds [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, (i * 2)) + sizeof (MonoObject));
if (field_klass->valuetype)
result = mono_value_box (domain, field_klass, (char *)this_arg + field->offset);
else
- result = *((gpointer *)((char *)this_arg + field->offset));
+ result = (MonoObject *)*((gpointer *)((char *)this_arg + field->offset));
out_args = mono_array_new (domain, mono_defaults.object_class, 1);
mono_gc_wbarrier_generic_store (outArgs, (MonoObject*) out_args);
MonoClassField* field = mono_class_get_field_from_name (k, str);
if (field) {
MonoClass *field_klass = mono_class_from_mono_type (field->type);
- MonoObject *val = mono_array_get (params, gpointer, 2);
+ MonoObject *val = (MonoObject *)mono_array_get (params, gpointer, 2);
if (field_klass->valuetype) {
size = mono_type_size (field->type, &align);
}
case MONO_TYPE_U2:
case MONO_TYPE_I2: {
- guint16 *p = (void*)mem;
+ guint16 *p = (guint16 *)mem;
*p = value;
break;
}
case MONO_TYPE_U4:
case MONO_TYPE_I4: {
- guint32 *p = (void*)mem;
+ guint32 *p = (guint32 *)mem;
*p = value;
break;
}
case MONO_TYPE_U8:
case MONO_TYPE_I8: {
- guint64 *p = (void*)mem;
+ guint64 *p = (guint64 *)mem;
*p = value;
break;
}
res = mono_array_new_specific (array_vtable, method_array->len);
for (i = 0; i < method_array->len; ++i) {
- MonoMethod *method = g_ptr_array_index (method_array, i);
+ MonoMethod *method = (MonoMethod *)g_ptr_array_index (method_array, i);
mono_array_setref (res, i, mono_method_get_object (domain, method, refklass));
}
ex_count = 0;
for (i = 0; i < len; i++) {
- MonoReflectionType *t = mono_array_get (res, gpointer, i);
+ MonoReflectionType *t = (MonoReflectionType *)mono_array_get (res, gpointer, i);
MonoClass *klass;
if (t) {
exl = mono_array_new (domain, mono_defaults.exception_class, length);
/* Types for which mono_class_get_checked () succeeded */
for (i = 0, tmp = list; tmp; i++, tmp = tmp->next) {
- MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
+ MonoException *exc = mono_class_get_exception_for_failure ((MonoClass *)tmp->data);
mono_array_setref (exl, i, exc);
}
/* Types for which it don't */
if (image_is_dynamic (image)) {
if ((table == MONO_TABLE_TYPEDEF) || (table == MONO_TABLE_TYPEREF)) {
- klass = mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
+ klass = (MonoClass *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
return klass ? &klass->byval_arg : NULL;
}
init_generic_context_from_args (&context, type_args, method_args);
- klass = mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
+ klass = (MonoClass *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
return klass ? &klass->byval_arg : NULL;
}
if (image_is_dynamic (image)) {
if (table == MONO_TABLE_METHOD)
- return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
+ return (MonoMethod *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
if ((table == MONO_TABLE_MEMBERREF) && !(mono_memberref_is_method (image, token))) {
*resolve_error = ResolveTokenError_BadTable;
}
init_generic_context_from_args (&context, type_args, method_args);
- return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
+ return (MonoMethod *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
}
if ((index <= 0) || (index > image->tables [table].rows)) {
}
if (image_is_dynamic (image))
- return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
+ return (MonoString *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
if ((index <= 0) || (index >= image->heap_us.size)) {
*error = ResolveTokenError_OutOfRange;
if (image_is_dynamic (image)) {
if (table == MONO_TABLE_FIELD)
- return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
+ return (MonoClassField *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
if (mono_memberref_is_method (image, token)) {
*resolve_error = ResolveTokenError_BadTable;
}
init_generic_context_from_args (&context, type_args, method_args);
- return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
+ return (MonoClassField *)mono_lookup_dynamic_token_class (image, token, FALSE, NULL, &context);
}
if ((index <= 0) || (index > image->tables [table].rows)) {
type = ((MonoReflectionType *)rp->class_to_proxy)->type;
klass = mono_class_from_mono_type (type);
+ // mono_remote_class_vtable cannot handle errors well, so force any loading error to occur early
+ mono_class_setup_vtable (klass);
+ if (klass->exception_type)
+ mono_raise_exception (mono_class_get_exception_for_failure (klass));
+
tp->custom_type_info = (mono_object_isinst (this_obj, mono_defaults.iremotingtypeinfo_class) != NULL);
tp->remote_class = mono_remote_class (domain, class_name, klass);
- res->vtable = mono_remote_class_vtable (domain, tp->remote_class, rp);
+ res->vtable = (MonoVTable *)mono_remote_class_vtable (domain, tp->remote_class, rp);
return res;
}
if (size > initial_size) {
if (ptr != buf)
g_free (ptr);
- ptr = g_malloc0 ((size + 1) * sizeof (gunichar2));
+ ptr = (gunichar2 *)g_malloc0 ((size + 1) * sizeof (gunichar2));
initial_size = size;
size++;
}
return NULL;
len = config_file_path_length - config_ext_length;
- module = g_malloc0 (len + 1);
+ module = (gchar *)g_malloc0 (len + 1);
memcpy (module, config_file_path, len);
// Get the config file from the module name
app_config = mono_config_string_for_assembly_file (module);
*result = NULL;
*size = 0;
image = assembly->assembly->image;
- entry = mono_image_lookup_resource (image, MONO_PE_RESOURCE_ID_ASPNET_STRING, 0, NULL);
+ entry = (MonoPEResourceDataEntry *)mono_image_lookup_resource (image, MONO_PE_RESOURCE_ID_ASPNET_STRING, 0, NULL);
if (!entry)
return FALSE;
ves_icall_MonoMethod_get_base_method (MonoReflectionMethod *m, gboolean definition)
{
MonoClass *klass, *parent;
+ MonoGenericContext *generic_inst = NULL;
MonoMethod *method = m->method;
MonoMethod *result = NULL;
int slot;
return m;
klass = method->klass;
- if (klass->generic_class)
+ if (klass->generic_class) {
+ generic_inst = mono_class_get_context (klass);
klass = klass->generic_class->container_class;
+ }
if (definition) {
/* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
for (parent = klass->parent; parent != NULL; parent = parent->parent) {
+ /* on entry, klass is either a plain old non-generic class and generic_inst == NULL
+ or klass is the generic container class and generic_inst is the instantiation.
+
+ when we go to the parent, if the parent is an open constructed type, we need to
+ replace the type parameters by the definitions from the generic_inst, and then take it
+ apart again into the klass and the generic_inst.
+
+ For cases like this:
+ class C<T> : B<T, int> {
+ public override void Foo () { ... }
+ }
+ class B<U,V> : A<HashMap<U,V>> {
+ public override void Foo () { ... }
+ }
+ class A<X> {
+ public virtual void Foo () { ... }
+ }
+
+ if at each iteration the parent isn't open, we can skip inflating it. if at some
+ iteration the parent isn't generic (after possible inflation), we set generic_inst to
+ NULL;
+ */
+ MonoGenericContext *parent_inst = NULL;
+ if (mono_class_is_open_constructed_type (mono_class_get_type (parent))) {
+ MonoError error;
+ parent = mono_class_inflate_generic_class_checked (parent, generic_inst, &error);
+ mono_error_raise_exception(&error);
+ }
+ if (parent->generic_class) {
+ parent_inst = mono_class_get_context (parent);
+ parent = parent->generic_class->container_class;
+ }
+
mono_class_setup_vtable (parent);
if (parent->vtable_size <= slot)
break;
klass = parent;
+ generic_inst = parent_inst;
}
} else {
klass = klass->parent;
if (!klass)
return m;
+ if (mono_class_is_open_constructed_type (mono_class_get_type (klass))) {
+ MonoError error;
+ klass = mono_class_inflate_generic_class_checked (klass, generic_inst, &error);
+ mono_error_raise_exception(&error);
+
+ generic_inst = NULL;
+ }
+ if (klass->generic_class) {
+ generic_inst = mono_class_get_context (klass);
+ klass = klass->generic_class->container_class;
+ }
+
+ }
+
+ if (generic_inst) {
+ MonoError error;
+ klass = mono_class_inflate_generic_class_checked (klass, generic_inst, &error);
+ mono_error_raise_exception(&error);
}
if (klass == method->klass)
mono_TypedReference_ToObject (MonoTypedRef* tref)
{
if (MONO_TYPE_IS_REFERENCE (tref->type)) {
- MonoObject** objp = tref->value;
+ MonoObject** objp = (MonoObject **)tref->value;
return *objp;
}
static gpointer
find_method_icall (const IcallTypeDesc *imap, const char *name)
{
- const guint16 *nameslot = mono_binary_search (name, icall_names_idx + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names_idx [0]), compare_method_imap);
+ const guint16 *nameslot = (const guint16 *)mono_binary_search (name, icall_names_idx + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names_idx [0]), compare_method_imap);
if (!nameslot)
return NULL;
return (gpointer)icall_functions [(nameslot - &icall_names_idx [0])];
static const IcallTypeDesc*
find_class_icalls (const char *name)
{
- const guint16 *nameslot = mono_binary_search (name, icall_type_names_idx, Icall_type_num, sizeof (icall_type_names_idx [0]), compare_class_imap);
+ const guint16 *nameslot = (const guint16 *)mono_binary_search (name, icall_type_names_idx, Icall_type_num, sizeof (icall_type_names_idx [0]), compare_class_imap);
if (!nameslot)
return NULL;
return &icall_type_descs [nameslot - &icall_type_names_idx [0]];
}
static MonoType*
-type_from_typename (char *typename)
+type_from_typename (char *type_name)
{
MonoClass *klass = NULL; /* assignment to shut GCC warning up */
- if (!strcmp (typename, "int"))
+ if (!strcmp (type_name, "int"))
klass = mono_defaults.int_class;
- else if (!strcmp (typename, "ptr"))
+ else if (!strcmp (type_name, "ptr"))
klass = mono_defaults.int_class;
- else if (!strcmp (typename, "void"))
+ else if (!strcmp (type_name, "void"))
klass = mono_defaults.void_class;
- else if (!strcmp (typename, "int32"))
+ else if (!strcmp (type_name, "int32"))
klass = mono_defaults.int32_class;
- else if (!strcmp (typename, "uint32"))
+ else if (!strcmp (type_name, "uint32"))
klass = mono_defaults.uint32_class;
- else if (!strcmp (typename, "int8"))
+ else if (!strcmp (type_name, "int8"))
klass = mono_defaults.sbyte_class;
- else if (!strcmp (typename, "uint8"))
+ else if (!strcmp (type_name, "uint8"))
klass = mono_defaults.byte_class;
- else if (!strcmp (typename, "int16"))
+ else if (!strcmp (type_name, "int16"))
klass = mono_defaults.int16_class;
- else if (!strcmp (typename, "uint16"))
+ else if (!strcmp (type_name, "uint16"))
klass = mono_defaults.uint16_class;
- else if (!strcmp (typename, "long"))
+ else if (!strcmp (type_name, "long"))
klass = mono_defaults.int64_class;
- else if (!strcmp (typename, "ulong"))
+ else if (!strcmp (type_name, "ulong"))
klass = mono_defaults.uint64_class;
- else if (!strcmp (typename, "float"))
+ else if (!strcmp (type_name, "float"))
klass = mono_defaults.single_class;
- else if (!strcmp (typename, "double"))
+ else if (!strcmp (type_name, "double"))
klass = mono_defaults.double_class;
- else if (!strcmp (typename, "object"))
+ else if (!strcmp (type_name, "object"))
klass = mono_defaults.object_class;
- else if (!strcmp (typename, "obj"))
+ else if (!strcmp (type_name, "obj"))
klass = mono_defaults.object_class;
- else if (!strcmp (typename, "string"))
+ else if (!strcmp (type_name, "string"))
klass = mono_defaults.string_class;
- else if (!strcmp (typename, "bool"))
+ else if (!strcmp (type_name, "bool"))
klass = mono_defaults.boolean_class;
- else if (!strcmp (typename, "boolean"))
+ else if (!strcmp (type_name, "boolean"))
klass = mono_defaults.boolean_class;
else {
- g_error ("%s", typename);
+ g_error ("%s", type_name);
g_assert_not_reached ();
}
return &klass->byval_arg;
MonoImage *corlib = mono_defaults.corlib;
mono_image_lock (corlib);
- res = g_hash_table_lookup (corlib->helper_signatures, sigstr);
+ res = (MonoMethodSignature *)g_hash_table_lookup (corlib->helper_signatures, sigstr);
mono_image_unlock (corlib);
if (res)
g_strfreev (parts);
mono_image_lock (corlib);
- res2 = g_hash_table_lookup (corlib->helper_signatures, sigstr);
+ res2 = (MonoMethodSignature *)g_hash_table_lookup (corlib->helper_signatures, sigstr);
if (res2)
res = res2; /*Value is allocated in the image pool*/
else
g_assert (jit_icall_hash_name);
mono_icall_lock ();
- info = g_hash_table_lookup (jit_icall_hash_name, name);
+ info = (MonoJitICallInfo *)g_hash_table_lookup (jit_icall_hash_name, name);
mono_icall_unlock ();
return info;
}
g_assert (jit_icall_hash_addr);
mono_icall_lock ();
- info = g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
+ info = (MonoJitICallInfo *)g_hash_table_lookup (jit_icall_hash_addr, (gpointer)addr);
mono_icall_unlock ();
return info;
const char *res = NULL;
mono_icall_lock ();
- info = g_hash_table_lookup (jit_icall_hash_name, name);
+ info = (MonoJitICallInfo *)g_hash_table_lookup (jit_icall_hash_name, name);
if (info)
res = info->c_symbol;
mono_icall_unlock ();