#include "mono-endian.h"
#include <mono/os/gc_wrapper.h>
+typedef struct {
+ char *p;
+ char *buf;
+ char *end;
+} SigBuffer;
+
#define TEXT_OFFSET 512
#define CLI_H_SIZE 136
#define FILE_ALIGN 512
static char* type_get_qualified_name (MonoType *type, MonoAssembly *ass);
static void ensure_runtime_vtable (MonoClass *klass);
static gpointer resolve_object (MonoImage *image, MonoObject *obj, MonoClass **handle_class);
-static void encode_type (MonoDynamicImage *assembly, MonoType *type, char *p, char **endbuf);
-static guint32 type_get_signature_size (MonoType *type);
+static void encode_type (MonoDynamicImage *assembly, MonoType *type, SigBuffer *buf);
static void get_default_param_value_blobs (MonoMethod *method, char **blobs, guint32 *types);
static MonoObject *mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob);
static inline MonoType *dup_type (const MonoType *original);
static MonoReflectionType *mono_reflection_type_get_underlying_system_type (MonoReflectionType* t);
+static MonoType* mono_reflection_get_type_with_rootimage (MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve);
#define mono_reflection_lock() EnterCriticalSection (&reflection_mutex)
#define mono_reflection_unlock() LeaveCriticalSection (&reflection_mutex)
InitializeCriticalSection (&reflection_mutex);
}
+static void
+sigbuffer_init (SigBuffer *buf, int size)
+{
+ buf->buf = g_malloc (size);
+ buf->p = buf->buf;
+ buf->end = buf->buf + size;
+}
+
+static void
+sigbuffer_make_room (SigBuffer *buf, int size)
+{
+ if (buf->end - buf->p < size) {
+ int new_size = buf->end - buf->buf + size + 32;
+ char *p = g_realloc (buf->buf, new_size);
+ size = buf->p - buf->buf;
+ buf->buf = p;
+ buf->p = p + size;
+ buf->end = buf->buf + new_size;
+ }
+}
+
+static void
+sigbuffer_add_value (SigBuffer *buf, guint32 val)
+{
+ sigbuffer_make_room (buf, 6);
+ mono_metadata_encode_value (val, buf->p, &buf->p);
+}
+
+static void
+sigbuffer_add_byte (SigBuffer *buf, guint8 val)
+{
+ sigbuffer_make_room (buf, 1);
+ buf->p [0] = val;
+ buf->p++;
+}
+
+static void
+sigbuffer_add_mem (SigBuffer *buf, char *p, guint32 size)
+{
+ sigbuffer_make_room (buf, size);
+ memcpy (buf->p, p, size);
+ buf->p += size;
+}
+
+static void
+sigbuffer_free (SigBuffer *buf)
+{
+ g_free (buf->buf);
+}
+
/**
* mp_g_alloc:
*
return g_malloc0 (size);
}
+/**
+ * mp_string_to_utf8:
+ *
+ * Allocate memory from the mempool MP if it is non-NULL. Otherwise, allocate
+ * memory from the C heap.
+ */
+static char *
+mp_string_to_utf8 (MonoMemPool *mp, MonoString *s)
+{
+ if (mp)
+ return mono_string_to_utf8_mp (mp, s);
+ else
+ return mono_string_to_utf8 (s);
+}
+
#define mp_g_new(mp,struct_type, n_structs) \
((struct_type *) mp_g_malloc (mp, ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
return idx;
}
+static guint32
+sigbuffer_add_to_blob_cached (MonoDynamicImage *assembly, SigBuffer *buf)
+{
+ char blob_size [8];
+ char *b = blob_size;
+ guint32 size = buf->p - buf->buf;
+ /* store length */
+ g_assert (size <= (buf->end - buf->buf));
+ mono_metadata_encode_value (size, b, &b);
+ return add_to_blob_cached (assembly, blob_size, b-blob_size, buf->buf, size);
+}
+
/*
* Copy len * nelem bytes from val to dest, swapping bytes to LE if necessary.
* dest may be misaligned.
case MONO_TYPE_STRING:
return mono_defaults.string_class;
default:
- g_warning ("implement me 0x%02x\n", type->type);
+ g_warning ("default_class_from_mono_type: implement me 0x%02x\n", type->type);
g_assert_not_reached ();
}
}
static void
-encode_generic_class (MonoDynamicImage *assembly, MonoGenericClass *gclass, char *p, char **endbuf)
+encode_generic_class (MonoDynamicImage *assembly, MonoGenericClass *gclass, SigBuffer *buf)
{
int i;
+ MonoGenericInst *class_inst;
- if (!gclass) {
- g_assert_not_reached ();
- return;
- }
+ g_assert (gclass);
- mono_metadata_encode_value (MONO_TYPE_GENERICINST, p, &p);
- encode_type (assembly, &gclass->container_class->byval_arg, p, &p);
- mono_metadata_encode_value (gclass->inst->type_argc, p, &p);
- for (i = 0; i < gclass->inst->type_argc; ++i)
- encode_type (assembly, gclass->inst->type_argv [i], p, &p);
+ class_inst = gclass->context.class_inst;
+
+ sigbuffer_add_value (buf, MONO_TYPE_GENERICINST);
+ encode_type (assembly, &gclass->container_class->byval_arg, buf);
+ sigbuffer_add_value (buf, class_inst->type_argc);
+ for (i = 0; i < class_inst->type_argc; ++i)
+ encode_type (assembly, class_inst->type_argv [i], buf);
- *endbuf = p;
}
static void
-encode_type (MonoDynamicImage *assembly, MonoType *type, char *p, char **endbuf)
+encode_type (MonoDynamicImage *assembly, MonoType *type, SigBuffer *buf)
{
if (!type) {
g_assert_not_reached ();
}
if (type->byref)
- mono_metadata_encode_value (MONO_TYPE_BYREF, p, &p);
+ sigbuffer_add_value (buf, MONO_TYPE_BYREF);
switch (type->type){
case MONO_TYPE_VOID:
case MONO_TYPE_STRING:
case MONO_TYPE_OBJECT:
case MONO_TYPE_TYPEDBYREF:
- mono_metadata_encode_value (type->type, p, &p);
+ sigbuffer_add_value (buf, type->type);
break;
case MONO_TYPE_PTR:
- mono_metadata_encode_value (type->type, p, &p);
- encode_type (assembly, type->data.type, p, &p);
+ sigbuffer_add_value (buf, type->type);
+ encode_type (assembly, type->data.type, buf);
break;
case MONO_TYPE_SZARRAY:
- mono_metadata_encode_value (type->type, p, &p);
- encode_type (assembly, &type->data.klass->byval_arg, p, &p);
+ sigbuffer_add_value (buf, type->type);
+ encode_type (assembly, &type->data.klass->byval_arg, buf);
break;
case MONO_TYPE_VALUETYPE:
case MONO_TYPE_CLASS: {
/*
* Make sure we use the correct type.
*/
- mono_metadata_encode_value (k->byval_arg.type, p, &p);
+ sigbuffer_add_value (buf, k->byval_arg.type);
/*
* ensure only non-byref gets passed to mono_image_typedef_or_ref(),
* otherwise two typerefs could point to the same type, leading to
* verification errors.
*/
- mono_metadata_encode_value (mono_image_typedef_or_ref (assembly, &k->byval_arg), p, &p);
+ sigbuffer_add_value (buf, mono_image_typedef_or_ref (assembly, &k->byval_arg));
break;
}
case MONO_TYPE_ARRAY:
- mono_metadata_encode_value (type->type, p, &p);
- encode_type (assembly, &type->data.array->eklass->byval_arg, p, &p);
- mono_metadata_encode_value (type->data.array->rank, p, &p);
- mono_metadata_encode_value (0, p, &p); /* FIXME: set to 0 for now */
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (buf, type->type);
+ encode_type (assembly, &type->data.array->eklass->byval_arg, buf);
+ sigbuffer_add_value (buf, type->data.array->rank);
+ sigbuffer_add_value (buf, 0); /* FIXME: set to 0 for now */
+ sigbuffer_add_value (buf, 0);
break;
case MONO_TYPE_GENERICINST:
- encode_generic_class (assembly, type->data.generic_class, p, &p);
+ encode_generic_class (assembly, type->data.generic_class, buf);
break;
case MONO_TYPE_VAR:
case MONO_TYPE_MVAR:
- mono_metadata_encode_value (type->type, p, &p);
- mono_metadata_encode_value (type->data.generic_param->num, p, &p);
+ sigbuffer_add_value (buf, type->type);
+ sigbuffer_add_value (buf, type->data.generic_param->num);
break;
default:
g_error ("need to encode type %x", type->type);
}
- *endbuf = p;
}
static void
-encode_reflection_type (MonoDynamicImage *assembly, MonoReflectionType *type, char *p, char **endbuf)
+encode_reflection_type (MonoDynamicImage *assembly, MonoReflectionType *type, SigBuffer *buf)
{
if (!type) {
- mono_metadata_encode_value (MONO_TYPE_VOID, p, endbuf);
+ sigbuffer_add_value (buf, MONO_TYPE_VOID);
return;
}
if (type->type ||
((type = mono_reflection_type_get_underlying_system_type (type)) && type->type)) {
- encode_type (assembly, type->type, p, endbuf);
+ encode_type (assembly, type->type, buf);
return;
}
}
static void
-encode_custom_modifiers (MonoDynamicImage *assembly, MonoArray *modreq, MonoArray *modopt, char *p, char **endbuf)
+encode_custom_modifiers (MonoDynamicImage *assembly, MonoArray *modreq, MonoArray *modopt, SigBuffer *buf)
{
int i;
if (modreq) {
for (i = 0; i < mono_array_length (modreq); ++i) {
MonoReflectionType *mod = mono_array_get (modreq, MonoReflectionType*, i);
- *p = MONO_TYPE_CMOD_REQD;
- p++;
- mono_metadata_encode_value (mono_image_typedef_or_ref (assembly, mod->type), p, &p);
+ sigbuffer_add_byte (buf, MONO_TYPE_CMOD_REQD);
+ sigbuffer_add_value (buf, mono_image_typedef_or_ref (assembly, mod->type));
}
}
if (modopt) {
for (i = 0; i < mono_array_length (modopt); ++i) {
MonoReflectionType *mod = mono_array_get (modopt, MonoReflectionType*, i);
- *p = MONO_TYPE_CMOD_OPT;
- p++;
- mono_metadata_encode_value (mono_image_typedef_or_ref (assembly, mod->type), p, &p);
+ sigbuffer_add_byte (buf, MONO_TYPE_CMOD_OPT);
+ sigbuffer_add_value (buf, mono_image_typedef_or_ref (assembly, mod->type));
}
}
- *endbuf = p;
-}
-
-static guint32
-generic_class_get_signature_size (MonoGenericClass *gclass)
-{
- guint32 size = 0;
- int i;
-
- if (!gclass) {
- g_assert_not_reached ();
- }
-
- size += 1 + type_get_signature_size (&gclass->container_class->byval_arg);
- size += 4;
- for (i = 0; i < gclass->inst->type_argc; ++i)
- size += type_get_signature_size (gclass->inst->type_argv [i]);
-
- return size;
-}
-
-static guint32
-type_get_signature_size (MonoType *type)
-{
- guint32 size = 0;
-
- if (!type) {
- g_assert_not_reached ();
- }
-
- if (type->byref)
- size++;
-
- switch (type->type){
- case MONO_TYPE_VOID:
- case MONO_TYPE_BOOLEAN:
- case MONO_TYPE_CHAR:
- case MONO_TYPE_I1:
- case MONO_TYPE_U1:
- case MONO_TYPE_I2:
- case MONO_TYPE_U2:
- case MONO_TYPE_I4:
- case MONO_TYPE_U4:
- case MONO_TYPE_I8:
- case MONO_TYPE_U8:
- case MONO_TYPE_R4:
- case MONO_TYPE_R8:
- case MONO_TYPE_I:
- case MONO_TYPE_U:
- case MONO_TYPE_STRING:
- case MONO_TYPE_OBJECT:
- case MONO_TYPE_TYPEDBYREF:
- return size + 1;
- case MONO_TYPE_PTR:
- return size + 1 + type_get_signature_size (type->data.type);
- case MONO_TYPE_SZARRAY:
- return size + 1 + type_get_signature_size (&type->data.klass->byval_arg);
- case MONO_TYPE_VALUETYPE:
- case MONO_TYPE_CLASS:
- return size + 5;
- case MONO_TYPE_ARRAY:
- return size + 7 + type_get_signature_size (&type->data.array->eklass->byval_arg);
- case MONO_TYPE_GENERICINST:
- return size + generic_class_get_signature_size (type->data.generic_class);
- case MONO_TYPE_VAR:
- case MONO_TYPE_MVAR:
- return size + 5;
- default:
- g_error ("need to encode type %x", type->type);
- return size;
- }
-}
-
-static guint32
-method_get_signature_size (MonoMethodSignature *sig)
-{
- guint32 size;
- int i;
-
- size = type_get_signature_size (sig->ret);
- for (i = 0; i < sig->param_count; i++)
- size += type_get_signature_size (sig->params [i]);
-
- if (sig->generic_param_count)
- size += 4;
- if (sig->sentinelpos >= 0)
- size++;
-
- return size;
}
static guint32
method_encode_signature (MonoDynamicImage *assembly, MonoMethodSignature *sig)
{
- char *buf;
- char *p;
+ SigBuffer buf;
int i;
guint32 nparams = sig->param_count;
- guint32 size = 11 + method_get_signature_size (sig);
guint32 idx;
- char blob_size [6];
- char *b = blob_size;
if (!assembly->save)
return 0;
- p = buf = g_malloc (size);
+ sigbuffer_init (&buf, 32);
/*
* FIXME: vararg, explicit_this, differenc call_conv values...
*/
- *p = sig->call_convention;
+ idx = sig->call_convention;
if (sig->hasthis)
- *p |= 0x20; /* hasthis */
+ idx |= 0x20; /* hasthis */
if (sig->generic_param_count)
- *p |= 0x10; /* generic */
- p++;
+ idx |= 0x10; /* generic */
+ sigbuffer_add_byte (&buf, idx);
if (sig->generic_param_count)
- mono_metadata_encode_value (sig->generic_param_count, p, &p);
- mono_metadata_encode_value (nparams, p, &p);
- encode_type (assembly, sig->ret, p, &p);
+ sigbuffer_add_value (&buf, sig->generic_param_count);
+ sigbuffer_add_value (&buf, nparams);
+ encode_type (assembly, sig->ret, &buf);
for (i = 0; i < nparams; ++i) {
if (i == sig->sentinelpos)
- *p++ = MONO_TYPE_SENTINEL;
- encode_type (assembly, sig->params [i], p, &p);
+ sigbuffer_add_byte (&buf, MONO_TYPE_SENTINEL);
+ encode_type (assembly, sig->params [i], &buf);
}
- /* store length */
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
/*
* FIXME: reuse code from method_encode_signature().
*/
- char *buf;
- char *p;
+ SigBuffer buf;
int i;
guint32 nparams = mb->parameters ? mono_array_length (mb->parameters): 0;
guint32 ngparams = mb->generic_params ? mono_array_length (mb->generic_params): 0;
guint32 notypes = mb->opt_types ? mono_array_length (mb->opt_types): 0;
- guint32 size = 41 + nparams * 40 + notypes * 40;
guint32 idx;
- char blob_size [6];
- char *b = blob_size;
- p = buf = g_malloc (size);
+ sigbuffer_init (&buf, 32);
/* LAMESPEC: all the call conv spec is foobared */
- *p = mb->call_conv & 0x60; /* has-this, explicit-this */
+ idx = mb->call_conv & 0x60; /* has-this, explicit-this */
if (mb->call_conv & 2)
- *p |= 0x5; /* vararg */
+ idx |= 0x5; /* vararg */
if (!(mb->attrs & METHOD_ATTRIBUTE_STATIC))
- *p |= 0x20; /* hasthis */
+ idx |= 0x20; /* hasthis */
if (ngparams)
- *p |= 0x10; /* generic */
- p++;
+ idx |= 0x10; /* generic */
+ sigbuffer_add_byte (&buf, idx);
if (ngparams)
- mono_metadata_encode_value (ngparams, p, &p);
- mono_metadata_encode_value (nparams + notypes, p, &p);
- encode_custom_modifiers (assembly, mb->return_modreq, mb->return_modopt, p, &p);
- encode_reflection_type (assembly, mb->rtype, p, &p);
+ sigbuffer_add_value (&buf, ngparams);
+ sigbuffer_add_value (&buf, nparams + notypes);
+ encode_custom_modifiers (assembly, mb->return_modreq, mb->return_modopt, &buf);
+ encode_reflection_type (assembly, mb->rtype, &buf);
for (i = 0; i < nparams; ++i) {
MonoArray *modreq = NULL;
MonoArray *modopt = NULL;
modreq = mono_array_get (mb->param_modreq, MonoArray*, i);
if (mb->param_modopt && (i < mono_array_length (mb->param_modopt)))
modopt = mono_array_get (mb->param_modopt, MonoArray*, i);
- encode_custom_modifiers (assembly, modreq, modopt, p, &p);
+ encode_custom_modifiers (assembly, modreq, modopt, &buf);
pt = mono_array_get (mb->parameters, MonoReflectionType*, i);
- encode_reflection_type (assembly, pt, p, &p);
+ encode_reflection_type (assembly, pt, &buf);
}
if (notypes)
- *p++ = MONO_TYPE_SENTINEL;
+ sigbuffer_add_byte (&buf, MONO_TYPE_SENTINEL);
for (i = 0; i < notypes; ++i) {
MonoReflectionType *pt;
pt = mono_array_get (mb->opt_types, MonoReflectionType*, i);
- encode_reflection_type (assembly, pt, p, &p);
+ encode_reflection_type (assembly, pt, &buf);
}
- /* store length */
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
{
MonoDynamicTable *table;
guint32 *values;
- char *p;
- guint32 idx, sig_idx, size;
+ guint32 idx, sig_idx;
guint nl = mono_array_length (ilgen->locals);
- char *buf;
- char blob_size [6];
- char *b = blob_size;
+ SigBuffer buf;
int i;
- size = 50 + nl * 30;
- p = buf = g_malloc (size);
+ sigbuffer_init (&buf, 32);
table = &assembly->tables [MONO_TABLE_STANDALONESIG];
idx = table->next_idx ++;
table->rows ++;
alloc_table (table, table->rows);
values = table->values + idx * MONO_STAND_ALONE_SIGNATURE_SIZE;
- mono_metadata_encode_value (0x07, p, &p);
- mono_metadata_encode_value (nl, p, &p);
+ sigbuffer_add_value (&buf, 0x07);
+ sigbuffer_add_value (&buf, nl);
for (i = 0; i < nl; ++i) {
MonoReflectionLocalBuilder *lb = mono_array_get (ilgen->locals, MonoReflectionLocalBuilder*, i);
if (lb->is_pinned)
- mono_metadata_encode_value (MONO_TYPE_PINNED, p, &p);
+ sigbuffer_add_value (&buf, MONO_TYPE_PINNED);
- encode_reflection_type (assembly, lb->type, p, &p);
+ encode_reflection_type (assembly, lb->type, &buf);
}
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- sig_idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ sig_idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
values [MONO_STAND_ALONE_SIGNATURE] = sig_idx;
static MonoCustomAttrInfo*
lookup_custom_attr (void *member)
{
- MonoCustomAttrInfo *ainfo;
+ MonoCustomAttrInfo *ainfo, *res;
+ int size;
+
mono_reflection_lock ();
ainfo = g_hash_table_lookup (dynamic_custom_attrs, member);
mono_reflection_unlock ();
- return ainfo;
+
+ if (ainfo) {
+ /* Need to copy since it will be freed later */
+ size = sizeof (MonoCustomAttrInfo) + sizeof (MonoCustomAttrEntry) * (ainfo->num_attrs - MONO_ZERO_LEN_ARRAY);
+ res = g_malloc0 (size);
+ memcpy (res, ainfo, size);
+ return res;
+ }
+ return NULL;
}
static gboolean
static guint32
fieldref_encode_signature (MonoDynamicImage *assembly, MonoType *type)
{
- char blob_size [64];
- char *b = blob_size;
- char *p;
- char* buf;
+ SigBuffer buf;
guint32 idx;
if (!assembly->save)
return 0;
- p = buf = g_malloc (256);
+ sigbuffer_init (&buf, 32);
- mono_metadata_encode_value (0x06, p, &p);
+ sigbuffer_add_value (&buf, 0x06);
/* encode custom attributes before the type */
- encode_type (assembly, type, p, &p);
- g_assert (p-buf < 256);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ encode_type (assembly, type, &buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
static guint32
field_encode_signature (MonoDynamicImage *assembly, MonoReflectionFieldBuilder *fb)
{
- char blob_size [64];
- char *b = blob_size;
- char *p;
- char* buf;
+ SigBuffer buf;
guint32 idx;
+
+ sigbuffer_init (&buf, 32);
- p = buf = g_malloc (256);
-
- mono_metadata_encode_value (0x06, p, &p);
- encode_custom_modifiers (assembly, fb->modreq, fb->modopt, p, &p);
+ sigbuffer_add_value (&buf, 0x06);
+ encode_custom_modifiers (assembly, fb->modreq, fb->modopt, &buf);
/* encode custom attributes before the type */
- encode_reflection_type (assembly, fb->type, p, &p);
- g_assert (p-buf < 256);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ encode_reflection_type (assembly, fb->type, &buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
g_free (buf);
return idx;
}
+ case MONO_TYPE_GENERICINST:
+ *ret_type = val->vtable->klass->generic_class->container_class->byval_arg.type;
+ goto handle_enum;
default:
g_error ("we don't encode constant type 0x%02x yet", *ret_type);
}
static guint32
encode_marshal_blob (MonoDynamicImage *assembly, MonoReflectionMarshal *minfo) {
- char blob_size [64];
- char *b = blob_size;
- char *p, *buf, *str;
- guint32 idx, len, bufsize = 256;
-
- p = buf = g_malloc (bufsize);
+ char *str;
+ SigBuffer buf;
+ guint32 idx, len;
- mono_metadata_encode_value (minfo->type, p, &p);
+ sigbuffer_init (&buf, 32);
+
+ sigbuffer_add_value (&buf, minfo->type);
switch (minfo->type) {
case MONO_NATIVE_BYVALTSTR:
case MONO_NATIVE_BYVALARRAY:
- mono_metadata_encode_value (minfo->count, p, &p);
+ sigbuffer_add_value (&buf, minfo->count);
break;
case MONO_NATIVE_LPARRAY:
if (minfo->eltype || minfo->has_size) {
- mono_metadata_encode_value (minfo->eltype, p, &p);
+ sigbuffer_add_value (&buf, minfo->eltype);
if (minfo->has_size) {
- if (minfo->param_num != -1)
- mono_metadata_encode_value (minfo->param_num, p, &p);
- else
- mono_metadata_encode_value (0, p, &p);
- if (minfo->count != -1)
- mono_metadata_encode_value (minfo->count, p, &p);
- else
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, minfo->param_num != -1? minfo->param_num: 0);
+ sigbuffer_add_value (&buf, minfo->count != -1? minfo->count: 0);
/* LAMESPEC: ElemMult is undocumented */
- if (minfo->param_num != -1)
- mono_metadata_encode_value (1, p, &p);
- else
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, minfo->param_num != -1? 1: 0);
}
}
break;
if (minfo->guid) {
str = mono_string_to_utf8 (minfo->guid);
len = strlen (str);
- mono_metadata_encode_value (len, p, &p);
- memcpy (p, str, len);
- p += len;
+ sigbuffer_add_value (&buf, len);
+ sigbuffer_add_mem (&buf, str, len);
g_free (str);
} else {
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, 0);
}
/* native type name */
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, 0);
/* custom marshaler type name */
if (minfo->marshaltype || minfo->marshaltyperef) {
if (minfo->marshaltyperef)
else
str = mono_string_to_utf8 (minfo->marshaltype);
len = strlen (str);
- mono_metadata_encode_value (len, p, &p);
- if (p + len >= buf + bufsize) {
- idx = p - buf;
- bufsize *= 2;
- buf = g_realloc (buf, bufsize);
- p = buf + idx;
- }
- memcpy (p, str, len);
- p += len;
+ sigbuffer_add_value (&buf, len);
+ sigbuffer_add_mem (&buf, str, len);
g_free (str);
} else {
/* FIXME: Actually a bug, since this field is required. Punting for now ... */
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, 0);
}
if (minfo->mcookie) {
str = mono_string_to_utf8 (minfo->mcookie);
len = strlen (str);
- mono_metadata_encode_value (len, p, &p);
- if (p + len >= buf + bufsize) {
- idx = p - buf;
- bufsize *= 2;
- buf = g_realloc (buf, bufsize);
- p = buf + idx;
- }
- memcpy (p, str, len);
- p += len;
+ sigbuffer_add_value (&buf, len);
+ sigbuffer_add_mem (&buf, str, len);
g_free (str);
} else {
- mono_metadata_encode_value (0, p, &p);
+ sigbuffer_add_value (&buf, 0);
}
break;
default:
break;
}
- len = p-buf;
- mono_metadata_encode_value (len, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, len);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
static guint32
property_encode_signature (MonoDynamicImage *assembly, MonoReflectionPropertyBuilder *fb)
{
- char *buf, *p;
- char blob_size [6];
- char *b = blob_size;
+ SigBuffer buf;
guint32 nparams = 0;
MonoReflectionMethodBuilder *mb = fb->get_method;
MonoReflectionMethodBuilder *smb = fb->set_method;
- guint32 idx, i, size;
+ guint32 idx, i;
if (mb && mb->parameters)
nparams = mono_array_length (mb->parameters);
if (!mb && smb && smb->parameters)
nparams = mono_array_length (smb->parameters) - 1;
- size = 24 + nparams * 10;
- buf = p = g_malloc (size);
- *p = 0x08;
- p++;
- mono_metadata_encode_value (nparams, p, &p);
+ sigbuffer_init (&buf, 32);
+ sigbuffer_add_byte (&buf, 0x08);
+ sigbuffer_add_value (&buf, nparams);
if (mb) {
- encode_reflection_type (assembly, mb->rtype, p, &p);
+ encode_reflection_type (assembly, mb->rtype, &buf);
for (i = 0; i < nparams; ++i) {
MonoReflectionType *pt = mono_array_get (mb->parameters, MonoReflectionType*, i);
- encode_reflection_type (assembly, pt, p, &p);
+ encode_reflection_type (assembly, pt, &buf);
}
} else if (smb && smb->parameters) {
/* the property type is the last param */
- encode_reflection_type (assembly, mono_array_get (smb->parameters, MonoReflectionType*, nparams), p, &p);
+ encode_reflection_type (assembly, mono_array_get (smb->parameters, MonoReflectionType*, nparams), &buf);
for (i = 0; i < nparams; ++i) {
MonoReflectionType *pt = mono_array_get (smb->parameters, MonoReflectionType*, i);
- encode_reflection_type (assembly, pt, p, &p);
+ encode_reflection_type (assembly, pt, &buf);
}
- }
- else {
- encode_reflection_type (assembly, fb->type, p, &p);
+ } else {
+ encode_reflection_type (assembly, fb->type, &buf);
}
- /* store length */
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
MonoDynamicTable *table;
guint32 *values;
guint32 token;
- char sig [128];
- char *p = sig;
- char blob_size [6];
- char *b = blob_size;
+ SigBuffer buf;
+ sigbuffer_init (&buf, 32);
switch (type->type) {
case MONO_TYPE_FNPTR:
case MONO_TYPE_PTR:
case MONO_TYPE_VAR:
case MONO_TYPE_MVAR:
case MONO_TYPE_GENERICINST:
- encode_type (assembly, type, p, &p);
+ encode_type (assembly, type, &buf);
break;
case MONO_TYPE_CLASS:
case MONO_TYPE_VALUETYPE: {
MonoClass *k = mono_class_from_mono_type (type);
- if (!k || !k->generic_class)
+ if (!k || !k->generic_class) {
+ sigbuffer_free (&buf);
return 0;
- encode_generic_class (assembly, k->generic_class, p, &p);
+ }
+ encode_generic_class (assembly, k->generic_class, &buf);
break;
}
default:
+ sigbuffer_free (&buf);
return 0;
}
table = &assembly->tables [MONO_TABLE_TYPESPEC];
if (assembly->save) {
- g_assert (p-sig < 128);
- mono_metadata_encode_value (p-sig, b, &b);
- token = add_to_blob_cached (assembly, blob_size, b-blob_size, sig, p-sig);
+ token = sigbuffer_add_to_blob_cached (assembly, &buf);
alloc_table (table, table->rows + 1);
values = table->values + table->next_idx * MONO_TYPESPEC_SIZE;
values [MONO_TYPESPEC_SIGNATURE] = token;
}
+ sigbuffer_free (&buf);
token = MONO_TYPEDEFORREF_TYPESPEC | (table->next_idx << MONO_TYPEDEFORREF_BITS);
g_hash_table_insert (assembly->typeref, type, GUINT_TO_POINTER(token));
}
static guint32
-encode_generic_method_sig (MonoDynamicImage *assembly, MonoGenericMethod *gmethod)
+encode_generic_method_sig (MonoDynamicImage *assembly, MonoGenericContext *context)
{
- char *buf;
- char *p;
+ SigBuffer buf;
int i;
- guint32 nparams = gmethod->inst->type_argc;
- guint32 size = 10 + nparams * 30;
+ guint32 nparams = context->method_inst->type_argc;
guint32 idx;
- char blob_size [6];
- char *b = blob_size;
if (!assembly->save)
return 0;
- p = buf = g_malloc (size);
+ sigbuffer_init (&buf, 32);
/*
* FIXME: vararg, explicit_this, differenc call_conv values...
*/
- mono_metadata_encode_value (0xa, p, &p); /* FIXME FIXME FIXME */
- mono_metadata_encode_value (nparams, p, &p);
+ sigbuffer_add_value (&buf, 0xa); /* FIXME FIXME FIXME */
+ sigbuffer_add_value (&buf, nparams);
for (i = 0; i < nparams; i++)
- encode_type (assembly, gmethod->inst->type_argv [i], p, &p);
+ encode_type (assembly, context->method_inst->type_argv [i], &buf);
- /* store length */
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
table = &assembly->tables [MONO_TABLE_METHODSPEC];
g_assert (method->is_inflated);
+ g_assert (!method->klass->generic_container);
imethod = (MonoMethodInflated *) method;
declaring = imethod->declaring;
g_assert_not_reached ();
}
- sig = encode_generic_method_sig (assembly, mono_method_get_context (method)->gmethod);
+ sig = encode_generic_method_sig (assembly, mono_method_get_context (method));
if (assembly->save) {
alloc_table (table, table->rows + 1);
MonoClass *klass;
guint32 *values;
guint32 token;
- char sig [128];
- char *p = sig;
- char blob_size [6];
- char *b = blob_size;
+ SigBuffer buf;
int count, i;
/*
if (token)
return token;
+ sigbuffer_init (&buf, 32);
+
g_assert (tb->generic_params);
klass = mono_class_from_mono_type (tb->type.type);
- mono_metadata_encode_value (MONO_TYPE_GENERICINST, p, &p);
- encode_type (assembly, &klass->byval_arg, p, &p);
+ sigbuffer_add_value (&buf, MONO_TYPE_GENERICINST);
+ encode_type (assembly, &klass->byval_arg, &buf);
count = mono_array_length (tb->generic_params);
- mono_metadata_encode_value (count, p, &p);
+ sigbuffer_add_value (&buf, count);
for (i = 0; i < count; i++) {
MonoReflectionGenericParam *gparam;
gparam = mono_array_get (tb->generic_params, MonoReflectionGenericParam *, i);
- encode_type (assembly, gparam->type.type, p, &p);
+ encode_type (assembly, gparam->type.type, &buf);
}
table = &assembly->tables [MONO_TABLE_TYPESPEC];
- g_assert (p-sig < 128);
if (assembly->save) {
- mono_metadata_encode_value (p-sig, b, &b);
- token = add_to_blob_cached (assembly, blob_size, b-blob_size, sig, p-sig);
+ token = sigbuffer_add_to_blob_cached (assembly, &buf);
alloc_table (table, table->rows + 1);
values = table->values + table->next_idx * MONO_TYPESPEC_SIZE;
values [MONO_TYPESPEC_SIGNATURE] = token;
}
+ sigbuffer_free (&buf);
token = MONO_TYPEDEFORREF_TYPESPEC | (table->next_idx << MONO_TYPEDEFORREF_BITS);
g_hash_table_insert (assembly->typespec, tb->type.type, GUINT_TO_POINTER(token));
static guint32
mono_reflection_encode_sighelper (MonoDynamicImage *assembly, MonoReflectionSigHelper *helper)
{
- char *buf;
- char *p;
+ SigBuffer buf;
guint32 nargs;
guint32 size;
guint32 i, idx;
- char blob_size [6];
- char *b = blob_size;
if (!assembly->save)
return 0;
size = 10 + (nargs * 10);
- p = buf = g_malloc (size);
+ sigbuffer_init (&buf, 32);
/* Encode calling convention */
/* Change Any to Standard */
helper->call_conv &= 0x20;
if (helper->call_conv == 0) { /* Unmanaged */
- *p = helper->unmanaged_call_conv - 1;
+ idx = helper->unmanaged_call_conv - 1;
} else {
/* Managed */
- *p = helper->call_conv & 0x60; /* has_this + explicit_this */
+ idx = helper->call_conv & 0x60; /* has_this + explicit_this */
if (helper->call_conv & 0x02) /* varargs */
- *p += 0x05;
+ idx += 0x05;
}
- p++;
- mono_metadata_encode_value (nargs, p, &p);
- encode_reflection_type (assembly, helper->return_type, p, &p);
+ sigbuffer_add_byte (&buf, idx);
+ sigbuffer_add_value (&buf, nargs);
+ encode_reflection_type (assembly, helper->return_type, &buf);
for (i = 0; i < nargs; ++i) {
MonoReflectionType *pt = mono_array_get (helper->arguments, MonoReflectionType*, i);
- encode_reflection_type (assembly, pt, p, &p);
+ encode_reflection_type (assembly, pt, &buf);
}
- /* store length */
- g_assert (p - buf < size);
- mono_metadata_encode_value (p-buf, b, &b);
- idx = add_to_blob_cached (assembly, blob_size, b-blob_size, buf, p-buf);
- g_free (buf);
+ idx = sigbuffer_add_to_blob_cached (assembly, &buf);
+ sigbuffer_free (&buf);
return idx;
}
resource_tree_encode (tree, p, p, &p);
- g_assert (p - buf < size);
+ g_assert (p - buf <= size);
assembly->win32_res = g_malloc (p - buf);
assembly->win32_res_size = p - buf;
}
MonoReflectionModule *
-mono_image_load_module (MonoReflectionAssemblyBuilder *ab, MonoString *fileName)
+mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *ab, MonoString *fileName)
{
char *name;
MonoImage *image;
MonoDynamicAssembly *assembly;
guint32 module_count;
MonoImage **new_modules;
+ gboolean *new_modules_loaded;
name = mono_string_to_utf8 (fileName);
module_count = image->assembly->image->module_count;
new_modules = g_new0 (MonoImage *, module_count + 1);
+ new_modules_loaded = g_new0 (gboolean, module_count + 1);
if (image->assembly->image->modules)
memcpy (new_modules, image->assembly->image->modules, module_count * sizeof (MonoImage *));
+ if (image->assembly->image->modules_loaded)
+ memcpy (new_modules_loaded, image->assembly->image->modules_loaded, module_count * sizeof (gboolean));
new_modules [module_count] = image;
+ new_modules_loaded [module_count] = TRUE;
mono_image_addref (image);
g_free (image->assembly->image->modules);
image->assembly->image->modules = new_modules;
+ image->assembly->image->modules_loaded = new_modules_loaded;
image->assembly->image->module_count ++;
mono_assembly_load_references (image, &status);
return t1->data.array->eklass == t2->data.array->eklass;
case MONO_TYPE_GENERICINST: {
int i;
- if (t1->data.generic_class->inst->type_argc != t2->data.generic_class->inst->type_argc)
+ MonoGenericInst *i1 = t1->data.generic_class->context.class_inst;
+ MonoGenericInst *i2 = t2->data.generic_class->context.class_inst;
+ if (i1->type_argc != i2->type_argc)
return FALSE;
if (!mono_metadata_type_equal (&t1->data.generic_class->container_class->byval_arg,
&t2->data.generic_class->container_class->byval_arg))
return FALSE;
- for (i = 0; i < t1->data.generic_class->inst->type_argc; ++i) {
- if (!mono_metadata_type_equal (t1->data.generic_class->inst->type_argv [i], t2->data.generic_class->inst->type_argv [i]))
+ /* FIXME: we should probably just compare the instance pointers directly. */
+ for (i = 0; i < i1->type_argc; ++i) {
+ if (!mono_metadata_type_equal (i1->type_argv [i], i2->type_argv [i]))
return FALSE;
}
return TRUE;
return ((hash << 5) - hash) ^ mymono_metadata_type_hash (t1->data.type);
case MONO_TYPE_GENERICINST: {
int i;
- MonoGenericInst *inst = t1->data.generic_class->inst;
+ MonoGenericInst *inst = t1->data.generic_class->context.class_inst;
hash += g_str_hash (t1->data.generic_class->container_class->name);
hash *= 13;
for (i = 0; i < inst->type_argc; ++i) {
mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *field)
{
MonoReflectionField *res;
- MonoClass *oklass;
+ static MonoClass *monofield_klass;
CHECK_OBJECT (MonoReflectionField *, field, klass);
- oklass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoField");
- res = (MonoReflectionField *)mono_object_new (domain, oklass);
+ if (!monofield_klass)
+ monofield_klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoField");
+ res = (MonoReflectionField *)mono_object_new (domain, monofield_klass);
res->klass = klass;
res->field = field;
MONO_OBJECT_SETREF (res, name, mono_string_new (domain, field->name));
mono_property_get_object (MonoDomain *domain, MonoClass *klass, MonoProperty *property)
{
MonoReflectionProperty *res;
- MonoClass *oklass;
+ static MonoClass *monoproperty_klass;
CHECK_OBJECT (MonoReflectionProperty *, property, klass);
- oklass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoProperty");
- res = (MonoReflectionProperty *)mono_object_new (domain, oklass);
+ if (!monoproperty_klass)
+ monoproperty_klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoProperty");
+ res = (MonoReflectionProperty *)mono_object_new (domain, monoproperty_klass);
res->klass = klass;
res->property = property;
CACHE_OBJECT (MonoReflectionProperty *, property, res, klass);
mono_event_get_object (MonoDomain *domain, MonoClass *klass, MonoEvent *event)
{
MonoReflectionEvent *res;
- MonoClass *oklass;
+ static MonoClass *monoevent_klass;
CHECK_OBJECT (MonoReflectionEvent *, event, klass);
- oklass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoEvent");
- res = (MonoReflectionEvent *)mono_object_new (domain, oklass);
+ if (!monoevent_klass)
+ monoevent_klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoEvent");
+ res = (MonoReflectionEvent *)mono_object_new (domain, monoevent_klass);
res->klass = klass;
res->event = event;
CACHE_OBJECT (MonoReflectionEvent *, event, res, klass);
mono_get_dbnull_object (MonoDomain *domain)
{
MonoObject *obj;
- MonoClass *klass;
static MonoClassField *dbnull_value_field = NULL;
if (!dbnull_value_field) {
- klass = mono_class_from_name (mono_defaults.corlib, "System", "DBNull");
- mono_class_init (klass);
- dbnull_value_field = mono_class_get_field_from_name (klass, "Value");
+ MonoClass *dbnull_klass;
+ dbnull_klass = mono_class_from_name (mono_defaults.corlib, "System", "DBNull");
+ mono_class_init (dbnull_klass);
+ dbnull_value_field = mono_class_get_field_from_name (dbnull_klass, "Value");
g_assert (dbnull_value_field);
}
obj = mono_field_get_value_object (domain, dbnull_value_field, NULL);
{
gboolean type_resolve = FALSE;
MonoType *type;
+ MonoImage *rootimage = image;
if (info->assembly.name) {
MonoAssembly *assembly = mono_assembly_loaded (&info->assembly);
image = mono_defaults.corlib;
}
- type = mono_reflection_get_type (image, info, ignorecase, &type_resolve);
+ type = mono_reflection_get_type_with_rootimage (rootimage, image, info, ignorecase, &type_resolve);
if (type == NULL && !info->assembly.name && image != mono_defaults.corlib) {
image = mono_defaults.corlib;
- type = mono_reflection_get_type (image, info, ignorecase, &type_resolve);
+ type = mono_reflection_get_type_with_rootimage (rootimage, image, info, ignorecase, &type_resolve);
}
return type;
}
static MonoType*
-mono_reflection_get_type_internal (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase)
+mono_reflection_get_type_internal (MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase)
{
MonoClass *klass;
GList *mod;
for (i = 0; i < info->type_arguments->len; i++) {
MonoTypeNameParse *subinfo = g_ptr_array_index (info->type_arguments, i);
- type_args [i] = _mono_reflection_get_type_from_info (subinfo, image, ignorecase);
+ type_args [i] = _mono_reflection_get_type_from_info (subinfo, rootimage, ignorecase);
if (!type_args [i]) {
g_free (type_args);
return NULL;
*/
MonoType*
-mono_reflection_get_type (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve)
+mono_reflection_get_type (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve) {
+ return mono_reflection_get_type_with_rootimage(image, image, info, ignorecase, type_resolve);
+}
+
+MonoType*
+mono_reflection_get_type_with_rootimage (MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve)
{
MonoType *type;
MonoReflectionAssembly *assembly;
GString *fullName;
GList *mod;
- type = mono_reflection_get_type_internal (image, info, ignorecase);
+ type = mono_reflection_get_type_internal (rootimage, image, info, ignorecase);
if (type)
return type;
if (!mono_domain_has_type_resolve (mono_domain_get ()))
if (abuilder->modules) {
for (i = 0; i < mono_array_length (abuilder->modules); ++i) {
MonoReflectionModuleBuilder *mb = mono_array_get (abuilder->modules, MonoReflectionModuleBuilder*, i);
- type = mono_reflection_get_type_internal (&mb->dynamic_image->image, info, ignorecase);
+ type = mono_reflection_get_type_internal (rootimage, &mb->dynamic_image->image, info, ignorecase);
if (type)
break;
}
if (!type && abuilder->loaded_modules) {
for (i = 0; i < mono_array_length (abuilder->loaded_modules); ++i) {
MonoReflectionModule *mod = mono_array_get (abuilder->loaded_modules, MonoReflectionModule*, i);
- type = mono_reflection_get_type_internal (mod->image, info, ignorecase);
+ type = mono_reflection_get_type_internal (rootimage, mod->image, info, ignorecase);
if (type)
break;
}
}
}
else
- type = mono_reflection_get_type_internal (assembly->assembly->image,
+ type = mono_reflection_get_type_internal (rootimage, assembly->assembly->image,
info, ignorecase);
}
g_string_free (fullName, TRUE);
case MONO_TYPE_U: /* error out instead? this should probably not happen */
case MONO_TYPE_I:
#endif
- case MONO_TYPE_R8:
case MONO_TYPE_U8:
case MONO_TYPE_I8: {
guint64 *val = g_malloc (sizeof (guint64));
*end = p + 8;
return val;
}
+ case MONO_TYPE_R8: {
+ double *val = g_malloc (sizeof (double));
+ readr8 (p, val);
+ *end = p + 8;
+ return val;
+ }
case MONO_TYPE_VALUETYPE:
if (t->data.klass->enumtype) {
type = t->data.klass->enum_basetype->type;
int etype = *p;
p ++;
+ if (etype == 0x51)
+ /* See Partition II, Appendix B3 */
+ etype = MONO_TYPE_OBJECT;
type = MONO_TYPE_SZARRAY;
simple_type.type = etype;
tklass = mono_class_from_mono_type (&simple_type);
}
break;
case MONO_TYPE_R8:
+ for (i = 0; i < alen; i++) {
+ double val;
+ readr8 (p, &val);
+ mono_array_set (arr, double, i, val);
+ p += 8;
+ }
+ break;
case MONO_TYPE_U8:
case MONO_TYPE_I8:
for (i = 0; i < alen; i++) {
{
MonoArray *typedargs, *namedargs;
MonoClass *attrklass;
- static MonoClass *klass;
static MonoMethod *ctor;
MonoDomain *domain;
MonoObject *attr;
void *params [3];
mono_class_init (method->klass);
-
- if (!klass)
- klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "CustomAttributeData");
+
if (!ctor)
- ctor = mono_class_get_method_from_name (klass, ".ctor", 3);
-
+ ctor = mono_class_get_method_from_name (mono_defaults.customattribute_data_class, ".ctor", 3);
+
domain = mono_domain_get ();
if (len == 0) {
/* This is for Attributes with no parameters */
- attr = mono_object_new (domain, klass);
+ attr = mono_object_new (domain, mono_defaults.customattribute_data_class);
params [0] = mono_method_get_object (domain, method, NULL);
params [1] = params [2] = NULL;
mono_runtime_invoke (method, attr, params, NULL);
}
g_free (name);
}
- attr = mono_object_new (domain, klass);
+ attr = mono_object_new (domain, mono_defaults.customattribute_data_class);
params [0] = mono_method_get_object (domain, method, NULL);
params [1] = typedargs;
params [2] = namedargs;
mono_custom_attrs_construct (MonoCustomAttrInfo *cinfo)
{
MonoArray *result;
- MonoClass *klass;
MonoObject *attr;
int i;
- klass = mono_class_from_name (mono_defaults.corlib, "System", "Attribute");
- result = mono_array_new (mono_domain_get (), klass, cinfo->num_attrs);
+ result = mono_array_new (mono_domain_get (), mono_defaults.attribute_class, cinfo->num_attrs);
for (i = 0; i < cinfo->num_attrs; ++i) {
attr = create_custom_attr (cinfo->image, cinfo->attrs [i].ctor, cinfo->attrs [i].data, cinfo->attrs [i].data_size);
mono_array_setref (result, i, attr);
{
MonoArray *result;
MonoObject *attr;
- MonoClass *klass;
int i, n;
n = 0;
n ++;
}
- klass = mono_class_from_name (mono_defaults.corlib, "System", "Attribute");
- result = mono_array_new (mono_domain_get (), klass, n);
+ result = mono_array_new (mono_domain_get (), mono_defaults.attribute_class, n);
n = 0;
for (i = 0; i < cinfo->num_attrs; ++i) {
if (mono_class_is_assignable_from (attr_klass, cinfo->attrs [i].ctor->klass)) {
mono_custom_attrs_data_construct (MonoCustomAttrInfo *cinfo)
{
MonoArray *result;
- static MonoClass *klass;
MonoObject *attr;
int i;
-
- if (!klass)
- klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "CustomAttributeData");
- result = mono_array_new (mono_domain_get (), klass, cinfo->num_attrs);
+ result = mono_array_new (mono_domain_get (), mono_defaults.customattribute_data_class, cinfo->num_attrs);
for (i = 0; i < cinfo->num_attrs; ++i) {
attr = create_custom_attr_data (cinfo->image, cinfo->attrs [i].ctor, cinfo->attrs [i].data, cinfo->attrs [i].data_size);
mono_array_setref (result, i, attr);
return result;
}
+/**
+ * mono_custom_attrs_from_index:
+ *
+ * Returns: NULL if no attributes are found or if a loading error occurs.
+ */
MonoCustomAttrInfo*
mono_custom_attrs_from_index (MonoImage *image, guint32 idx)
{
break;
}
ainfo->attrs [i].ctor = mono_get_method (image, mtoken, NULL);
- if (!ainfo->attrs [i].ctor)
- g_error ("Can't find custom attr constructor image: %s mtoken: 0x%08x", image->name, mtoken);
+ if (!ainfo->attrs [i].ctor) {
+ g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x", image->name, mtoken);
+ g_list_free (list);
+ g_free (ainfo);
+ return NULL;
+ }
data = mono_metadata_blob_heap (image, cols [MONO_CUSTOM_ATTR_VALUE]);
ainfo->attrs [i].data_size = mono_metadata_decode_value (data, &data);
ainfo->attrs [i].data = (guchar*)data;
MonoReflectionMethodAux *aux;
if (method->klass->image->dynamic) {
+ MonoCustomAttrInfo *res, *ainfo;
+ int size;
+
aux = g_hash_table_lookup (((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
if (!aux || !aux->param_cattr)
return NULL;
- return aux->param_cattr [param];
+
+ /* Need to copy since it will be freed later */
+ ainfo = aux->param_cattr [param];
+ size = sizeof (MonoCustomAttrInfo) + sizeof (MonoCustomAttrEntry) * (ainfo->num_attrs - MONO_ZERO_LEN_ARRAY);
+ res = g_malloc0 (size);
+ memcpy (res, ainfo, size);
+ return res;
}
image = method->klass->image;
*
* Return an array with all the custom attributes defined of the
* reflection handle @obj. If @attr_klass is non-NULL, only custom attributes
- * of that type are returned. The objects are fully build.
+ * of that type are returned. The objects are fully build. Return NULL if a loading error
+ * occurs.
*/
MonoArray*
mono_reflection_get_custom_attrs_by_type (MonoObject *obj, MonoClass *attr_klass)
if (!cinfo->cached)
mono_custom_attrs_free (cinfo);
} else {
- MonoClass *klass;
- klass = mono_class_from_name (mono_defaults.corlib, "System", "Attribute");
- result = mono_array_new (mono_domain_get (), klass, 0);
+ if (mono_loader_get_last_error ())
+ return NULL;
+ result = mono_array_new (mono_domain_get (), mono_defaults.attribute_class, 0);
}
return result;
* @obj: a reflection object handle
*
* Return an array with all the custom attributes defined of the
- * reflection handle @obj. The objects are fully build.
+ * reflection handle @obj. The objects are fully build. Return NULL if a loading error
+ * occurs.
*/
MonoArray*
mono_reflection_get_custom_attrs (MonoObject *obj)
result = mono_custom_attrs_data_construct (cinfo);
if (!cinfo->cached)
mono_custom_attrs_free (cinfo);
- } else {
- MonoClass *klass;
- klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "CustomAttributeData");
- result = mono_array_new (mono_domain_get (), klass, 0);
- }
+ } else
+ result = mono_array_new (mono_domain_get (), mono_defaults.customattribute_data_class, 0);
return result;
}
swap_with_size (p, argval, 4, 1);
p += 4;
break;
+ case MONO_TYPE_R8:
+#if defined(ARM_FPU_FPA) && G_BYTE_ORDER == G_LITTLE_ENDIAN
+ p [0] = argval [4];
+ p [1] = argval [5];
+ p [2] = argval [6];
+ p [3] = argval [7];
+ p [4] = argval [0];
+ p [5] = argval [1];
+ p [6] = argval [2];
+ p [7] = argval [3];
+#else
+ swap_with_size (p, argval, 8, 1);
+#endif
+ p += 8;
+ break;
case MONO_TYPE_U8:
case MONO_TYPE_I8:
- case MONO_TYPE_R8:
swap_with_size (p, argval, 8, 1);
p += 8;
break;
goto handle_enum;
} else if (klass->rank == 1) {
*p++ = 0x1D;
- *p++ = klass->element_class->byval_arg.type;
+ if (klass->element_class->byval_arg.type == MONO_TYPE_OBJECT)
+ /* See Partition II, Appendix B3 */
+ *p++ = 0x51;
+ else
+ *p++ = klass->element_class->byval_arg.type;
encode_cattr_value (assembly, buffer, p, &buffer, &p, buflen, &klass->byval_arg, arg, NULL);
break;
} else if (klass->byval_arg.type >= MONO_TYPE_BOOLEAN && klass->byval_arg.type <= MONO_TYPE_R8) {
fb = mono_array_get (tb->fields, MonoReflectionFieldBuilder*, 0);
+ if (!mono_type_is_valid_enum_basetype (fb->type->type)) {
+ mono_loader_unlock ();
+ return;
+ }
+
klass->enum_basetype = fb->type->type;
klass->element_class = my_mono_class_from_mono_type (klass->enum_basetype);
if (!klass->element_class)
pm = (MonoMethodNormal*)m;
+ m->dynamic = dynamic;
m->slot = -1;
m->flags = rmb->attrs;
m->iflags = rmb->iattrs;
- m->name = dynamic ? mono_string_to_utf8 (rmb->name) : mono_string_to_utf8_mp (mp, rmb->name);
+ m->name = mp_string_to_utf8 (mp, rmb->name);
m->klass = klass;
m->signature = sig;
m->skip_visibility = rmb->skip_visibility;
container->parent = klass->generic_container;
container->context.class_inst = klass->generic_container->context.class_inst;
}
- container->context.gmethod = mono_get_shared_generic_method (container);
+ container->context.method_inst = mono_get_shared_generic_inst (container);
}
if (rmb->refs) {
}
if (pb->name)
- method_aux->param_names [i] = dynamic ? mono_string_to_utf8 (pb->name) : mono_string_to_utf8_mp (mp, pb->name);
+ method_aux->param_names [i] = mp_string_to_utf8 (mp, pb->name);
if (pb->cattrs) {
if (!method_aux->param_cattr)
method_aux->param_cattr = mp_g_new0 (mp, MonoCustomAttrInfo*, m->signature->param_count + 1);
{
MonoClass *klass;
MonoReflectionTypeBuilder *tb = NULL;
- MonoGenericClass *gclass, *cached;
gboolean is_dynamic = FALSE;
MonoDomain *domain;
- MonoType *geninst;
- int i;
+ MonoClass *geninst;
mono_loader_lock ();
is_dynamic = TRUE;
}
- if (is_dynamic) {
- MonoDynamicGenericClass *dgclass = g_new0 (MonoDynamicGenericClass, 1);
- gclass = &dgclass->generic_class;
- gclass->is_dynamic = TRUE;
- } else {
- gclass = g_new0 (MonoGenericClass, 1);
- }
-
- gclass->inst = g_new0 (MonoGenericInst, 1);
-
- gclass->inst->type_argc = type_argc;
- gclass->inst->type_argv = g_new0 (MonoType *, gclass->inst->type_argc);
- gclass->inst->is_reference = 1;
-
- for (i = 0; i < gclass->inst->type_argc; ++i) {
- MonoType *t = dup_type (types [i]);
-
- if (!gclass->inst->is_open)
- gclass->inst->is_open = mono_class_is_open_constructed_type (t);
- if (gclass->inst->is_reference)
- gclass->inst->is_reference = MONO_TYPE_IS_REFERENCE (t);
- gclass->inst->type_argv [i] = t;
- }
-
- gclass->inst = mono_metadata_lookup_generic_inst (gclass->inst);
-
- gclass->container_class = klass;
-
- geninst = g_new0 (MonoType, 1);
- geninst->type = MONO_TYPE_GENERICINST;
-
- cached = mono_metadata_lookup_generic_class (gclass);
- if (cached) {
- g_free (gclass);
- mono_loader_unlock ();
- geninst->data.generic_class = cached;
- return geninst;
- }
-
- geninst->data.generic_class = gclass;
-
mono_loader_unlock ();
- return geninst;
+ geninst = mono_class_bind_generic_parameters (klass, type_argc, types, is_dynamic);
+
+ return &geninst->byval_arg;
}
-MonoType*
-mono_class_bind_generic_parameters (MonoType *type, int type_argc, MonoType **types)
+MonoClass*
+mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic)
{
- MonoClass *klass;
- MonoGenericClass *gclass, *cached;
- MonoType *geninst;
+ MonoGenericClass *gclass;
+ MonoGenericInst *inst;
int i;
- klass = mono_class_from_mono_type (type);
- if (!klass->generic_container && !klass->generic_class &&
- !(klass->nested_in && klass->nested_in->generic_container))
- return NULL;
-
- mono_loader_lock ();
-
- gclass = g_new0 (MonoGenericClass, 1);
+ g_assert (klass->generic_container);
- gclass->inst = g_new0 (MonoGenericInst, 1);
- gclass->inst->type_argc = type_argc;
- gclass->inst->type_argv = g_new0 (MonoType *, gclass->inst->type_argc);
- gclass->inst->is_reference = 1;
+ inst = g_new0 (MonoGenericInst, 1);
+ inst->type_argc = type_argc;
+ inst->type_argv = g_new0 (MonoType *, inst->type_argc);
- for (i = 0; i < gclass->inst->type_argc; ++i) {
+ for (i = 0; i < inst->type_argc; ++i) {
MonoType *t = dup_type (types [i]);
- if (!gclass->inst->is_open)
- gclass->inst->is_open = mono_class_is_open_constructed_type (t);
- if (gclass->inst->is_reference)
- gclass->inst->is_reference = MONO_TYPE_IS_REFERENCE (t);
-
- gclass->inst->type_argv [i] = t;
- }
-
- gclass->inst = mono_metadata_lookup_generic_inst (gclass->inst);
-
- gclass->container_class = klass;
-
- if (klass->generic_class) {
- MonoGenericClass *kgclass = klass->generic_class;
- MonoGenericClass *ogclass = gclass;
-
- gclass = g_new0 (MonoGenericClass, 1);
-
- gclass->inst = g_new0 (MonoGenericInst, 1);
- gclass->inst->type_argc = kgclass->inst->type_argc;
- gclass->inst->type_argv = g_new0 (MonoType *, gclass->inst->type_argc);
- gclass->inst->is_reference = 1;
-
- for (i = 0; i < gclass->inst->type_argc; i++) {
- MonoType *t = kgclass->inst->type_argv [i];
-
- t = mono_class_inflate_generic_type (t, mono_generic_class_get_context (ogclass));
-
- if (!gclass->inst->is_open)
- gclass->inst->is_open = mono_class_is_open_constructed_type (t);
- if (gclass->inst->is_reference)
- gclass->inst->is_reference = MONO_TYPE_IS_REFERENCE (t);
-
- gclass->inst->type_argv [i] = t;
- }
-
- gclass->inst = mono_metadata_lookup_generic_inst (gclass->inst);
-
- gclass->container_class = kgclass->container_class;
- }
-
- geninst = g_new0 (MonoType, 1);
- geninst->type = MONO_TYPE_GENERICINST;
+ if (!inst->is_open)
+ inst->is_open = mono_class_is_open_constructed_type (t);
- cached = mono_metadata_lookup_generic_class (gclass);
- if (cached) {
- g_free (gclass);
- mono_loader_unlock ();
- geninst->data.generic_class = cached;
- return geninst;
+ inst->type_argv [i] = t;
}
- geninst->data.generic_class = gclass;
+ inst = mono_metadata_lookup_generic_inst (inst);
+ gclass = mono_metadata_lookup_generic_class (klass, inst, is_dynamic);
- mono_loader_unlock ();
-
- return geninst;
+ return mono_generic_class_get_class (gclass);
}
static inline MonoType*
MonoReflectionMethod*
mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *rmethod, MonoArray *types)
{
+ MonoClass *klass;
MonoMethod *method, *inflated;
+ MonoMethodInflated *imethod;
MonoReflectionMethodBuilder *mb = NULL;
MonoGenericContainer *container;
- MonoGenericMethod *gmethod;
- MonoGenericContext *context;
+ MonoGenericContext tmp_context;
MonoGenericInst *ginst;
int count, i;
method = rmethod->method;
}
- method = mono_get_inflated_method (method);
+ klass = method->klass;
+
+ if (method->is_inflated)
+ method = ((MonoMethodInflated *) method)->declaring;
count = mono_method_signature (method)->generic_param_count;
if (count != mono_array_length (types))
if (!container->method_hash)
container->method_hash = g_hash_table_new (
- (GHashFunc) mono_metadata_generic_method_hash,
- (GCompareFunc) mono_metadata_generic_method_equal);
+ (GHashFunc) mono_metadata_generic_context_hash,
+ (GCompareFunc) mono_metadata_generic_context_equal);
ginst = g_new0 (MonoGenericInst,1 );
ginst->type_argc = count;
ginst->type_argv = g_new0 (MonoType *, count);
- ginst->is_reference = 1;
for (i = 0; i < count; i++) {
MonoReflectionType *garg = mono_array_get (types, gpointer, i);
ginst->type_argv [i] = dup_type (garg->type);
if (!ginst->is_open)
ginst->is_open = mono_class_is_open_constructed_type (ginst->type_argv [i]);
- if (ginst->is_reference)
- ginst->is_reference = MONO_TYPE_IS_REFERENCE (ginst->type_argv [i]);
}
ginst = mono_metadata_lookup_generic_inst (ginst);
- gmethod = g_new0 (MonoGenericMethod, 1);
- if (method->klass->generic_class)
- gmethod->class_inst = method->klass->generic_class->inst;
- gmethod->container = container;
- gmethod->inst = ginst;
-
- inflated = g_hash_table_lookup (container->method_hash, gmethod);
- if (inflated) {
- g_free (gmethod);
+ tmp_context.class_inst = klass->generic_class ? klass->generic_class->context.class_inst : NULL;
+ tmp_context.method_inst = ginst;
+ inflated = g_hash_table_lookup (container->method_hash, &tmp_context);
+ if (inflated)
return mono_method_get_object (mono_object_domain (rmethod), inflated, NULL);
- }
-
- MOVING_GC_REGISTER (&gmethod->reflection_info);
- gmethod->reflection_info = rmethod;
- context = g_new0 (MonoGenericContext, 1);
- context->class_inst = gmethod->class_inst;
- context->gmethod = gmethod;
+ inflated = mono_class_inflate_generic_method (method, &tmp_context);
+ imethod = (MonoMethodInflated *) inflated;
- if (method->is_inflated)
- method = ((MonoMethodInflated *) method)->declaring;
+ MOVING_GC_REGISTER (&imethod->reflection_info);
+ imethod->reflection_info = rmethod;
- inflated = mono_class_inflate_generic_method (method, context);
- g_hash_table_insert (container->method_hash, gmethod, inflated);
+ g_hash_table_insert (container->method_hash, mono_method_get_context (inflated), inflated);
return mono_method_get_object (mono_object_domain (rmethod), inflated, NULL);
}
static MonoMethod *
inflate_mono_method (MonoReflectionGenericClass *type, MonoMethod *method, MonoObject *obj)
{
- MonoGenericMethod *gmethod = NULL;
+ MonoMethodInflated *imethod;
+ MonoGenericContext tmp_context;
MonoGenericContext *context;
MonoClass *klass;
if (method->generic_container) {
g_assert (method->klass == klass->generic_class->container_class);
- gmethod = g_new0 (MonoGenericMethod, 1);
- gmethod->class_inst = klass->generic_class->inst;
- gmethod->container = method->generic_container;
- MOVING_GC_REGISTER (&gmethod->reflection_info);
- gmethod->reflection_info = obj;
- gmethod->inst = method->generic_container->context.gmethod->inst;
-
- context = g_new0 (MonoGenericContext, 1);
- context->class_inst = klass->generic_class->inst;
- context->gmethod = gmethod;
+ tmp_context.class_inst = klass->generic_class->context.class_inst;
+ tmp_context.method_inst = method->generic_container->context.method_inst;
+ context = &tmp_context;
}
- return mono_class_inflate_generic_method_full (method, klass, context);
+ imethod = (MonoMethodInflated *) mono_class_inflate_generic_method_full (method, klass, context);
+ if (method->generic_container) {
+ MOVING_GC_REGISTER (&imethod->reflection_info);
+ imethod->reflection_info = obj;
+ }
+ return (MonoMethod *) imethod;
}
static MonoMethod *
typebuilder_setup_properties (klass);
typebuilder_setup_events (klass);
-
+
klass->wastypebuilder = TRUE;
mono_loader_unlock ();
mono_domain_unlock (domain);
+ if (klass->enumtype && !mono_class_is_valid_enum (klass)) {
+ mono_class_set_failure (klass, MONO_EXCEPTION_TYPE_LOAD, NULL);
+ mono_raise_exception (mono_get_exception_type_load (tb->name, NULL));
+ }
+
res = mono_type_get_object (mono_object_domain (tb), &klass->byval_arg);
g_assert (res != (MonoReflectionType*)tb);
{
MonoDynamicImage *assembly = sig->module->dynamic_image;
guint32 na = mono_array_length (sig->arguments);
- guint32 buflen, i, size;
+ guint32 buflen, i;
MonoArray *result;
- char *buf, *p;
-
- MONO_ARCH_SAVE_REGS;
+ SigBuffer buf;
- p = buf = g_malloc (size = 50 + na * 50);
+ sigbuffer_init (&buf, 32);
- mono_metadata_encode_value (0x07, p, &p);
- mono_metadata_encode_value (na, p, &p);
+ sigbuffer_add_value (&buf, 0x07);
+ sigbuffer_add_value (&buf, na);
for (i = 0; i < na; ++i) {
MonoReflectionType *type = mono_array_get (sig->arguments, MonoReflectionType *, i);
- encode_reflection_type (assembly, type, p, &p);
+ encode_reflection_type (assembly, type, &buf);
}
- buflen = p - buf;
- g_assert (buflen < size);
+ buflen = buf.p - buf.buf;
result = mono_array_new (mono_domain_get (), mono_defaults.byte_class, buflen);
- p = mono_array_addr (result, char, 0);
- memcpy (p, buf, buflen);
- g_free (buf);
+ memcpy (mono_array_addr (result, char, 0), buf.buf, buflen);
+ sigbuffer_free (&buf);
return result;
}
{
MonoDynamicImage *assembly = sig->module->dynamic_image;
guint32 na = mono_array_length (sig->arguments);
- guint32 buflen, i, size;
+ guint32 buflen, i;
MonoArray *result;
- char *buf, *p;
+ SigBuffer buf;
- MONO_ARCH_SAVE_REGS;
-
- p = buf = g_malloc (size = 10 + na * 10);
+ sigbuffer_init (&buf, 32);
- mono_metadata_encode_value (0x06, p, &p);
+ sigbuffer_add_value (&buf, 0x06);
for (i = 0; i < na; ++i) {
MonoReflectionType *type = mono_array_get (sig->arguments, MonoReflectionType *, i);
- encode_reflection_type (assembly, type, p, &p);
+ encode_reflection_type (assembly, type, &buf);
}
- buflen = p - buf;
- g_assert (buflen < size);
+ buflen = buf.p - buf.buf;
result = mono_array_new (mono_domain_get (), mono_defaults.byte_class, buflen);
- p = mono_array_addr (result, char, 0);
- memcpy (p, buf, buflen);
- g_free (buf);
+ memcpy (mono_array_addr (result, char, 0), buf.buf, buflen);
+ sigbuffer_free (&buf);
return result;
}
{
ReflectionMethodBuilder rmb;
MonoMethodSignature *sig;
+ GSList *l;
int i;
sig = dynamic_method_to_signature (mb);
rmb.refs = g_new0 (gpointer, mb->nrefs + 1);
for (i = 0; i < mb->nrefs; i += 2) {
MonoClass *handle_class;
- gpointer ref = resolve_object (mb->module->image,
- mono_array_get (mb->refs, MonoObject*, i), &handle_class);
- if (!ref) {
- g_free (rmb.refs);
- mono_raise_exception (mono_get_exception_type_load (NULL, NULL));
- return;
+ gpointer ref;
+ MonoObject *obj = mono_array_get (mb->refs, MonoObject*, i);
+
+ if (strcmp (obj->vtable->klass->name, "DynamicMethod") == 0) {
+ MonoReflectionDynamicMethod *method = (MonoReflectionDynamicMethod*)obj;
+ /*
+ * The referenced DynamicMethod should already be created by the managed
+ * code, except in the case of circular references. In that case, we store
+ * method in the refs array, and fix it up later when the referenced
+ * DynamicMethod is created.
+ */
+ if (method->mhandle) {
+ ref = method->mhandle;
+ } else {
+ /* FIXME: GC object stored in unmanaged memory */
+ ref = method;
+
+ /* FIXME: GC object stored in unmanaged memory */
+ method->referenced_by = g_slist_append (method->referenced_by, mb);
+ }
+ handle_class = mono_defaults.methodhandle_class;
+ } else {
+ ref = resolve_object (mb->module->image, obj, &handle_class);
+ if (!ref) {
+ g_free (rmb.refs);
+ mono_raise_exception (mono_get_exception_type_load (NULL, NULL));
+ return;
+ }
}
+
rmb.refs [i] = ref; /* FIXME: GC object stored in unmanaged memory (change also resolve_object() signature) */
rmb.refs [i + 1] = handle_class;
}
/* FIXME: class */
mb->mhandle = reflection_methodbuilder_to_mono_method (mono_defaults.object_class, &rmb, sig);
+ /* Fix up refs entries pointing at us */
+ for (l = mb->referenced_by; l; l = l->next) {
+ MonoReflectionDynamicMethod *method = (MonoReflectionDynamicMethod*)l->data;
+ MonoMethodWrapper *wrapper = (MonoMethodWrapper*)method->mhandle;
+ gpointer *data;
+
+ g_assert (method->mhandle);
+
+ data = (gpointer*)wrapper->method_data;
+ for (i = 0; i < GPOINTER_TO_UINT (data [0]); i += 2) {
+ if ((data [i + 1] == mb) && (data [i + 1 + 1] == mono_defaults.methodhandle_class))
+ data [i + 1] = mb->mhandle;
+ }
+ }
+ g_slist_free (mb->referenced_by);
+
g_free (rmb.refs);
/* ilgen is no longer needed */
mb->ilgen = NULL;
}
+void
+mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb)
+{
+ g_assert (mb);
+
+ if (mb->mhandle)
+ mono_runtime_free_method (
+ mono_object_get_domain ((MonoObject*)mb), mb->mhandle);
+}
+
/**
* mono_reflection_lookup_dynamic_token:
*
static guint32
mono_declsec_get_flags (MonoImage *image, guint32 token)
{
- guint32 index = mono_metadata_declsec_from_index (image, token);
+ int index = mono_metadata_declsec_from_index (image, token);
MonoTableInfo *t = &image->tables [MONO_TABLE_DECLSECURITY];
guint32 result = 0;
guint32 action;
int i;
+ /* HasSecurity can be present for other, not specially encoded, attributes,
+ e.g. SuppressUnmanagedCodeSecurityAttribute */
+ if (index < 0)
+ return 0;
+
for (i = index; i < t->rows; i++) {
guint32 cols [MONO_DECL_SECURITY_SIZE];