@@ -137,18 +137,23 @@ public PReferenceType refType(LazyPythonClass cls, Object object, @SuppressWarni
137
137
138
138
@ Specialization (guards = "!isNativeObject(object)" )
139
139
public PReferenceType refType (LazyPythonClass cls , Object object , Object callback ) {
140
- return factory ().createReferenceType (cls , object , callback , getWeakReferenceQueue ());
140
+ if (callback instanceof PNone ) {
141
+ return factory ().createReferenceType (cls , object , null , getWeakReferenceQueue ());
142
+ } else {
143
+ return factory ().createReferenceType (cls , object , callback , getWeakReferenceQueue ());
144
+ }
141
145
}
142
146
143
147
@ Specialization
144
148
public PReferenceType refType (LazyPythonClass cls , PythonAbstractNativeObject pythonObject , Object callback ,
145
149
@ Cached ("create()" ) GetLazyClassNode getClassNode ,
146
150
@ Cached ("create()" ) IsBuiltinClassProfile profile ) {
151
+ Object actualCallback = callback instanceof PNone ? null : callback ;
147
152
LazyPythonClass clazz = getClassNode .execute (pythonObject );
148
153
149
154
// if the object is a type, a weak ref is allowed
150
155
if (profile .profileClass (clazz , PythonBuiltinClassType .PythonClass )) {
151
- return factory ().createReferenceType (cls , pythonObject , callback , getWeakReferenceQueue ());
156
+ return factory ().createReferenceType (cls , pythonObject , actualCallback , getWeakReferenceQueue ());
152
157
}
153
158
154
159
// if the object's type is a native type, we need to consider 'tp_weaklistoffset'
@@ -159,10 +164,10 @@ public PReferenceType refType(LazyPythonClass cls, PythonAbstractNativeObject py
159
164
}
160
165
Object tpWeaklistoffset = getTpWeaklistoffsetNode .execute (clazz );
161
166
if (tpWeaklistoffset != PNone .NO_VALUE ) {
162
- return factory ().createReferenceType (cls , pythonObject , callback , getWeakReferenceQueue ());
167
+ return factory ().createReferenceType (cls , pythonObject , actualCallback , getWeakReferenceQueue ());
163
168
}
164
169
}
165
- return refType (cls , pythonObject , callback );
170
+ return refType (cls , pythonObject , actualCallback );
166
171
}
167
172
168
173
@ Fallback
0 commit comments