mono_custom_attrs_from_index (MonoImage *image, guint32 idx)
{
MonoError error;
- MonoCustomAttrInfo *result = mono_custom_attrs_from_index_checked (image, idx, &error);
+ MonoCustomAttrInfo *result = mono_custom_attrs_from_index_checked (image, idx, FALSE, &error);
mono_error_cleanup (&error);
return result;
}
* Returns: NULL if no attributes are found. On error returns NULL and sets @error.
*/
MonoCustomAttrInfo*
-mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, MonoError *error)
+mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ignore_missing, MonoError *error)
{
guint32 mtoken, i, len;
guint32 cols [MONO_CUSTOM_ATTR_SIZE];
attr = &ainfo->attrs [i - 1];
attr->ctor = mono_get_method_checked (image, mtoken, NULL, NULL, error);
if (!attr->ctor) {
- g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x due to %s", image->name, mtoken, mono_error_get_message (error));
- g_list_free (list);
- g_free (ainfo);
- return NULL;
+ g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x due to: %s", image->name, mtoken, mono_error_get_message (error));
+ if (ignore_missing) {
+ mono_error_cleanup (error);
+ mono_error_init (error);
+ } else {
+ g_list_free (list);
+ g_free (ainfo);
+ return NULL;
+ }
}
if (!mono_verifier_verify_cattr_blob (image, cols [MONO_CUSTOM_ATTR_VALUE], NULL)) {
idx = mono_method_get_index (method);
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_METHODDEF;
- return mono_custom_attrs_from_index_checked (method->klass->image, idx, error);
+ return mono_custom_attrs_from_index_checked (method->klass->image, idx, FALSE, error);
}
MonoCustomAttrInfo*
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_TYPEDEF;
}
- return mono_custom_attrs_from_index_checked (klass->image, idx, error);
+ return mono_custom_attrs_from_index_checked (klass->image, idx, FALSE, error);
}
MonoCustomAttrInfo*
mono_custom_attrs_from_assembly (MonoAssembly *assembly)
{
MonoError error;
- MonoCustomAttrInfo *result = mono_custom_attrs_from_assembly_checked (assembly, &error);
+ MonoCustomAttrInfo *result = mono_custom_attrs_from_assembly_checked (assembly, FALSE, &error);
mono_error_cleanup (&error);
return result;
}
MonoCustomAttrInfo*
-mono_custom_attrs_from_assembly_checked (MonoAssembly *assembly, MonoError *error)
+mono_custom_attrs_from_assembly_checked (MonoAssembly *assembly, gboolean ignore_missing, MonoError *error)
{
guint32 idx;
idx = 1; /* there is only one assembly */
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_ASSEMBLY;
- return mono_custom_attrs_from_index_checked (assembly->image, idx, error);
+ return mono_custom_attrs_from_index_checked (assembly->image, idx, ignore_missing, error);
}
static MonoCustomAttrInfo*
idx = 1; /* there is only one module */
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_MODULE;
- return mono_custom_attrs_from_index_checked (image, idx, error);
+ return mono_custom_attrs_from_index_checked (image, idx, FALSE, error);
}
MonoCustomAttrInfo*
idx = find_property_index (klass, property);
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_PROPERTY;
- return mono_custom_attrs_from_index_checked (klass->image, idx, error);
+ return mono_custom_attrs_from_index_checked (klass->image, idx, FALSE, error);
}
MonoCustomAttrInfo*
idx = find_event_index (klass, event);
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_EVENT;
- return mono_custom_attrs_from_index_checked (klass->image, idx, error);
+ return mono_custom_attrs_from_index_checked (klass->image, idx, FALSE, error);
}
MonoCustomAttrInfo*
idx = find_field_index (klass, field);
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_FIELDDEF;
- return mono_custom_attrs_from_index_checked (klass->image, idx, error);
+ return mono_custom_attrs_from_index_checked (klass->image, idx, FALSE, error);
}
/**
idx = i;
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_PARAMDEF;
- return mono_custom_attrs_from_index_checked (image, idx, error);
+ return mono_custom_attrs_from_index_checked (image, idx, FALSE, error);
}
gboolean
{
int i;
for (i = 0; i < ainfo->num_attrs; ++i) {
- MonoClass *klass = ainfo->attrs [i].ctor->klass;
- if (mono_class_has_parent (klass, attr_klass) || (MONO_CLASS_IS_INTERFACE (attr_klass) && mono_class_is_assignable_from (attr_klass, klass)))
+ MonoCustomAttrEntry *centry = &ainfo->attrs[i];
+ if (centry->ctor == NULL)
+ continue;
+ MonoClass *klass = centry->ctor->klass;
+ if (klass == attr_klass || mono_class_has_parent (klass, attr_klass) || (MONO_CLASS_IS_INTERFACE (attr_klass) && mono_class_is_assignable_from (attr_klass, klass)))
return TRUE;
}
return FALSE;
MonoObject*
mono_custom_attrs_get_attr_checked (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass, MonoError *error)
{
- int i, attr_index;
- MonoArray *attrs;
+ int i;
+ MonoCustomAttrEntry *centry = NULL;
+
+ g_assert (attr_klass != NULL);
mono_error_init (error);
- attr_index = -1;
for (i = 0; i < ainfo->num_attrs; ++i) {
- MonoClass *klass = ainfo->attrs [i].ctor->klass;
- if (mono_class_has_parent (klass, attr_klass)) {
- attr_index = i;
+ centry = &ainfo->attrs[i];
+ if (centry->ctor == NULL)
+ continue;
+ MonoClass *klass = centry->ctor->klass;
+ if (attr_klass == klass || mono_class_is_assignable_from (attr_klass, klass))
break;
- }
}
- if (attr_index == -1)
+ if (centry == NULL)
return NULL;
- attrs = mono_custom_attrs_construct_by_type (ainfo, NULL, error);
- if (!mono_error_ok (error))
- return NULL;
- return mono_array_get (attrs, MonoObject*, attr_index);
+ return create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, error);
}
/*
return_val_if_nok (error, NULL);
} else if (strcmp ("Assembly", klass->name) == 0 || strcmp ("MonoAssembly", klass->name) == 0) {
MonoReflectionAssembly *rassembly = (MonoReflectionAssembly*)obj;
- cinfo = mono_custom_attrs_from_assembly_checked (rassembly->assembly, error);
+ cinfo = mono_custom_attrs_from_assembly_checked (rassembly->assembly, FALSE, error);
return_val_if_nok (error, NULL);
} else if (strcmp ("Module", klass->name) == 0 || strcmp ("MonoModule", klass->name) == 0) {
MonoReflectionModule *module = (MonoReflectionModule*)obj;
MonoReflectionMethod *rmethod = (MonoReflectionMethod*)obj;
cinfo = mono_custom_attrs_from_method_checked (rmethod->method, error);
return_val_if_nok (error, NULL);
- } else if ((strcmp ("MonoGenericMethod", klass->name) == 0) || (strcmp ("MonoGenericCMethod", klass->name) == 0)) {
- MonoReflectionMethod *rmethod = (MonoReflectionMethod*)obj;
- cinfo = mono_custom_attrs_from_method_checked (rmethod->method, error);
- return_val_if_nok (error, NULL);
} else if (strcmp ("ParameterInfo", klass->name) == 0 || strcmp ("MonoParameterInfo", klass->name) == 0) {
MonoReflectionParameter *param = (MonoReflectionParameter*)obj;
MonoClass *member_class = mono_object_class (param->MemberImpl);
}
#ifndef DISABLE_REFLECTION_EMIT
else if (mono_is_sre_method_on_tb_inst (member_class)) {/*XXX This is a workaround for Compiler Context*/
- MonoMethod *method = mono_reflection_method_on_tb_inst_get_handle ((MonoReflectionMethodOnTypeBuilderInst*)param->MemberImpl, error);
- return_val_if_nok (error, NULL);
- cinfo = mono_custom_attrs_from_param_checked (method, param->PositionImpl + 1, error);
- return_val_if_nok (error, NULL);
+ // FIXME: Is this still needed ?
+ g_assert_not_reached ();
} else if (mono_is_sre_ctor_on_tb_inst (member_class)) { /*XX This is a workaround for Compiler Context*/
- MonoReflectionCtorOnTypeBuilderInst *c = (MonoReflectionCtorOnTypeBuilderInst*)param->MemberImpl;
- MonoMethod *method = NULL;
- if (mono_is_sre_ctor_builder (mono_object_class (c->cb)))
- method = ((MonoReflectionCtorBuilder *)c->cb)->mhandle;
- else if (mono_is_sr_mono_cmethod (mono_object_class (c->cb)))
- method = ((MonoReflectionMethod *)c->cb)->method;
- else
- g_error ("mono_reflection_get_custom_attrs_info:: can't handle a CTBI with base_method of type %s", mono_type_get_full_name (member_class));
-
- cinfo = mono_custom_attrs_from_param_checked (method, param->PositionImpl + 1, error);
- return_val_if_nok (error, NULL);
+ // FIXME: Is this still needed ?
+ g_assert_not_reached ();
}
#endif
else {