Author: zoltan
Date: 2006-09-17 11:08:21 -0400 (Sun, 17 Sep 2006)
New Revision: 65551

Modified:
   trunk/mono/mono/metadata/marshal.c
   trunk/mono/mono/metadata/marshal.h
Log:
2006-09-17  Zoltan Varga  <[EMAIL PROTECTED]>

        * marshal.c (mono_marshal_emit_native_wrapper): Add an 'image' 
argument, 
        indicating the image where custom marshaller types should be looked up.
        (mono_ftnptr_to_delegate): Use the image of the delegate type to look up
        custom marshallers, instead of corlib. Fixes #79425.


Modified: trunk/mono/mono/metadata/marshal.c
===================================================================
--- trunk/mono/mono/metadata/marshal.c  2006-09-17 14:45:58 UTC (rev 65550)
+++ trunk/mono/mono/metadata/marshal.c  2006-09-17 15:08:21 UTC (rev 65551)
@@ -150,7 +150,7 @@
 mono_marshal_set_last_error_windows (int error);
 
 static void
-mono_marshal_emit_native_wrapper (MonoMethodBuilder *mb, MonoMethodSignature 
*sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
+mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, 
MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, 
gpointer func);
 
 static void
 register_icall (gpointer func, const char *name, const char *sigstr, gboolean 
save)
@@ -560,7 +560,7 @@
                sig = mono_metadata_signature_dup (mono_method_signature 
(invoke));
                sig->hasthis = 0;
 
-               wrapper = mono_marshal_get_native_func_wrapper (sig, &piinfo, 
mspecs, ftn);
+               wrapper = mono_marshal_get_native_func_wrapper (klass->image, 
sig, &piinfo, mspecs, ftn);
 
                for (i = mono_method_signature (invoke)->param_count; i >= 0; 
i--)
                        if (mspecs [i])
@@ -2849,7 +2849,7 @@
 
        mspecs[0] = NULL;
 
-       mono_marshal_emit_native_wrapper(mb_native, sig_native, piinfo, mspecs, 
piinfo->addr);
+       mono_marshal_emit_native_wrapper(mono_defaults.corlib, mb_native, 
sig_native, piinfo, mspecs, piinfo->addr);
 
        mono_loader_lock ();
        mono_marshal_lock ();
@@ -4975,6 +4975,7 @@
        int retobj_var;
        MonoClass *retobj_class;
        MonoMethodSignature *csig; /* Might need to be changed due to MarshalAs 
directives */
+       MonoImage *image; /* The image to use for looking up custom marshallers 
*/
 } EmitMarshalContext;
 
 typedef enum {
@@ -5018,7 +5019,7 @@
                g_assert (marshal_native_to_managed);
        }
 
-       mtype = mono_reflection_type_from_name 
(spec->data.custom_data.custom_name, mb->method->klass->image);
+       mtype = mono_reflection_type_from_name 
(spec->data.custom_data.custom_name, m->image);
        g_assert (mtype != NULL);
        mklass = mono_class_from_mono_type (mtype);
        g_assert (mklass != NULL);
@@ -7101,6 +7102,7 @@
 
 /**
  * mono_marshal_emit_native_wrapper:
+ * @image: the image to use for looking up custom marshallers
  * @sig: The signature of the native function
  * @piinfo: Marshalling information
  * @mspecs: Marshalling information
@@ -7109,7 +7111,7 @@
  * generates IL code for the pinvoke wrapper, the generated code calls @func.
  */
 static void
-mono_marshal_emit_native_wrapper (MonoMethodBuilder *mb, MonoMethodSignature 
*sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func)
+mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, 
MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, 
gpointer func)
 {
        EmitMarshalContext m;
        MonoMethodSignature *csig;
@@ -7125,6 +7127,7 @@
        csig = signature_dup (mb->method->klass->image, sig);
        csig->pinvoke = 1;
        m.csig = csig;
+       m.image = image;
 
        /* we allocate local for use with emit_struct_conv() */
        /* allocate local 0 (pointer) src_ptr */
@@ -7425,7 +7428,7 @@
        mspecs = g_new (MonoMarshalSpec*, sig->param_count + 1);
        mono_method_get_marshal_info (method, mspecs);
 
-       mono_marshal_emit_native_wrapper (mb, sig, piinfo, mspecs, 
piinfo->addr);
+       mono_marshal_emit_native_wrapper (mb->method->klass->image, mb, sig, 
piinfo, mspecs, piinfo->addr);
 
        csig = signature_dup (method->klass->image, sig);
        csig->pinvoke = 0;
@@ -7445,6 +7448,7 @@
 
 /**
  * mono_marshal_get_native_func_wrapper:
+ * @image: The image to use for memory allocation and for looking up custom 
marshallers.
  * @sig: The signature of the function
  * @func: The native function to wrap
  *
@@ -7452,7 +7456,7 @@
  * wrapper.
  */
 MonoMethod *
-mono_marshal_get_native_func_wrapper (MonoMethodSignature *sig, 
+mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature 
*sig, 
                                                                          
MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func)
 {
        MonoMethodSignature *csig;
@@ -7462,7 +7466,7 @@
        GHashTable *cache;
        char *name;
 
-       cache = mono_defaults.corlib->native_wrapper_cache;
+       cache = image->native_wrapper_cache;
        if ((res = mono_marshal_find_in_cache (cache, func)))
                return res;
 
@@ -7470,9 +7474,9 @@
        mb = mono_mb_new (mono_defaults.object_class, name, 
MONO_WRAPPER_MANAGED_TO_NATIVE);
        mb->method->save_lmf = 1;
 
-       mono_marshal_emit_native_wrapper (mb, sig, piinfo, mspecs, func);
+       mono_marshal_emit_native_wrapper (image, mb, sig, piinfo, mspecs, func);
 
-       csig = signature_dup (mb->method->klass->image, sig);
+       csig = signature_dup (image, sig);
        csig->pinvoke = 0;
        res = mono_mb_create_and_cache (cache, func,
                                                                        mb, 
csig, csig->param_count + 16);
@@ -7546,6 +7550,7 @@
        m.piinfo = NULL;
        m.retobj_var = 0;
        m.csig = csig;
+       m.image = method->klass->image;
 
 #ifdef PLATFORM_WIN32
        /* 

Modified: trunk/mono/mono/metadata/marshal.h
===================================================================
--- trunk/mono/mono/metadata/marshal.h  2006-09-17 14:45:58 UTC (rev 65550)
+++ trunk/mono/mono/metadata/marshal.h  2006-09-17 15:08:21 UTC (rev 65551)
@@ -212,7 +212,7 @@
 mono_marshal_get_native_wrapper (MonoMethod *method);
 
 MonoMethod *
-mono_marshal_get_native_func_wrapper (MonoMethodSignature *sig, 
MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
+mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature 
*sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
 
 MonoMethod *
 mono_marshal_get_struct_to_ptr (MonoClass *klass);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to