Merge pull request #2716 from BrzVlad/fix-tramp-jinfo
[mono.git] / mono / metadata / marshal.c
index 259e51ed02479622b5ca839d9876ada284c0ff7c..559ecc4cfe4fd1719890485054ac87c112628831 100644 (file)
@@ -450,6 +450,7 @@ mono_marshal_use_aot_wrappers (gboolean use)
 static void
 parse_unmanaged_function_pointer_attr (MonoClass *klass, MonoMethodPInvoke *piinfo)
 {
+       MonoError error;
        MonoCustomAttrInfo *cinfo;
        MonoReflectionUnmanagedFunctionPointerAttribute *attr;
 
@@ -459,9 +460,12 @@ parse_unmanaged_function_pointer_attr (MonoClass *klass, MonoMethodPInvoke *piin
                 * The pinvoke attributes are stored in a real custom attribute so we have to
                 * construct it.
                 */
-               cinfo = mono_custom_attrs_from_class (klass);
+               cinfo = mono_custom_attrs_from_class_checked (klass, &error);
+               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 && !mono_runtime_get_no_exec ()) {
-                       MonoError error;
                        attr = (MonoReflectionUnmanagedFunctionPointerAttribute*)mono_custom_attrs_get_attr_checked (cinfo, mono_class_try_get_unmanaged_function_pointer_attribute_class (), &error);
                        if (attr) {
                                piinfo->piflags = (attr->call_conv << 8) | (attr->charset ? (attr->charset - 1) * 2 : 1) | attr->set_last_error;
@@ -2147,6 +2151,7 @@ mono_marshal_emit_thread_force_interrupt_checkpoint (MonoMethodBuilder *mb)
 static MonoAsyncResult *
 mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params)
 {
+       MonoError error;
        MonoMulticastDelegate *mcast_delegate;
        MonoClass *klass;
        MonoMethod *method;
@@ -2181,7 +2186,11 @@ mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params)
                        msg->call_type = CallType_BeginInvoke;
 
                        exc = NULL;
-                       mono_remoting_invoke ((MonoObject *)tp->rp, msg, &exc, &out_args);
+                       mono_remoting_invoke ((MonoObject *)tp->rp, msg, &exc, &out_args, &error);
+                       if (!mono_error_ok (&error)) {
+                               mono_error_set_pending_exception (&error);
+                               return NULL;
+                       }
                        if (exc)
                                mono_set_pending_exception ((MonoException *) exc);
                        return ares;
@@ -2920,7 +2929,11 @@ mono_delegate_end_invoke (MonoDelegate *delegate, gpointer *params)
                mono_message_init (domain, msg, delegate->method_info, NULL);
                msg->call_type = CallType_EndInvoke;
                MONO_OBJECT_SETREF (msg, async_result, ares);
-               res = mono_remoting_invoke ((MonoObject *)tp->rp, msg, &exc, &out_args);
+               res = mono_remoting_invoke ((MonoObject *)tp->rp, msg, &exc, &out_args, &error);
+               if (!mono_error_ok (&error)) {
+                       mono_error_set_pending_exception (&error);
+                       return NULL;
+               }
        } else
 #endif
        {
@@ -3158,11 +3171,13 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt
        if (callvirt) {
                subtype = WRAPPER_SUBTYPE_DELEGATE_INVOKE_VIRTUAL;
                if (target_method->is_inflated) {
+                       MonoError error;
                        MonoType *target_type;
 
                        g_assert (method->signature->hasthis);
-                       target_type = mono_class_inflate_generic_type (method->signature->params [0],
-                               mono_method_get_context (method));
+                       target_type = mono_class_inflate_generic_type_checked (method->signature->params [0],
+                               mono_method_get_context (method), &error);
+                       mono_error_assert_ok (&error); /* FIXME don't swallow the error */
                        target_class = mono_class_from_mono_type (target_type);
                } else {
                        target_class = target_method->klass;
@@ -8122,6 +8137,7 @@ mono_marshal_set_callconv_from_modopt (MonoMethod *method, MonoMethodSignature *
 MonoMethod *
 mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t target_handle)
 {
+       MonoError error;
        MonoMethodSignature *sig, *csig, *invoke_sig;
        MonoMethodBuilder *mb;
        MonoMethod *res, *invoke;
@@ -8186,7 +8202,8 @@ mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass,
                 * contents of the attribute without constructing it, as that might not be
                 * possible when running in cross-compiling mode.
                 */
-               cinfo = mono_custom_attrs_from_class (delegate_klass);
+               cinfo = mono_custom_attrs_from_class_checked (delegate_klass, &error);
+               mono_error_assert_ok (&error);
                attr = NULL;
                if (cinfo) {
                        for (i = 0; i < cinfo->num_attrs; ++i) {