[class] Short circuit collect_implemented_interfaces_aux on gparams
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 20 Sep 2017 21:34:59 +0000 (17:34 -0400)
committerAleksey Kliger (λgeek) <akliger@gmail.com>
Mon, 25 Sep 2017 20:57:17 +0000 (16:57 -0400)
and also setup_interface_offsets.

A gparam is never a real interface so we can just short circuit
if we see a gparam during interface collection.  (A gparam may be instantiated
with an interface --- but ginst interface offsets are processed anew when the
ginst is initialized in mono_class_init, not somehow extracted from the gtd and
the MonoGenericContext).

mono/metadata/class.c

index f00d436281a5d0d1a05075f56870a49d37183875..f3e87fe6428f9296d921a09a1405f21ae87f235f 100644 (file)
@@ -2926,6 +2926,10 @@ collect_implemented_interfaces_aux (MonoClass *klass, GPtrArray **res, GHashTabl
                        *ifaces = g_hash_table_new (NULL, NULL);
                if (g_hash_table_lookup (*ifaces, ic))
                        continue;
+               /* A gparam is not an implemented interface for the purposes of
+                * mono_class_get_implemented_interfaces */
+               if (mono_class_is_gparam (ic))
+                       continue;
                g_ptr_array_add (*res, ic);
                g_hash_table_insert (*ifaces, ic, ic);
                mono_class_init (ic);
@@ -3316,7 +3320,9 @@ setup_interface_offsets (MonoClass *klass, int cur_slot, gboolean overwrite)
                for (i = 0; i < k->interface_count; i++) {
                        ic = k->interfaces [i];
 
-                       mono_class_init (ic);
+                       /* A gparam does not have any interface_id set. */
+                       if (! mono_class_is_gparam (ic))
+                               mono_class_init (ic);
 
                        if (max_iid < ic->interface_id)
                                max_iid = ic->interface_id;