return TRUE;
}
+static MonoClass *
+mono_class_get_throw (MonoImage *image, guint32 type_token)
+{
+ MonoClass *class = mono_class_get (image, type_token);
+ MonoLoaderError *error;
+ MonoException *ex;
+
+ if (class != NULL){
+ if (class->exception_type) {
+ MonoException *exc = mono_class_get_exception_for_failure (class);
+ g_assert (exc);
+ mono_raise_exception (exc);
+ }
+ return class;
+ }
+ error = mono_loader_get_last_error ();
+ g_assert (error != NULL);
+
+ ex = mono_loader_error_prepare_exception (error);
+ mono_raise_exception (ex);
+ return NULL;
+}
+
static void
ves_icall_System_Double_AssertEndianity (double *value)
{
return mono_object_clone (this);
}
-#define MONO_OBJECT_ALIGNMENT_SHIFT 3
-
-/*
- * Return hashcode based on object address. This function will need to be
- * smarter in the presence of a moving garbage collector, which will cache
- * the address hash before relocating the object.
- *
- * Wang's address-based hash function:
- * http://www.concentric.net/~Ttwang/tech/addrhash.htm
- */
-static gint32
-ves_icall_System_Object_GetHashCode (MonoObject *this)
-{
- MONO_ARCH_SAVE_REGS;
-
- return (GPOINTER_TO_UINT (this) >> MONO_OBJECT_ALIGNMENT_SHIFT) * 2654435761u;
-}
-
static gint32
ves_icall_System_ValueType_InternalGetHashCode (MonoObject *this, MonoArray **fields)
{
ves_icall_Type_GetFields_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
MonoClass *startklass, *klass, *refklass;
MonoArray *res;
MonoObject *member;
domain = ((MonoObject *)type)->vtable->domain;
if (type->type->byref)
- return mono_array_new (domain, mono_defaults.method_info_class, 0);
+ return mono_array_new (domain, mono_defaults.field_info_class, 0);
klass = startklass = mono_class_from_mono_type (type->type);
refklass = mono_class_from_mono_type (reftype->type);
+ i = 0;
+ len = 2;
+ res = mono_array_new (domain, mono_defaults.field_info_class, len);
handle_parent:
iter = NULL;
while ((field = mono_class_get_fields (klass, &iter))) {
if (!match)
continue;
member = (MonoObject*)mono_field_get_object (domain, refklass, field);
- l = g_slist_prepend (l, member);
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, member);
+ ++i;
}
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
goto handle_parent;
- len = g_slist_length (l);
- res = mono_array_new (domain, mono_defaults.field_info_class, len);
- i = 0;
- tmp = l = g_slist_reverse (l);
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.field_info_class, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
+ }
return res;
}
ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
MonoClass *startklass, *klass, *refklass;
MonoArray *res;
MonoMethod *method;
method_slots = method_slots_default;
memset (method_slots, 0, sizeof (method_slots_default));
}
+ i = 0;
+ len = 1;
+ res = mono_array_new (domain, mono_defaults.method_info_class, len);
handle_parent:
mono_class_setup_vtable (klass);
iter = NULL;
member = (MonoObject*)mono_method_get_object (domain, method, refklass);
- l = g_slist_prepend (l, member);
- len++;
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, member);
+ ++i;
}
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
goto handle_parent;
g_free (mname);
- res = mono_array_new (domain, mono_defaults.method_info_class, len);
- i = 0;
-
- tmp = l = g_slist_reverse (l);
-
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
if (method_slots != method_slots_default)
g_free (method_slots);
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.method_info_class, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
+ }
return res;
}
ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
static MonoClass *System_Reflection_ConstructorInfo;
MonoClass *startklass, *klass, *refklass;
MonoArray *res;
klass = startklass = mono_class_from_mono_type (type->type);
refklass = mono_class_from_mono_type (reftype->type);
+ if (!System_Reflection_ConstructorInfo)
+ System_Reflection_ConstructorInfo = mono_class_from_name (
+ mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
+
+ i = 0;
+ len = 2;
+ res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
iter = NULL;
while ((method = mono_class_get_methods (klass, &iter))) {
match = 0;
if (!match)
continue;
member = (MonoObject*)mono_method_get_object (domain, method, refklass);
-
- l = g_slist_prepend (l, member);
+
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, member);
+ ++i;
+ }
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_ConstructorInfo, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
}
- len = g_slist_length (l);
- if (!System_Reflection_ConstructorInfo)
- System_Reflection_ConstructorInfo = mono_class_from_name (
- mono_defaults.corlib, "System.Reflection", "ConstructorInfo");
- res = mono_array_new (domain, System_Reflection_ConstructorInfo, len);
- i = 0;
- tmp = l = g_slist_reverse (l);
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
return res;
}
ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
static MonoClass *System_Reflection_PropertyInfo;
MonoClass *startklass, *klass;
MonoArray *res;
method_slots = method_slots_default;
memset (method_slots, 0, sizeof (method_slots_default));
}
+ i = 0;
+ len = 2;
+ res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
handle_parent:
mono_class_setup_vtable (klass);
iter = NULL;
method_slots [prop->set->slot >> 5] |= 1 << (prop->set->slot & 0x1f);
}
- l = g_slist_prepend (l, mono_property_get_object (domain, startklass, prop));
- len++;
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, mono_property_get_object (domain, startklass, prop));
+ ++i;
}
if ((!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent)))
goto handle_parent;
g_free (propname);
- res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
- i = 0;
-
- tmp = l = g_slist_reverse (l);
-
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
if (method_slots != method_slots_default)
g_free (method_slots);
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_PropertyInfo, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
+ }
return res;
}
ves_icall_Type_GetEvents_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
static MonoClass *System_Reflection_EventInfo;
MonoClass *startklass, *klass;
MonoArray *res;
return mono_array_new (domain, System_Reflection_EventInfo, 0);
klass = startklass = mono_class_from_mono_type (type->type);
+ i = 0;
+ len = 2;
+ res = mono_array_new (domain, System_Reflection_EventInfo, len);
handle_parent:
iter = NULL;
while ((event = mono_class_get_events (klass, &iter))) {
if (!match)
continue;
match = 0;
- l = g_slist_prepend (l, mono_event_get_object (domain, startklass, event));
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, mono_event_get_object (domain, startklass, event));
+ ++i;
}
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
goto handle_parent;
- len = g_slist_length (l);
- res = mono_array_new (domain, System_Reflection_EventInfo, len);
- i = 0;
-
- tmp = l = g_slist_reverse (l);
-
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, System_Reflection_EventInfo, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
+ }
return res;
}
ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
{
MonoDomain *domain;
- GSList *l = NULL, *tmp;
GList *tmpn;
MonoClass *startklass, *klass;
MonoArray *res;
return mono_array_new (domain, mono_defaults.monotype_class, 0);
klass = startklass = mono_class_from_mono_type (type->type);
+ i = 0;
+ len = 1;
+ res = mono_array_new (domain, mono_defaults.monotype_class, len);
for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
match = 0;
nested = tmpn->data;
if (!match)
continue;
member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
- l = g_slist_prepend (l, member);
+ if (i >= len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, len * 2);
+ mono_array_memcpy_refs (new_res, 0, res, 0, len);
+ len *= 2;
+ res = new_res;
+ }
+ mono_array_setref (res, i, member);
+ ++i;
+ }
+ if (i != len) {
+ MonoArray *new_res = mono_array_new (domain, mono_defaults.monotype_class, i);
+ mono_array_memcpy_refs (new_res, 0, res, 0, i);
+ res = new_res;
+ /*
+ * Better solution for the new GC.
+ * res->max_length = i;
+ */
}
- len = g_slist_length (l);
- res = mono_array_new (domain, mono_defaults.monotype_class, len);
- i = 0;
- tmp = l = g_slist_reverse (l);
- for (; tmp; tmp = tmp->next, ++i)
- mono_array_setref (res, i, tmp->data);
- g_slist_free (l);
return res;
}
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);
}
static MonoArray*
-mono_module_get_types (MonoDomain *domain, MonoImage *image,
- MonoBoolean exportedOnly)
+mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoBoolean exportedOnly)
{
MonoArray *res;
MonoClass *klass;
attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
- klass = mono_class_get (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
+ klass = mono_class_get_throw (image, (i + 1) | MONO_TOKEN_TYPE_DEF);
+ if (mono_loader_get_last_error ())
+ mono_loader_clear_error ();
mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg));
count++;
}
MonoImage *image = NULL;
MonoTableInfo *table = NULL;
MonoDomain *domain;
- int i;
+ GList *list = NULL;
+ int i, len;
MONO_ARCH_SAVE_REGS;
}
}
- if (mono_is_security_manager_active ()) {
- /* the ReflectionTypeLoadException must have all the types (Types property),
- * NULL replacing types which throws an exception. The LoaderException must
- * contains all exceptions for NULL items.
- */
+ /* the ReflectionTypeLoadException must have all the types (Types property),
+ * NULL replacing types which throws an exception. The LoaderException must
+ * contain all exceptions for NULL items.
+ */
- guint32 len = mono_array_length (res);
- GList *list = NULL;
-
- for (i = 0; i < len; i++) {
- MonoReflectionType *t = mono_array_get (res, gpointer, i);
- MonoClass *klass = mono_type_get_class (t->type);
- if ((klass != NULL) && klass->exception_type) {
- /* keep the class in the list */
- list = g_list_append (list, klass);
- /* and replace Type with NULL */
- mono_array_setref (res, i, NULL);
- }
+ len = mono_array_length (res);
+
+ for (i = 0; i < len; i++) {
+ MonoReflectionType *t = mono_array_get (res, gpointer, i);
+ MonoClass *klass = mono_type_get_class (t->type);
+ if ((klass != NULL) && klass->exception_type) {
+ /* keep the class in the list */
+ list = g_list_append (list, klass);
+ /* and replace Type with NULL */
+ mono_array_setref (res, i, NULL);
}
+ }
- if (list) {
- GList *tmp = NULL;
- MonoException *exc = NULL;
- int length = g_list_length (list);
+ if (list) {
+ GList *tmp = NULL;
+ MonoException *exc = NULL;
+ int length = g_list_length (list);
- MonoArray *exl = mono_array_new (domain, mono_defaults.exception_class, length);
- for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
- MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
- mono_array_setref (exl, i, exc);
- }
- g_list_free (list);
- list = NULL;
+ mono_loader_clear_error ();
- exc = mono_get_exception_reflection_type_load (res, exl);
- mono_raise_exception (exc);
+ MonoArray *exl = mono_array_new (domain, mono_defaults.exception_class, length);
+ for (i = 0, tmp = list; i < length; i++, tmp = tmp->next) {
+ MonoException *exc = mono_class_get_exception_for_failure (tmp->data);
+ mono_array_setref (exl, i, exc);
}
+ g_list_free (list);
+ list = NULL;
+
+ exc = mono_get_exception_reflection_type_load (res, exl);
+ mono_raise_exception (exc);
}
return res;
{"AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem},
{"AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal},
{"DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure},
+ {"FreeBSTR", ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR},
{"FreeCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem},
{"FreeHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal},
+ {"GetComSlotForMethodInfoInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetComSlotForMethodInfoInternal},
{"GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal},
{"GetFunctionPointerForDelegateInternal", mono_delegate_to_ftnptr},
{"GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error},
{"ReadInt64", ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64},
{"ReadIntPtr", ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr},
{"SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf},
+ {"StringToBSTR", ves_icall_System_Runtime_InteropServices_Marshal_StringToBSTR},
{"StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
{"StringToHGlobalAuto", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi},
{"StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni},