Skip to content

Commit e7a2655

Browse files
timfelansalond
authored andcommitted
do not enqueue PNone callbacks
(cherry picked from commit 8f17727)
1 parent b906688 commit e7a2655

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,23 @@ public PReferenceType refType(LazyPythonClass cls, Object object, @SuppressWarni
137137

138138
@Specialization(guards = "!isNativeObject(object)")
139139
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+
}
141145
}
142146

143147
@Specialization
144148
public PReferenceType refType(LazyPythonClass cls, PythonAbstractNativeObject pythonObject, Object callback,
145149
@Cached("create()") GetLazyClassNode getClassNode,
146150
@Cached("create()") IsBuiltinClassProfile profile) {
151+
Object actualCallback = callback instanceof PNone ? null : callback;
147152
LazyPythonClass clazz = getClassNode.execute(pythonObject);
148153

149154
// if the object is a type, a weak ref is allowed
150155
if (profile.profileClass(clazz, PythonBuiltinClassType.PythonClass)) {
151-
return factory().createReferenceType(cls, pythonObject, callback, getWeakReferenceQueue());
156+
return factory().createReferenceType(cls, pythonObject, actualCallback, getWeakReferenceQueue());
152157
}
153158

154159
// 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
159164
}
160165
Object tpWeaklistoffset = getTpWeaklistoffsetNode.execute(clazz);
161166
if (tpWeaklistoffset != PNone.NO_VALUE) {
162-
return factory().createReferenceType(cls, pythonObject, callback, getWeakReferenceQueue());
167+
return factory().createReferenceType(cls, pythonObject, actualCallback, getWeakReferenceQueue());
163168
}
164169
}
165-
return refType(cls, pythonObject, callback);
170+
return refType(cls, pythonObject, actualCallback);
166171
}
167172

168173
@Fallback

0 commit comments

Comments
 (0)