@@ -3023,23 +3023,40 @@ static void doPythonAbstractObject(PythonAbstractObject delegate, PythonNativeWr
3023
3023
delegate .clearNativeWrapper ();
3024
3024
}
3025
3025
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 ) {
3029
3040
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" ;
3031
3042
delegate .clearNativeWrapper ();
3032
3043
}
3033
3044
}
3034
3045
3035
- @ Specialization (guards = "! isAnyPythonObject(delegate)" )
3046
+ @ Specialization (guards = { "delegate != null" , "! isAnyPythonObject(delegate)"} )
3036
3047
static void doOther (@ SuppressWarnings ("unused" ) Object delegate , @ SuppressWarnings ("unused" ) PythonNativeWrapper nativeWrapper ) {
3048
+ assert !isPrimitiveNativeWrapper (nativeWrapper );
3037
3049
// ignore
3038
3050
}
3039
3051
3040
3052
static boolean isPrimitiveNativeWrapper (PythonNativeWrapper nativeWrapper ) {
3041
3053
return nativeWrapper instanceof PrimitiveNativeWrapper ;
3042
3054
}
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
+
3043
3060
}
3044
3061
3045
3062
@ GenerateUncached
0 commit comments