2007-05-25 Jonathan Chambers <joncham@gmail.com>
authorJonathan Chambers <joncham@gmail.com>
Fri, 25 May 2007 20:55:14 +0000 (20:55 -0000)
committerJonathan Chambers <joncham@gmail.com>
Fri, 25 May 2007 20:55:14 +0000 (20:55 -0000)
       * marshal.c: Fix interface lookup loops for
       cominterop_get_com_slot_for_method and
       cominterop_get_method_interface. Only need to lookup
       if type is a class, else use interface type method is on.

       Code is contributed under MIT/X11 license.

svn path=/trunk/mono/; revision=77973

mono/metadata/ChangeLog
mono/metadata/marshal.c

index f059d78419706d549d232fbbf4412df90f55202e..e98c694206cd0d81007d6c086180a9aba2d31cc0 100644 (file)
@@ -1,3 +1,12 @@
+2007-05-25  Jonathan Chambers  <joncham@gmail.com>
+
+       * marshal.c: Fix interface lookup loops for
+       cominterop_get_com_slot_for_method and 
+       cominterop_get_method_interface. Only need to lookup
+       if type is a class, else use interface type method is on.
+
+       Code is contributed under MIT/X11 license.
+
 2007-05-25  Sebastien Pouliot  <sebastien@ximian.com>
 
        * reflection.c: HasSecurity can be present even if no specially 
index afecc433cb9c60140d5e5f15574091771d26d65d..14b1d1bb85958c89652b712c06bafc9eb223fdf8 100644 (file)
@@ -416,27 +416,27 @@ static int
 cominterop_get_com_slot_for_method (MonoMethod* method)
 {
        guint32 slot = method->slot;
-       GPtrArray *ifaces;
-       MonoClass *ic = NULL;
-       int i;
+       MonoClass *ic = method->klass;
 
-       ifaces = mono_class_get_implemented_interfaces (method->klass);
-       if (ifaces) {
-               int offset;
-               for (i = 0; i < ifaces->len; ++i) {
-                       ic = g_ptr_array_index (ifaces, i);
-                       offset = mono_class_interface_offset (method->klass, ic);
-                       if (method->slot >= offset && method->slot < offset + ic->method.count) {
-                               slot -= offset;
-                               break;
+       /* if method is on a class, we need to look up interface method exists on */
+       if (!MONO_CLASS_IS_INTERFACE(method->klass)) {
+               GPtrArray *ifaces = mono_class_get_implemented_interfaces (method->klass);
+               if (ifaces) {
+                       int i;
+                       for (i = 0; i < ifaces->len; ++i) {
+                               int offset;
+                               ic = g_ptr_array_index (ifaces, i);
+                               offset = mono_class_interface_offset (method->klass, ic);
+                               if (method->slot >= offset && method->slot < offset + ic->method.count) {
+                                       slot -= offset;
+                                       break;
+                               }
+                               ic = NULL;
                        }
+                       g_ptr_array_free (ifaces, TRUE);
                }
-               g_ptr_array_free (ifaces, TRUE);
        }
 
-       if (!ic)
-               ic = method->klass;
-       
        g_assert (ic);
        g_assert (MONO_CLASS_IS_INTERFACE (ic));
 
@@ -452,28 +452,27 @@ cominterop_get_com_slot_for_method (MonoMethod* method)
 static MonoReflectionType*
 cominterop_get_method_interface (MonoMethod* method)
 {
-       GPtrArray *ifaces;
        MonoType* t = NULL;
-       MonoClass *ic = NULL;
-       int i;
        MonoReflectionType* rt = NULL;
+       MonoClass *ic = method->klass;
 
-       ifaces = mono_class_get_implemented_interfaces (method->klass);
-       if (ifaces) {
-               int offset;
-               for (i = 0; i < ifaces->len; ++i) {
-                       ic = g_ptr_array_index (ifaces, i);
-                       offset = mono_class_interface_offset (method->klass, ic);
-                       if (method->slot >= offset && method->slot < offset + ic->method.count)
-                               break;
-                       ic = NULL;
+       /* if method is on a class, we need to look up interface method exists on */
+       if (!MONO_CLASS_IS_INTERFACE(method->klass)) {
+               GPtrArray *ifaces = mono_class_get_implemented_interfaces (method->klass);
+               if (ifaces) {
+                       int i;
+                       for (i = 0; i < ifaces->len; ++i) {
+                               int offset;
+                               ic = g_ptr_array_index (ifaces, i);
+                               offset = mono_class_interface_offset (method->klass, ic);
+                               if (method->slot >= offset && method->slot < offset + ic->method.count)
+                                       break;
+                               ic = NULL;
+                       }
+                       g_ptr_array_free (ifaces, TRUE);
                }
-               g_ptr_array_free (ifaces, TRUE);
        }
 
-       if (!ic)
-               ic = method->klass;
-
        g_assert (ic);
        g_assert (MONO_CLASS_IS_INTERFACE (ic));