[runtime] Call error_init instead of mono_error_init (#4425)
[mono.git] / mono / metadata / custom-attrs.c
index 46c8ba4f1640831814a2583aed99009b32776a8a..889315f06531e409d02ea705a7726a96a9de430e 100644 (file)
@@ -39,8 +39,8 @@
 
 static gboolean type_is_reference (MonoType *type);
 
-static GENERATE_GET_CLASS_WITH_CACHE (custom_attribute_typed_argument, System.Reflection, CustomAttributeTypedArgument);
-static GENERATE_GET_CLASS_WITH_CACHE (custom_attribute_named_argument, System.Reflection, CustomAttributeNamedArgument);
+static GENERATE_GET_CLASS_WITH_CACHE (custom_attribute_typed_argument, "System.Reflection", "CustomAttributeTypedArgument");
+static GENERATE_GET_CLASS_WITH_CACHE (custom_attribute_named_argument, "System.Reflection", "CustomAttributeNamedArgument");
 
 /*
  * LOCKING: Acquires the loader lock. 
@@ -187,7 +187,7 @@ load_cattr_enum_type (MonoImage *image, const char *p, const char **end, MonoErr
        MonoType *t;
        int slen = mono_metadata_decode_value (p, &p);
 
-       mono_error_init (error);
+       error_init (error);
 
        n = (char *)g_memdup (p, slen + 1);
        n [slen] = 0;
@@ -205,7 +205,7 @@ load_cattr_value (MonoImage *image, MonoType *t, const char *p, const char **end
        int slen, type = t->type;
        MonoClass *tklass = t->data.klass;
 
-       mono_error_init (error);
+       error_init (error);
 
 handle_enum:
        switch (type) {
@@ -447,7 +447,7 @@ handle_type:
 static MonoObject*
 load_cattr_value_boxed (MonoDomain *domain, MonoImage *image, MonoType *t, const char* p, const char** end, MonoError *error)
 {
-       mono_error_init (error);
+       error_init (error);
 
        gboolean is_ref = type_is_reference (t);
 
@@ -473,7 +473,7 @@ create_cattr_typed_arg (MonoType *t, MonoObject *val, MonoError *error)
        MonoObject *retval;
        void *params [2], *unboxed;
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!ctor)
                ctor = mono_class_get_method_from_name (mono_class_get_custom_attribute_typed_argument_class (), ".ctor", 2);
@@ -499,7 +499,7 @@ create_cattr_named_arg (void *minfo, MonoObject *typedarg, MonoError *error)
        MonoObject *retval;
        void *unboxed, *params [2];
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!ctor)
                ctor = mono_class_get_method_from_name (mono_class_get_custom_attribute_named_argument_class (), ".ctor", 2);
@@ -578,7 +578,7 @@ create_custom_attr (MonoImage *image, MonoMethod *method, const guchar *data, gu
        void **params = NULL;
        MonoMethodSignature *sig;
 
-       mono_error_init (error);
+       error_init (error);
 
        mono_class_init (method->klass);
 
@@ -759,7 +759,7 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
        *named_args = NULL;
        *named_arg_info = NULL;
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!mono_verifier_verify_cattr_content (image, method, data, len, NULL)) {
                mono_error_set_generic_error (error, "System.Reflection", "CustomAttributeFormatException", "Binary format of the specified custom attribute was invalid.");
@@ -888,7 +888,7 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
        CattrNamedArg *arginfo = NULL;
        int i;
 
-       mono_error_init (error);
+       error_init (error);
 
        *ctor_args = NULL;
        *named_args = NULL;
@@ -962,16 +962,15 @@ ves_icall_System_Reflection_CustomAttributeData_ResolveArgumentsInternal (MonoRe
        mono_error_set_pending_exception (&error);
 }
 
-static MonoObject*
-create_custom_attr_data (MonoImage *image, MonoCustomAttrEntry *cattr, MonoError *error)
+static MonoObjectHandle
+create_custom_attr_data_handle (MonoImage *image, MonoCustomAttrEntry *cattr, MonoError *error)
 {
        static MonoMethod *ctor;
 
        MonoDomain *domain;
-       MonoObject *attr;
        void *params [4];
 
-       mono_error_init (error);
+       error_init (error);
 
        g_assert (image->assembly);
 
@@ -979,18 +978,34 @@ create_custom_attr_data (MonoImage *image, MonoCustomAttrEntry *cattr, MonoError
                ctor = mono_class_get_method_from_name (mono_defaults.customattribute_data_class, ".ctor", 4);
 
        domain = mono_domain_get ();
-       attr = mono_object_new_checked (domain, mono_defaults.customattribute_data_class, error);
-       return_val_if_nok (error, NULL);
-       params [0] = mono_method_get_object_checked (domain, cattr->ctor, NULL, error);
-       return_val_if_nok (error, NULL);
-       params [1] = mono_assembly_get_object_checked (domain, image->assembly, error);
-       return_val_if_nok (error, NULL);
+
+       MonoObjectHandle attr = MONO_HANDLE_NEW (MonoObject, mono_object_new_checked (domain, mono_defaults.customattribute_data_class, error));
+       if (!is_ok (error))
+               goto fail;
+
+       MonoReflectionMethod *ctor_obj = mono_method_get_object_checked (domain, cattr->ctor, NULL, error);
+       if (!is_ok (error))
+               goto fail;
+       MonoReflectionAssemblyHandle assm = mono_assembly_get_object_handle (domain, image->assembly, error);
+       if (!is_ok (error))
+               goto fail;
+       params [0] = ctor_obj;
+       params [1] = MONO_HANDLE_RAW (assm);
        params [2] = (gpointer)&cattr->data;
        params [3] = &cattr->data_size;
 
-       mono_runtime_invoke_checked (ctor, attr, params, error);
-       return_val_if_nok (error, NULL);
+       mono_runtime_invoke_checked (ctor, MONO_HANDLE_RAW (attr), params, error);
        return attr;
+fail:
+       return MONO_HANDLE_NEW (MonoObject, NULL);
+}
+
+static MonoObject *
+create_custom_attr_data (MonoImage *image, MonoCustomAttrEntry *cattr, MonoError *error)
+{
+       HANDLE_FUNCTION_ENTER ();
+       MonoObjectHandle obj = create_custom_attr_data_handle (image, cattr, error);
+       HANDLE_FUNCTION_RETURN_OBJ (obj);
 }
 
 static MonoArray*
@@ -1000,7 +1015,7 @@ mono_custom_attrs_construct_by_type (MonoCustomAttrInfo *cinfo, MonoClass *attr_
        MonoObject *attr;
        int i, n;
 
-       mono_error_init (error);
+       error_init (error);
 
        for (i = 0; i < cinfo->num_attrs; ++i) {
                MonoCustomAttrEntry *centry = &cinfo->attrs[i];
@@ -1057,7 +1072,7 @@ mono_custom_attrs_data_construct (MonoCustomAttrInfo *cinfo, MonoError *error)
        MonoObject *attr;
        int i;
        
-       mono_error_init (error);
+       error_init (error);
        result = mono_array_new_checked (mono_domain_get (), mono_defaults.customattribute_data_class, cinfo->num_attrs, error);
        return_val_if_nok (error, NULL);
        for (i = 0; i < cinfo->num_attrs; ++i) {
@@ -1097,7 +1112,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig
        const char *data;
        MonoCustomAttrEntry* attr;
 
-       mono_error_init (error);
+       error_init (error);
 
        ca = &image->tables [MONO_TABLE_CUSTOMATTRIBUTE];
 
@@ -1137,7 +1152,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig
                        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);
+                               error_init (error);
                        } else {
                                g_list_free (list);
                                g_free (ainfo);
@@ -1175,7 +1190,7 @@ mono_custom_attrs_from_method_checked (MonoMethod *method, MonoError *error)
 {
        guint32 idx;
 
-       mono_error_init (error);
+       error_init (error);
 
        /*
         * An instantiated method has the same cattrs as the generic method definition.
@@ -1213,7 +1228,7 @@ mono_custom_attrs_from_class_checked (MonoClass *klass, MonoError *error)
 {
        guint32 idx;
 
-       mono_error_init (error);
+       error_init (error);
 
        if (mono_class_is_ginst (klass))
                klass = mono_class_get_generic_class (klass)->container_class;
@@ -1247,7 +1262,7 @@ mono_custom_attrs_from_assembly_checked (MonoAssembly *assembly, gboolean ignore
 {
        guint32 idx;
        
-       mono_error_init (error);
+       error_init (error);
 
        if (image_is_dynamic (assembly->image))
                return lookup_custom_attr (assembly->image, assembly);
@@ -1331,7 +1346,7 @@ MonoCustomAttrInfo*
 mono_custom_attrs_from_field_checked (MonoClass *klass, MonoClassField *field, MonoError *error)
 {
        guint32 idx;
-       mono_error_init (error);
+       error_init (error);
 
        if (image_is_dynamic (klass->image)) {
                field = mono_metadata_get_corresponding_field_from_generic_type_definition (field);
@@ -1380,7 +1395,7 @@ mono_custom_attrs_from_param_checked (MonoMethod *method, guint32 param, MonoErr
        MonoImage *image;
        MonoReflectionMethodAux *aux;
 
-       mono_error_init (error);
+       error_init (error);
 
        /*
         * An instantiated method has the same cattrs as the generic method definition.
@@ -1471,7 +1486,7 @@ mono_custom_attrs_get_attr_checked (MonoCustomAttrInfo *ainfo, MonoClass *attr_k
 
        g_assert (attr_klass != NULL);
 
-       mono_error_init (error);
+       error_init (error);
 
        for (i = 0; i < ainfo->num_attrs; ++i) {
                centry = &ainfo->attrs[i];
@@ -1523,7 +1538,7 @@ mono_reflection_get_custom_attrs_info_checked (MonoObject *obj, MonoError *error
        MonoClass *klass;
        MonoCustomAttrInfo *cinfo = NULL;
        
-       mono_error_init (error);
+       error_init (error);
 
        klass = obj->vtable->klass;
        if (klass == mono_defaults.runtimetype_class) {
@@ -1635,7 +1650,7 @@ mono_reflection_get_custom_attrs_by_type (MonoObject *obj, MonoClass *attr_klass
        MonoArray *result;
        MonoCustomAttrInfo *cinfo;
 
-       mono_error_init (error);
+       error_init (error);
 
        cinfo = mono_reflection_get_custom_attrs_info_checked (obj, error);
        return_val_if_nok (error, NULL);
@@ -1701,7 +1716,7 @@ mono_reflection_get_custom_attrs_data_checked (MonoObject *obj, MonoError *error
        MonoArray *result;
        MonoCustomAttrInfo *cinfo;
 
-       mono_error_init (error);
+       error_init (error);
 
        cinfo = mono_reflection_get_custom_attrs_info_checked (obj, error);
        return_val_if_nok (error, NULL);