Skip to content

Commit a0c76ab

Browse files
committed
when we upcall from C and expect a long result, we can also return the pointer in an unwrapped PythonNativeVoidPtr
1 parent 2944aac commit a0c76ab

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,15 +1831,27 @@ abstract static class UpcallCextLNode extends PythonBuiltinNode {
18311831
@Child private CExtNodes.AsLong asLongNode = CExtNodes.AsLong.create();
18321832

18331833
@Specialization
1834-
long upcall(VirtualFrame frame, PythonModule cextModule, String name, Object[] args,
1834+
Object upcall(VirtualFrame frame, PythonModule cextModule, String name, Object[] args,
1835+
@Cached("createBinaryProfile()") ConditionProfile isVoidPtr,
18351836
@Cached("create()") CExtNodes.CextUpcallNode upcallNode) {
1836-
return asLongNode.execute(upcallNode.execute(frame, cextModule, name, args));
1837+
Object result = upcallNode.execute(frame, cextModule, name, args);
1838+
if (isVoidPtr.profile(result instanceof PythonNativeVoidPtr)) {
1839+
return ((PythonNativeVoidPtr) result).object;
1840+
} else {
1841+
return asLongNode.execute(result);
1842+
}
18371843
}
18381844

18391845
@Specialization(guards = "!isString(callable)")
1840-
long doDirect(VirtualFrame frame, @SuppressWarnings("unused") PythonModule cextModule, Object callable, Object[] args,
1846+
Object doDirect(VirtualFrame frame, @SuppressWarnings("unused") PythonModule cextModule, Object callable, Object[] args,
1847+
@Cached("createBinaryProfile()") ConditionProfile isVoidPtr,
18411848
@Cached("create()") CExtNodes.DirectUpcallNode upcallNode) {
1842-
return asLongNode.execute(upcallNode.execute(frame, callable, args));
1849+
Object result = upcallNode.execute(frame, callable, args);
1850+
if (isVoidPtr.profile(result instanceof PythonNativeVoidPtr)) {
1851+
return ((PythonNativeVoidPtr) result).object;
1852+
} else {
1853+
return asLongNode.execute(result);
1854+
}
18431855
}
18441856
}
18451857

0 commit comments

Comments
 (0)