Skip to content

Commit 2f16058

Browse files
committed
Fix: Disambiguate 'PythonNativeNull' from foreign objects.
1 parent a5d61e6 commit 2f16058

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ Object doPythonNativeNull(String name, @SuppressWarnings("unused") PythonNativeN
544544
return result;
545545
}
546546

547-
@Specialization(guards = "isForeignObject(result)")
547+
@Specialization(guards = {"isForeignObject(result)", "!isNativeNull(result)"})
548548
Object doForeign(String name, TruffleObject result,
549549
@Cached("createBinaryProfile()") ConditionProfile isNullProfile) {
550550
checkFunctionResult(name, isNullProfile.profile(isNull(result)));
@@ -583,6 +583,10 @@ private boolean isNull(TruffleObject result) {
583583
return ForeignAccess.sendIsNull(isNullNode, result);
584584
}
585585

586+
protected static boolean isNativeNull(TruffleObject object) {
587+
return object instanceof PythonNativeNull;
588+
}
589+
586590
protected static boolean isPythonObjectNativeWrapper(PythonNativeWrapper object) {
587591
return object instanceof PythonObjectNativeWrapper;
588592
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ protected static boolean isNativeWrapper(Object obj) {
218218
return obj instanceof PythonNativeWrapper;
219219
}
220220

221+
protected static boolean isNativeNull(Object object) {
222+
return object instanceof PythonNativeNull;
223+
}
224+
221225
protected TruffleObject importCAPISymbol(String name) {
222226
TruffleObject capiLibrary = (TruffleObject) getContext().getCapiLibrary();
223227
if (readSymbolNode == null) {
@@ -306,7 +310,7 @@ Object runAbstractObject(PythonAbstractObject object,
306310
return PythonObjectNativeWrapper.wrap(object, noWrapperProfile);
307311
}
308312

309-
@Specialization(guards = {"isForeignObject(object)", "!isNativeWrapper(object)"})
313+
@Specialization(guards = {"isForeignObject(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"})
310314
Object doPythonClass(TruffleObject object) {
311315
return TruffleObjectNativeWrapper.wrap(object);
312316
}
@@ -423,10 +427,6 @@ protected static boolean isPrimitiveNativeWrapper(PythonNativeWrapper object) {
423427
return object instanceof PrimitiveNativeWrapper && !isMaterialized((PrimitiveNativeWrapper) object);
424428
}
425429

426-
protected static boolean isNativeNull(Object object) {
427-
return object instanceof PythonNativeNull;
428-
}
429-
430430
protected boolean isForeignObject(TruffleObject obj) {
431431
// TODO we could probably also just use 'PGuards.isForeignObject'
432432
if (getClassNode == null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PythonNativeNull.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ long access(PythonNativeNull obj) {
100100
}
101101

102102
}
103+
104+
@Resolve(message = "IS_NULL")
105+
public abstract static class IsNull extends Node {
106+
boolean access(@SuppressWarnings("unused") PythonNativeNull obj) {
107+
return true;
108+
}
109+
}
103110
}
104111

105112
}

0 commit comments

Comments
 (0)