Author: zoltan
Date: 2007-06-21 13:29:45 -0400 (Thu, 21 Jun 2007)
New Revision: 80497

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/icall-def.h
   trunk/mono/mono/metadata/object-internals.h
   trunk/mono/mono/metadata/reflection.c
Log:
2007-06-21  Zoltan Varga  <[EMAIL PROTECTED]>

        * object-internals.h reflection.c icall-def.h: Applied patch from Robert
        Jordan ([EMAIL PROTECTED]). Add a dtor to dynamic methods which frees 
up the
        runtime memory used by the dynamic method. Fixes #77146.


Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2007-06-21 16:33:35 UTC (rev 80496)
+++ trunk/mono/mono/metadata/ChangeLog  2007-06-21 17:29:45 UTC (rev 80497)
@@ -1,3 +1,9 @@
+2007-06-21  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * object-internals.h reflection.c icall-def.h: Applied patch from Robert
+       Jordan ([EMAIL PROTECTED]). Add a dtor to dynamic methods which frees 
up the
+       runtime memory used by the dynamic method. Fixes #77146.
+
 2007-06-21  Dick Porter  <[EMAIL PROTECTED]>
 
        * file-io.h: 

Modified: trunk/mono/mono/metadata/icall-def.h
===================================================================
--- trunk/mono/mono/metadata/icall-def.h        2007-06-21 16:33:35 UTC (rev 
80496)
+++ trunk/mono/mono/metadata/icall-def.h        2007-06-21 17:29:45 UTC (rev 
80497)
@@ -432,6 +432,7 @@
 
 ICALL_TYPE(DYNM, "System.Reflection.Emit.DynamicMethod", DYNM_1)
 ICALL(DYNM_1, "create_dynamic_method", mono_reflection_create_dynamic_method)
+ICALL(DYNM_2, "destroy_dynamic_method", mono_reflection_destroy_dynamic_method)
 
 ICALL_TYPE(ENUMB, "System.Reflection.Emit.EnumBuilder", ENUMB_1)
 ICALL(ENUMB_1, "setup_enum_type", ves_icall_EnumBuilder_setup_enum_type)

Modified: trunk/mono/mono/metadata/object-internals.h
===================================================================
--- trunk/mono/mono/metadata/object-internals.h 2007-06-21 16:33:35 UTC (rev 
80496)
+++ trunk/mono/mono/metadata/object-internals.h 2007-06-21 17:29:45 UTC (rev 
80497)
@@ -1072,6 +1072,7 @@
 void        mono_reflection_get_dynamic_overrides (MonoClass *klass, 
MonoMethod ***overrides, int *num_overrides) MONO_INTERNAL;
 
 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m) 
MONO_INTERNAL;
+void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb) 
MONO_INTERNAL;
 
 void        mono_reflection_initialize_generic_parameter 
(MonoReflectionGenericParam *gparam) MONO_INTERNAL;
 

Modified: trunk/mono/mono/metadata/reflection.c
===================================================================
--- trunk/mono/mono/metadata/reflection.c       2007-06-21 16:33:35 UTC (rev 
80496)
+++ trunk/mono/mono/metadata/reflection.c       2007-06-21 17:29:45 UTC (rev 
80497)
@@ -240,6 +240,21 @@
                return g_malloc0 (size);
 }
 
+/**
+ * mp_string_to_utf8:
+ *
+ * Allocate memory from the mempool MP if it is non-NULL. Otherwise, allocate
+ * memory from the C heap.
+ */
+static char *
+mp_string_to_utf8 (MonoMemPool *mp, MonoString *s)
+{
+       if (mp)
+               return mono_string_to_utf8_mp (mp, s);
+       else
+               return mono_string_to_utf8 (s);
+}
+
 #define mp_g_new(mp,struct_type, n_structs)            \
     ((struct_type *) mp_g_malloc (mp, ((gsize) sizeof (struct_type)) * 
((gsize) (n_structs))))
 
@@ -8420,10 +8435,11 @@
 
        pm = (MonoMethodNormal*)m;
 
+       m->dynamic = dynamic;
        m->slot = -1;
        m->flags = rmb->attrs;
        m->iflags = rmb->iattrs;
-       m->name = dynamic ? mono_string_to_utf8 (rmb->name) : 
mono_string_to_utf8_mp (mp, rmb->name);
+       m->name = mp_string_to_utf8 (mp, rmb->name);
        m->klass = klass;
        m->signature = sig;
        m->skip_visibility = rmb->skip_visibility;
@@ -8582,7 +8598,7 @@
                                }
 
                                if (pb->name)
-                                       method_aux->param_names [i] = dynamic ? 
mono_string_to_utf8 (pb->name) : mono_string_to_utf8_mp (mp, pb->name);
+                                       method_aux->param_names [i] = 
mp_string_to_utf8 (mp, pb->name);
                                if (pb->cattrs) {
                                        if (!method_aux->param_cattr)
                                                method_aux->param_cattr = 
mp_g_new0 (mp, MonoCustomAttrInfo*, m->signature->param_count + 1);
@@ -9559,6 +9575,16 @@
        mb->ilgen = NULL;
 }
 
+void
+mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb)
+{
+       g_assert (mb);
+
+       if (mb->mhandle)
+               mono_runtime_free_method (
+                       mono_object_get_domain ((MonoObject*)mb), mb->mhandle);
+}
+
 /**
  * mono_reflection_lookup_dynamic_token:
  *

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

Reply via email to