Skip to content

Commit 5f08f44

Browse files
committed
Implement fallback case for 'PyType_IsSubtype'.
1 parent 82ea460 commit 5f08f44

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,10 +2042,11 @@ long doGeneric(Object n) {
20422042

20432043
@Builtin(name = "PyType_IsSubtype", fixedNumOfPositionalArgs = 2)
20442044
@GenerateNodeFactory
2045-
abstract static class PyType_IsSubtype extends PythonBuiltinNode {
2045+
abstract static class PyType_IsSubtype extends PythonBinaryBuiltinNode {
20462046

20472047
@Child private IsSubtypeNode isSubtypeNode = IsSubtypeNode.create();
20482048
@Child private CExtNodes.AsPythonObjectNode asPythonObjectNode = CExtNodes.AsPythonObjectNode.create();
2049+
@Child private CExtNodes.ToJavaNode toJavaNode;
20492050

20502051
@Specialization(guards = {"a == cachedA", "b == cachedB"})
20512052
int doCached(@SuppressWarnings("unused") PythonNativeWrapper a, @SuppressWarnings("unused") PythonNativeWrapper b,
@@ -2056,10 +2057,19 @@ int doCached(@SuppressWarnings("unused") PythonNativeWrapper a, @SuppressWarning
20562057
}
20572058

20582059
@Specialization(replaces = "doCached")
2059-
int doGeneric(PythonNativeWrapper a, PythonNativeWrapper b) {
2060+
int doUncached(PythonNativeWrapper a, PythonNativeWrapper b) {
20602061
return isNativeSubtype(a, b);
20612062
}
20622063

2064+
@Fallback
2065+
int doGeneric(Object a, Object b) {
2066+
if (toJavaNode == null) {
2067+
CompilerDirectives.transferToInterpreterAndInvalidate();
2068+
toJavaNode = insert(CExtNodes.ToJavaNode.create());
2069+
}
2070+
return isSubtypeNode.execute(toJavaNode.execute(a), toJavaNode.execute(b)) ? 1 : 0;
2071+
}
2072+
20632073
protected int isNativeSubtype(PythonNativeWrapper a, PythonNativeWrapper b) {
20642074
assert a instanceof PythonClassNativeWrapper || a instanceof PythonClassInitNativeWrapper;
20652075
assert b instanceof PythonClassNativeWrapper || b instanceof PythonClassInitNativeWrapper;

0 commit comments

Comments
 (0)