#include "mono/metadata/tokentype.h"
#include "mono/utils/checked-build.h"
#include "mono/utils/mono-digest.h"
+#include "mono/io-layer/io-layer.h"
static GENERATE_GET_CLASS_WITH_CACHE (marshal_as_attribute, System.Runtime.InteropServices, MarshalAsAttribute);
static GENERATE_GET_CLASS_WITH_CACHE (module_builder, System.Reflection.Emit, ModuleBuilder);
static gboolean ensure_runtime_vtable (MonoClass *klass, MonoError *error);
static void reflection_methodbuilder_from_dynamic_method (ReflectionMethodBuilder *rmb, MonoReflectionDynamicMethod *mb);
static gboolean reflection_setup_internal_class (MonoReflectionTypeBuilder *tb, MonoError *error);
+static gboolean reflection_create_generic_class (MonoReflectionTypeBuilder *tb, MonoError *error);
+
static gpointer register_assembly (MonoDomain *domain, MonoReflectionAssembly *res, MonoAssembly *assembly);
#endif
static gpointer
register_assembly (MonoDomain *domain, MonoReflectionAssembly *res, MonoAssembly *assembly)
{
- CACHE_OBJECT (MonoReflectionAssembly *, assembly, res, NULL);
+ return CACHE_OBJECT (MonoReflectionAssembly *, assembly, &res->object, NULL);
}
static gpointer
register_module (MonoDomain *domain, MonoReflectionModuleBuilder *res, MonoDynamicImage *module)
{
- CACHE_OBJECT (MonoReflectionModuleBuilder *, module, res, NULL);
+ return CACHE_OBJECT (MonoReflectionModuleBuilder *, module, &res->module.obj, NULL);
}
static gboolean
return NULL;
}
}
-
+ /* Need to resolve the generic_type in order for it to create its generic context. */
+ MonoType *gtd = mono_reflection_type_get_handle (gclass->generic_type, error);
+ if (!is_ok (error)) {
+ g_free (types);
+ return NULL;
+ }
+ MonoClass *gtd_klass = mono_class_from_mono_type (gtd);
+ if (is_sre_type_builder (mono_object_class (gclass->generic_type))) {
+ reflection_create_generic_class ((MonoReflectionTypeBuilder*)gclass->generic_type, error);
+ if (!is_ok (error)) {
+ g_free (types);
+ return NULL;
+ }
+ }
+ g_assert (count == 0 || mono_class_is_gtd (gtd_klass));
res = mono_reflection_bind_generic_parameters (gclass->generic_type, count, types, error);
g_free (types);
g_assert (res);
mono_error_init (error);
reflection_setup_internal_class (tb, error);
+ return_val_if_nok (error, FALSE);
klass = mono_class_from_mono_type (tb->type.type);
if (count == 0)
return TRUE;
+ if (mono_class_try_get_generic_container (klass) != NULL)
+ return TRUE; /* already setup */
+
MonoGenericContainer *generic_container = (MonoGenericContainer *)mono_image_alloc0 (klass->image, sizeof (MonoGenericContainer));
generic_container->owner.klass = klass;
if (!mono_class_get_generic_class (klass)->need_sync)
return TRUE;
- if (klass->method.count != gklass->method.count) {
- klass->method.count = gklass->method.count;
- klass->methods = (MonoMethod **)mono_image_alloc (klass->image, sizeof (MonoMethod*) * (klass->method.count + 1));
+ int mcount = mono_class_get_method_count (klass);
+ int gmcount = mono_class_get_method_count (gklass);
+ if (mcount != gmcount) {
+ mono_class_set_method_count (klass, gmcount);
+ klass->methods = (MonoMethod **)mono_image_alloc (klass->image, sizeof (MonoMethod*) * (gmcount + 1));
- for (i = 0; i < klass->method.count; i++) {
+ for (i = 0; i < gmcount; i++) {
klass->methods [i] = mono_class_inflate_generic_method_full_checked (
gklass->methods [i], klass, mono_class_get_context (klass), error);
mono_error_assert_ok (error);
klass->interfaces_inited = 1;
}
- if (klass->field.count != gklass->field.count) {
- klass->field.count = gklass->field.count;
- klass->fields = image_g_new0 (klass->image, MonoClassField, klass->field.count);
+ int fcount = mono_class_get_field_count (klass);
+ int gfcount = mono_class_get_field_count (gklass);
+ if (fcount != gfcount) {
+ mono_class_set_field_count (klass, gfcount);
+ klass->fields = image_g_new0 (klass->image, MonoClassField, gfcount);
- for (i = 0; i < klass->field.count; i++) {
+ for (i = 0; i < gfcount; i++) {
klass->fields [i] = gklass->fields [i];
klass->fields [i].parent = klass;
klass->fields [i].type = mono_class_inflate_generic_type_checked (gklass->fields [i].type, mono_class_get_context (klass), error);
if (tb) {
num = tb->ctors? mono_array_length (tb->ctors): 0;
num += tb->num_methods;
- klass->method.count = num;
+ mono_class_set_method_count (klass, num);
klass->methods = (MonoMethod **)mono_image_alloc (klass->image, sizeof (MonoMethod*) * num);
num = tb->ctors? mono_array_length (tb->ctors): 0;
for (i = 0; i < num; ++i) {
}
}
- if (mono_class_is_interface (klass)) {
+ if (mono_class_is_interface (klass) && !mono_class_is_ginst (klass)) {
int slot_num = 0;
- for (i = 0; i < klass->method.count; ++i) {
+ int mcount = mono_class_get_method_count (klass);
+ for (i = 0; i < mcount; ++i) {
MonoMethod *im = klass->methods [i];
if (!(im->flags & METHOD_ATTRIBUTE_STATIC))
im->slot = slot_num++;
MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *)mono_class_get_ref_info (klass);
MonoReflectionFieldBuilder *fb;
MonoClassField *field;
+ MonoFieldDefaultValue *def_values;
MonoImage *image = klass->image;
const char *p, *p2;
int i, instance_size, packing_size = 0;
instance_size = sizeof (MonoObject);
}
- klass->field.count = tb->num_fields;
- klass->field.first = 0;
+ int fcount = tb->num_fields;
+ mono_class_set_field_count (klass, fcount);
mono_error_init (error);
instance_size += tb->class_size;
}
- klass->fields = image_g_new0 (image, MonoClassField, klass->field.count);
- mono_class_alloc_ext (klass);
- klass->ext->field_def_values = image_g_new0 (image, MonoFieldDefaultValue, klass->field.count);
+ klass->fields = image_g_new0 (image, MonoClassField, fcount);
+ def_values = image_g_new0 (image, MonoFieldDefaultValue, fcount);
+ mono_class_set_field_def_values (klass, def_values);
/*
This is, guess what, a hack.
The issue is that the runtime doesn't know how to setup the fields of a typebuider and crash.
*/
klass->size_inited = 1;
- for (i = 0; i < klass->field.count; ++i) {
+ for (i = 0; i < fcount; ++i) {
MonoArray *rva_data;
fb = (MonoReflectionFieldBuilder *)mono_array_get (tb->fields, gpointer, i);
field = &klass->fields [i];
size_t size = mono_array_length (rva_data);
char *data = (char *)mono_image_alloc (klass->image, size);
memcpy (data, base, size);
- klass->ext->field_def_values [i].data = data;
+ def_values [i].data = data;
}
if (fb->offset != -1)
field->offset = fb->offset;
if (fb->def_value) {
MonoDynamicImage *assembly = (MonoDynamicImage*)klass->image;
field->type->attrs |= FIELD_ATTRIBUTE_HAS_DEFAULT;
- idx = mono_dynimage_encode_constant (assembly, fb->def_value, &klass->ext->field_def_values [i].def_type);
+ idx = mono_dynimage_encode_constant (assembly, fb->def_value, &def_values [i].def_type);
/* Copy the data from the blob since it might get realloc-ed */
p = assembly->blob.data + idx;
len = mono_metadata_decode_blob_size (p, &p2);
len += p2 - p;
- klass->ext->field_def_values [i].data = (const char *)mono_image_alloc (image, len);
- memcpy ((gpointer)klass->ext->field_def_values [i].data, p, len);
+ def_values [i].data = (const char *)mono_image_alloc (image, len);
+ memcpy ((gpointer)def_values [i].data, p, len);
}
}
MonoReflectionPropertyBuilder *pb;
MonoImage *image = klass->image;
MonoProperty *properties;
+ MonoClassPropertyInfo *info;
int i;
mono_error_init (error);
- if (!klass->ext)
- klass->ext = image_g_new0 (image, MonoClassExt, 1);
+ info = mono_class_get_property_info (klass);
+ if (!info) {
+ info = mono_class_alloc0 (klass, sizeof (MonoClassPropertyInfo));
+ mono_class_set_property_info (klass, info);
+ }
- klass->ext->property.count = tb->properties ? mono_array_length (tb->properties) : 0;
- klass->ext->property.first = 0;
+ info->count = tb->properties ? mono_array_length (tb->properties) : 0;
+ info->first = 0;
- properties = image_g_new0 (image, MonoProperty, klass->ext->property.count);
- klass->ext->properties = properties;
- for (i = 0; i < klass->ext->property.count; ++i) {
+ properties = image_g_new0 (image, MonoProperty, info->count);
+ info->properties = properties;
+ for (i = 0; i < info->count; ++i) {
pb = mono_array_get (tb->properties, MonoReflectionPropertyBuilder*, i);
properties [i].parent = klass;
properties [i].attrs = pb->attrs;
guint32 len, idx;
const char *p, *p2;
MonoDynamicImage *assembly = (MonoDynamicImage*)klass->image;
- if (!klass->ext->prop_def_values)
- klass->ext->prop_def_values = image_g_new0 (image, MonoFieldDefaultValue, klass->ext->property.count);
+ if (!info->def_values)
+ info->def_values = image_g_new0 (image, MonoFieldDefaultValue, info->count);
properties [i].attrs |= PROPERTY_ATTRIBUTE_HAS_DEFAULT;
- idx = mono_dynimage_encode_constant (assembly, pb->def_value, &klass->ext->prop_def_values [i].def_type);
+ idx = mono_dynimage_encode_constant (assembly, pb->def_value, &info->def_values [i].def_type);
/* Copy the data from the blob since it might get realloc-ed */
p = assembly->blob.data + idx;
len = mono_metadata_decode_blob_size (p, &p2);
len += p2 - p;
- klass->ext->prop_def_values [i].data = (const char *)mono_image_alloc (image, len);
- memcpy ((gpointer)klass->ext->prop_def_values [i].data, p, len);
+ info->def_values [i].data = (const char *)mono_image_alloc (image, len);
+ memcpy ((gpointer)info->def_values [i].data, p, len);
}
}
}
MonoReflectionEventBuilder *eb;
MonoImage *image = klass->image;
MonoEvent *events;
+ MonoClassEventInfo *info;
int i;
mono_error_init (error);
- if (!klass->ext)
- klass->ext = image_g_new0 (image, MonoClassExt, 1);
+ info = mono_class_alloc0 (klass, sizeof (MonoClassEventInfo));
+ mono_class_set_event_info (klass, info);
- klass->ext->event.count = tb->events ? mono_array_length (tb->events) : 0;
- klass->ext->event.first = 0;
+ info->count = tb->events ? mono_array_length (tb->events) : 0;
+ info->first = 0;
- events = image_g_new0 (image, MonoEvent, klass->ext->event.count);
- klass->ext->events = events;
- for (i = 0; i < klass->ext->event.count; ++i) {
+ events = image_g_new0 (image, MonoEvent, info->count);
+ info->events = events;
+ for (i = 0; i < info->count; ++i) {
eb = mono_array_get (tb->events, MonoReflectionEventBuilder*, i);
events [i].parent = klass;
events [i].attrs = eb->attrs;
goto failure;
if (tb->subtypes) {
+ GList *nested = NULL;
for (i = 0; i < mono_array_length (tb->subtypes); ++i) {
MonoReflectionTypeBuilder *subtb = mono_array_get (tb->subtypes, MonoReflectionTypeBuilder*, i);
- mono_class_alloc_ext (klass);
if (!subtb->type.type) {
reflection_setup_internal_class (subtb, &error);
MonoType *subtype = mono_reflection_type_get_handle ((MonoReflectionType*)subtb, &error);
if (!is_ok (&error)) goto failure;
- klass->ext->nested_classes = g_list_prepend_image (klass->image, klass->ext->nested_classes, mono_class_from_mono_type (subtype));
+ nested = g_list_prepend_image (klass->image, nested, mono_class_from_mono_type (subtype));
}
+ mono_class_set_nested_classes_property (klass, nested);
}
klass->nested_classes_inited = TRUE;