Skip to content

Commit ad728c0

Browse files
committed
Fix: did not invalidate handleValidAssumption for un-materialized primitive native wrappers.
1 parent 995d777 commit ad728c0

File tree

1 file changed

+22
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext

1 file changed

+22
-5
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,23 +3023,40 @@ static void doPythonAbstractObject(PythonAbstractObject delegate, PythonNativeWr
30233023
delegate.clearNativeWrapper();
30243024
}
30253025

3026-
@Specialization
3027-
static void doPrimitiveNativeWrapper(PythonAbstractObject delegate, PrimitiveNativeWrapper nativeWrapper,
3028-
@Cached("createBinaryProfile()") ConditionProfile profile) {
3026+
@Specialization(guards = "delegate == null")
3027+
static void doPrimitiveNativeWrapper(@SuppressWarnings("unused") Object delegate, PrimitiveNativeWrapper nativeWrapper,
3028+
@Cached("createBinaryProfile()") ConditionProfile profile,
3029+
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
3030+
assert !isSmallIntegerWrapperSingleton(contextRef, nativeWrapper) : "clearing primitive native wrapper singleton of small integer";
3031+
if (profile.profile(nativeWrapper.getHandleValidAssumption() != null)) {
3032+
nativeWrapper.getHandleValidAssumption().invalidate("releasing handle for native wrapper");
3033+
}
3034+
}
3035+
3036+
@Specialization(guards = "delegate != null")
3037+
static void doPrimitiveNativeWrapperMaterialized(PythonAbstractObject delegate, PrimitiveNativeWrapper nativeWrapper,
3038+
@Cached("createBinaryProfile()") ConditionProfile profile,
3039+
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
30293040
if (profile.profile(delegate.getNativeWrapper() == nativeWrapper)) {
3030-
assert !CApiGuards.isSmallIntegerWrapper(nativeWrapper) : "clearing primitive native wrapper for small integer";
3041+
assert !isSmallIntegerWrapperSingleton(contextRef, nativeWrapper) : "clearing primitive native wrapper singleton of small integer";
30313042
delegate.clearNativeWrapper();
30323043
}
30333044
}
30343045

3035-
@Specialization(guards = "!isAnyPythonObject(delegate)")
3046+
@Specialization(guards = {"delegate != null", "!isAnyPythonObject(delegate)"})
30363047
static void doOther(@SuppressWarnings("unused") Object delegate, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper) {
3048+
assert !isPrimitiveNativeWrapper(nativeWrapper);
30373049
// ignore
30383050
}
30393051

30403052
static boolean isPrimitiveNativeWrapper(PythonNativeWrapper nativeWrapper) {
30413053
return nativeWrapper instanceof PrimitiveNativeWrapper;
30423054
}
3055+
3056+
private static boolean isSmallIntegerWrapperSingleton(ContextReference<PythonContext> contextRef, PrimitiveNativeWrapper nativeWrapper) {
3057+
return CApiGuards.isSmallIntegerWrapper(nativeWrapper) && ToSulongNode.doLongSmall(null, nativeWrapper.getLong(), contextRef) == nativeWrapper;
3058+
}
3059+
30433060
}
30443061

30453062
@GenerateUncached

0 commit comments

Comments
 (0)