Commit f118d43a authored by Kevin Modzelewski's avatar Kevin Modzelewski

Catch exceptions from weakref callbacks

parent ee7c4f47
......@@ -660,7 +660,12 @@ static void graphTraversalMarking(Worklist& worklist, GCVisitor& visitor) {
static void callWeakrefCallback(PyWeakReference* head) {
if (head->wr_callback) {
runtimeCall(head->wr_callback, ArgPassSpec(1), reinterpret_cast<Box*>(head), NULL, NULL, NULL, NULL);
try {
runtimeCall(head->wr_callback, ArgPassSpec(1), reinterpret_cast<Box*>(head), NULL, NULL, NULL, NULL);
} catch (ExcInfo e) {
setCAPIException(e);
PyErr_WriteUnraisable(head->wr_callback);
}
head->wr_callback = NULL;
}
}
......
# Exceptions from finalizers should get caught:
import sys
from testing_helpers import test_gc
......@@ -24,4 +25,27 @@ test_gc(test, 10)
print sorted(strs)
print "done"
# Similarly for exceptions from weakref callbacks:
import weakref
called_callback = False
def callback(ref):
global called_callback
if not called_callback:
print "callback"
called_callback = True
raise ValueError()
class C(object):
pass
import gc
l = []
# Make a bunch of them just to make sure at least one gets collected:
for i in xrange(100):
l.append(weakref.ref(C(), callback))
gc.collect()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment