@@ -1572,8 +1572,57 @@ class TypeInfo_Delegate : TypeInfo
1572
1572
}
1573
1573
1574
1574
private extern (C) Object _d_newclass(const TypeInfo_Class ci);
1575
- private extern (C) int _d_isbaseof(scope TypeInfo_Class child,
1576
- scope const TypeInfo_Class parent) @nogc nothrow pure @safe ; // rt.cast_
1575
+
1576
+ extern (C ) int _d_isbaseof(scope ClassInfo oc, scope const ClassInfo c) @nogc nothrow pure @safe
1577
+ {
1578
+ import core.internal.cast_ : areClassInfosEqual;
1579
+
1580
+ if (areClassInfosEqual(oc, c))
1581
+ return true ;
1582
+
1583
+ do
1584
+ {
1585
+ if (oc.base && areClassInfosEqual(oc.base, c))
1586
+ return true ;
1587
+
1588
+ // Bugzilla 2013: Use depth-first search to calculate offset
1589
+ // from the derived (oc) to the base (c).
1590
+ foreach (iface; oc.interfaces)
1591
+ {
1592
+ if (areClassInfosEqual(iface.classinfo, c) || _d_isbaseof(iface.classinfo, c))
1593
+ return true ;
1594
+ }
1595
+
1596
+ oc = oc.base;
1597
+ } while (oc);
1598
+
1599
+ return false ;
1600
+ }
1601
+
1602
+ /* *****************************************
1603
+ * Given a pointer:
1604
+ * If it is an Object, return that Object.
1605
+ * If it is an interface, return the Object implementing the interface.
1606
+ * If it is null, return null.
1607
+ * Else, undefined crash
1608
+ */
1609
+ extern (C ) Object _d_toObject(return scope void * p) @nogc nothrow pure @trusted
1610
+ {
1611
+ if (! p)
1612
+ return null ;
1613
+
1614
+ Object o = cast (Object ) p;
1615
+ Interface * pi = ** cast (Interface *** ) p;
1616
+
1617
+ /* Interface.offset lines up with ClassInfo.name.ptr,
1618
+ * so we rely on pointers never being less than 64K,
1619
+ * and Objects never being greater.
1620
+ */
1621
+ if (pi.offset < 0x10000 )
1622
+ return cast (Object )(p - pi.offset);
1623
+
1624
+ return o;
1625
+ }
1577
1626
1578
1627
/**
1579
1628
* Runtime type information about a class.
0 commit comments