Remove all internal usages of mono_custom_attrs_construct and replace with mono_custom_attrs_construct_by_type
that takes a MonoError.
Introduce mono_custom_attrs_get_attr_checked and replace usage of the old one where it's needed.
threadpool-internals.h \
verify.c \
verify-internals.h \
- wrapper-types.h
+ wrapper-types.h \
+ reflection-internals.h
# These source files have compile time dependencies on GC code
gc_dependent_sources = \
#include "metadata/tabledefs.h"
#include "metadata/exception.h"
#include "metadata/appdomain.h"
+#include "metadata/reflection-internals.h"
#include "mono/metadata/debug-helpers.h"
#include "mono/metadata/threadpool.h"
#include "mono/metadata/threads.h"
interface_type_attribute = mono_class_from_name (mono_defaults.corlib, "System.Runtime.InteropServices", "InterfaceTypeAttribute");
cinfo = mono_custom_attrs_from_class (klass);
if (cinfo) {
- itf_attr = (MonoInterfaceTypeAttribute*)mono_custom_attrs_get_attr (cinfo, interface_type_attribute);
+ MonoError error;
+ itf_attr = (MonoInterfaceTypeAttribute*)mono_custom_attrs_get_attr_checked (cinfo, interface_type_attribute, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/
if (!cinfo->cached)
mono_custom_attrs_free (cinfo);
}
cinfo = mono_custom_attrs_from_class (klass);
if (cinfo) {
- MonoReflectionGuidAttribute *attr = (MonoReflectionGuidAttribute*)mono_custom_attrs_get_attr (cinfo, GuidAttribute);
+ MonoError error;
+ MonoReflectionGuidAttribute *attr = (MonoReflectionGuidAttribute*)mono_custom_attrs_get_attr_checked (cinfo, GuidAttribute, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/
if (!attr)
return FALSE;
cinfo = mono_custom_attrs_from_class (klass);
if (cinfo) {
- MonoReflectionComVisibleAttribute *attr = (MonoReflectionComVisibleAttribute*)mono_custom_attrs_get_attr (cinfo, ComVisibleAttribute);
+ MonoError error;
+ MonoReflectionComVisibleAttribute *attr = (MonoReflectionComVisibleAttribute*)mono_custom_attrs_get_attr_checked (cinfo, ComVisibleAttribute, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/
if (attr)
visible = attr->visible;
if (method) {
cinfo = mono_custom_attrs_from_method (method);
if (cinfo) {
- MonoObject *result = mono_custom_attrs_get_attr (cinfo, ComDispIdAttribute);
+ MonoError error;
+ MonoObject *result = mono_custom_attrs_get_attr_checked (cinfo, ComDispIdAttribute, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/;
if (result)
rgDispId[i] = *(gint32*)mono_object_unbox (result);
#include "mono/metadata/attrdefs.h"
#include "mono/metadata/gc-internal.h"
#include "mono/metadata/cominterop.h"
+#include "mono/metadata/reflection-internals.h"
#include "mono/utils/mono-counters.h"
#include "mono/utils/mono-tls.h"
#include "mono/utils/mono-memory-model.h"
*/
cinfo = mono_custom_attrs_from_class (klass);
if (cinfo && !mono_runtime_get_no_exec ()) {
- attr = (MonoReflectionUnmanagedFunctionPointerAttribute*)mono_custom_attrs_get_attr (cinfo, UnmanagedFunctionPointerAttribute);
+ MonoError error;
+ attr = (MonoReflectionUnmanagedFunctionPointerAttribute*)mono_custom_attrs_get_attr_checked (cinfo, UnmanagedFunctionPointerAttribute, &error);
if (attr) {
piinfo->piflags = (attr->call_conv << 8) | (attr->charset ? (attr->charset - 1) * 2 : 1) | attr->set_last_error;
+ } else {
+ if (!mono_error_ok (&error)) {
+ g_warning ("Could not load UnmanagedFunctionPointerAttribute due to %s", mono_error_get_message (&error));
+ mono_error_cleanup (&error);
+ }
}
if (!cinfo->cached)
mono_custom_attrs_free (cinfo);
--- /dev/null
+/*
+ * Copyright 2014 Xamarin Inc
+ */
+#ifndef __MONO_METADATA_REFLECTION_INTERBALS_H__
+#define __MONO_METADATA_REFLECTION_INTERBALS_H__
+
+#include <mono/metadata/reflection.h>
+#include <mono/utils/mono-compiler.h>
+#include <mono/utils/mono-error.h>
+
+MonoObject*
+mono_custom_attrs_get_attr_checked (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass, MonoError *error) MONO_INTERNAL;
+
+#endif
\ No newline at end of file
#include <config.h>
#include "mono/utils/mono-digest.h"
#include "mono/utils/mono-membar.h"
-#include "mono/metadata/reflection.h"
+#include "mono/metadata/reflection-internals.h"
#include "mono/metadata/tabledefs.h"
#include "mono/metadata/metadata-internals.h"
#include <mono/metadata/profiler-private.h>
mono_custom_attrs_construct (MonoCustomAttrInfo *cinfo)
{
MonoError error;
+ MonoArray *result = mono_custom_attrs_construct_by_type (cinfo, NULL, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/
- return mono_custom_attrs_construct_by_type (cinfo, NULL, &error);
+ return result;
}
static MonoArray*
MonoObject*
mono_custom_attrs_get_attr (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass)
+{
+ MonoError error;
+ MonoObject *res = mono_custom_attrs_get_attr_checked (ainfo, attr_klass, &error);
+ g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/
+ return res;
+}
+
+MonoObject*
+mono_custom_attrs_get_attr_checked (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass, MonoError *error)
{
int i, attr_index;
MonoClass *klass;
MonoArray *attrs;
+ mono_error_init (error);
+
attr_index = -1;
for (i = 0; i < ainfo->num_attrs; ++i) {
klass = ainfo->attrs [i].ctor->klass;
if (attr_index == -1)
return NULL;
- attrs = mono_custom_attrs_construct (ainfo);
- if (attrs)
- return mono_array_get (attrs, MonoObject*, attr_index);
- else
+ 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);
}
/*