{
MonoImage *m = class->image;
const int top = class->field.count;
- MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
int i;
g_assert (class->enumtype);
MonoGenericContainer *container = NULL;
MonoType *ftype;
- mono_metadata_decode_row (t, idx, cols, MONO_FIELD_SIZE);
+ /* class->field.first and idx points into the fieldptr table */
+ mono_metadata_decode_table_row (m, MONO_TABLE_FIELD, idx, cols, MONO_FIELD_SIZE);
sig = mono_metadata_blob_heap (m, cols [MONO_FIELD_SIGNATURE]);
mono_metadata_decode_value (sig, &sig);
/* FIELD signature == 0x06 */
MonoImage *m = class->image;
int top = class->field.count;
guint32 layout = class->flags & TYPE_ATTRIBUTE_LAYOUT_MASK;
- MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
int i, blittable = TRUE;
guint32 real_size = 0;
guint32 packing_size = 0;
const char *sig;
guint32 cols [MONO_FIELD_SIZE];
- mono_metadata_decode_row (t, idx, cols, MONO_FIELD_SIZE);
+ /* class->field.first and idx points into the fieldptr table */
+ mono_metadata_decode_table_row (m, MONO_TABLE_FIELD, idx, cols, MONO_FIELD_SIZE);
/* The name is needed for fieldrefs */
field->name = mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]);
sig = mono_metadata_blob_heap (m, cols [MONO_FIELD_SIGNATURE]);
for (pass = 0; pass < passes; ++pass) {
for (i = 0; i < top; i++){
- int size, align;
+ guint32 size, align;
+ MonoType *ftype;
field = &class->fields [i];
/* FIXME (LAMESPEC): should we also change the min alignment according to pack? */
align = class->packing_size ? MIN (class->packing_size, align): align;
+ /* if the field has managed references, we need to force-align it
+ * see bug #77788
+ */
+ ftype = mono_type_get_underlying_type (field->type);
+ if (MONO_TYPE_IS_REFERENCE (ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && mono_class_has_references (mono_class_from_mono_type (ftype)))))
+ align = sizeof (gpointer);
+
class->min_align = MAX (align, class->min_align);
field->offset = real_size;
field->offset += align - 1;
case TYPE_ATTRIBUTE_EXPLICIT_LAYOUT:
real_size = 0;
for (i = 0; i < top; i++) {
- int size, align;
+ guint32 size, align;
+ MonoType *ftype;
field = &class->fields [i];
* classes and valuetypes.
*/
field->offset += sizeof (MonoObject);
+ ftype = mono_type_get_underlying_type (field->type);
+ if (MONO_TYPE_IS_REFERENCE (ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && mono_class_has_references (mono_class_from_mono_type (ftype))))) {
+ if (field->offset % sizeof (gpointer)) {
+ mono_class_set_failure (class, MONO_EXCEPTION_TYPE_LOAD, NULL);
+ }
+ }
/*
* Calc max size.
* Compute static field layout and size
*/
for (i = 0; i < top; i++){
- int size, align;
+ guint32 size, align;
field = &class->fields [i];
if (!class->methods) {
methods = mono_mempool_alloc (class->image->mempool, sizeof (MonoMethod*) * class->method.count);
for (i = 0; i < class->method.count; ++i) {
- methods [i] = mono_get_method (class->image, MONO_TOKEN_METHOD_DEF | (i + class->method.first + 1), class);
+ int idx = mono_metadata_translate_token_index (class->image, MONO_TABLE_METHOD, class->method.first + i + 1);
+ methods [i] = mono_get_method (class->image, MONO_TOKEN_METHOD_DEF | idx, class);
}
}
{
guint startm, endm, i, j;
guint32 cols [MONO_PROPERTY_SIZE];
- MonoTableInfo *pt = &class->image->tables [MONO_TABLE_PROPERTY];
MonoTableInfo *msemt = &class->image->tables [MONO_TABLE_METHODSEMANTICS];
MonoProperty *properties;
guint32 last;
properties = mono_mempool_alloc0 (class->image->mempool, sizeof (MonoProperty) * class->property.count);
for (i = class->property.first; i < last; ++i) {
- mono_metadata_decode_row (pt, i, cols, MONO_PROPERTY_SIZE);
+ mono_metadata_decode_table_row (class->image, MONO_TABLE_PROPERTY, i, cols, MONO_PROPERTY_SIZE);
properties [i - class->property.first].parent = class;
properties [i - class->property.first].attrs = cols [MONO_PROPERTY_FLAGS];
properties [i - class->property.first].name = mono_metadata_string_heap (class->image, cols [MONO_PROPERTY_NAME]);
startm = mono_metadata_methods_from_property (class->image, i, &endm);
for (j = startm; j < endm; ++j) {
+ MonoMethod *method;
+
mono_metadata_decode_row (msemt, j, cols, MONO_METHOD_SEMA_SIZE);
+
+ if (class->image->uncompressed_metadata)
+ /* It seems like the MONO_METHOD_SEMA_METHOD column needs no remapping */
+ method = mono_get_method (class->image, MONO_TOKEN_METHOD_DEF | cols [MONO_METHOD_SEMA_METHOD], class);
+ else
+ method = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+
switch (cols [MONO_METHOD_SEMA_SEMANTICS]) {
case METHOD_SEMANTIC_SETTER:
- properties [i - class->property.first].set = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ properties [i - class->property.first].set = method;
break;
case METHOD_SEMANTIC_GETTER:
- properties [i - class->property.first].get = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ properties [i - class->property.first].get = method;
break;
default:
break;
{
guint startm, endm, i, j;
guint32 cols [MONO_EVENT_SIZE];
- MonoTableInfo *pt = &class->image->tables [MONO_TABLE_EVENT];
MonoTableInfo *msemt = &class->image->tables [MONO_TABLE_METHODSEMANTICS];
guint32 last;
MonoEvent *events;
events = mono_mempool_alloc0 (class->image->mempool, sizeof (MonoEvent) * class->event.count);
for (i = class->event.first; i < last; ++i) {
MonoEvent *event = &events [i - class->event.first];
-
- mono_metadata_decode_row (pt, i, cols, MONO_EVENT_SIZE);
+
+ mono_metadata_decode_table_row (class->image, MONO_TABLE_EVENT, i, cols, MONO_EVENT_SIZE);
event->parent = class;
event->attrs = cols [MONO_EVENT_FLAGS];
event->name = mono_metadata_string_heap (class->image, cols [MONO_EVENT_NAME]);
startm = mono_metadata_methods_from_event (class->image, i, &endm);
for (j = startm; j < endm; ++j) {
+ MonoMethod *method;
+
mono_metadata_decode_row (msemt, j, cols, MONO_METHOD_SEMA_SIZE);
+
+ if (class->image->uncompressed_metadata)
+ /* It seems like the MONO_METHOD_SEMA_METHOD column needs no remapping */
+ method = mono_get_method (class->image, MONO_TOKEN_METHOD_DEF | cols [MONO_METHOD_SEMA_METHOD], class);
+ else
+ method = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+
switch (cols [MONO_METHOD_SEMA_SEMANTICS]) {
case METHOD_SEMANTIC_ADD_ON:
- event->add = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ event->add = method;
break;
case METHOD_SEMANTIC_REMOVE_ON:
- event->remove = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ event->remove = method;
break;
case METHOD_SEMANTIC_FIRE:
- event->raise = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ event->raise = method;
break;
case METHOD_SEMANTIC_OTHER: {
int n = 0;
n++;
event->other = g_realloc (event->other, (n + 2) * sizeof (MonoMethod*));
}
- event->other [n] = class->methods [cols [MONO_METHOD_SEMA_METHOD] - 1 - class->method.first];
+ event->other [n] = method;
/* NULL terminated */
event->other [n + 1] = NULL;
break;
mono_class_setup_fields_locking (class);
while (class) {
- if (class->field.count) {
- if ((idx >= class->field.first) && (idx < class->field.first + class->field.count)){
- return &class->fields [idx - class->field.first];
+ if (class->image->uncompressed_metadata) {
+ /*
+ * class->field.first points to the FieldPtr table, while idx points into the
+ * Field table, so we have to do a search.
+ */
+ const char *name = mono_metadata_string_heap (class->image, mono_metadata_decode_row_col (&class->image->tables [MONO_TABLE_FIELD], idx, MONO_FIELD_NAME));
+ int i;
+
+ for (i = 0; i < class->field.count; ++i)
+ if (class->fields [i].name == name)
+ return &class->fields [i];
+ g_assert_not_reached ();
+ } else {
+ if (class->field.count) {
+ if ((idx >= class->field.first) && (idx < class->field.first + class->field.count)){
+ return &class->fields [idx - class->field.first];
+ }
}
}
class = class->parent;
mono_class_setup_fields_locking (klass);
while (klass) {
for (i = 0; i < klass->field.count; ++i) {
- if (&klass->fields [i] == field)
- return mono_metadata_make_token (MONO_TABLE_FIELD, klass->field.first + i + 1);
+ if (&klass->fields [i] == field) {
+ int idx = klass->field.first + i + 1;
+
+ if (klass->image->uncompressed_metadata)
+ idx = mono_metadata_translate_token_index (klass->image, MONO_TABLE_FIELD, idx);
+ return mono_metadata_make_token (MONO_TABLE_FIELD, idx);
+ }
}
klass = klass->parent;
}
* Obtains a MonoClass with a given namespace and a given name which
* is located in the given MonoImage. The namespace and name
* lookups are case insensitive.
- *
- * You can also pass @NULL to the image, and that will lookup for
- * a type with the given namespace and name in all of the loaded
- * assemblies: notice that since there might be a name clash in this
- * case, passing @NULL is not encouraged if you need a precise type.
- *
*/
MonoClass *
mono_class_from_name_case (MonoImage *image, const char* name_space, const char *name)
*
* Obtains a MonoClass with a given namespace and a given name which
* is located in the given MonoImage.
- *
- * You can also pass `NULL' to the image, and that will lookup for
- * a type with the given namespace and name in all of the loaded
- * assemblies: notice that since there might be a name clash in this
- * case, passing NULL is not encouraged if you need a precise type.
- *
*/
MonoClass *
mono_class_from_name (MonoImage *image, const char* name_space, const char *name)
mono_array_element_size (MonoClass *ac)
{
g_assert (ac->rank);
- g_assert (ac->sizes.element_size);
return ac->sizes.element_size;
}
return &klass->byval_arg;
}
+/**
+ * mono_class_get_type_token
+ * @klass: the MonoClass to act on
+ *
+ * This method returns type token for the class.
+ *
+ * Returns: the type token for the class.
+ */
+guint32
+mono_class_get_type_token (MonoClass *klass)
+{
+ return klass->type_token;
+}
+
/**
* mono_class_get_byref_type:
* @klass: the MonoClass to act on
return field->type->attrs;
}
+/**
+ * mono_field_get_data;
+ * @field: the MonoClassField to act on
+ *
+ * Returns: pointer to the metadata constant value or to the field
+ * data if it has an RVA flag.
+ */
+const char *
+mono_field_get_data (MonoClassField *field)
+{
+ return field->data;
+}
+
/**
* mono_property_get_name:
* @prop: the MonoProperty to act on
guint32 cols [MONO_METHOD_SIZE];
MonoMethod *method;
- mono_metadata_decode_row (&klass->image->tables [MONO_TABLE_METHOD], klass->method.first + i, cols, MONO_METHOD_SIZE);
+ /* class->method.first points into the methodptr table */
+ mono_metadata_decode_table_row (klass->image, MONO_TABLE_METHOD, klass->method.first + i, cols, MONO_METHOD_SIZE);
if (!strcmp (mono_metadata_string_heap (klass->image, cols [MONO_METHOD_NAME]), name)) {
method = mono_get_method (klass->image, MONO_TOKEN_METHOD_DEF | (klass->method.first + i + 1), klass);
mono_runtime_invoke (secman->inheritsecurityexception, NULL, args, &exc);
return (MonoException*) exc;
}
- case MONO_EXCEPTION_TYPE_LOAD:
- return mono_exception_from_name (mono_defaults.corlib, "System", "TypeLoadException");
-
+ case MONO_EXCEPTION_TYPE_LOAD: {
+ MonoString *name;
+ MonoException *ex;
+ char *str = mono_type_get_full_name (klass);
+ char *astr = klass->image->assembly? mono_stringify_assembly_name (&klass->image->assembly->aname): NULL;
+ name = mono_string_new (mono_domain_get (), str);
+ g_free (str);
+ ex = mono_get_exception_type_load (name, astr);
+ g_free (astr);
+ return ex;
+ }
default: {
MonoLoaderError *error;
MonoException *ex;