mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
This commit is contained in:
parent
4ce27904b5
commit
7642070807
4 changed files with 14 additions and 54 deletions
|
|
@ -1493,9 +1493,9 @@ move_legacy_finalizer_reachable(struct collection_state *state)
|
|||
}
|
||||
|
||||
// Clear all weakrefs to unreachable objects. Weakrefs with callbacks are
|
||||
// optionally enqueued in `wrcb_to_call`, but not invoked yet.
|
||||
// enqueued in `wrcb_to_call`, but not invoked yet.
|
||||
static void
|
||||
clear_weakrefs(struct collection_state *state, bool enqueue_callbacks)
|
||||
clear_weakrefs(struct collection_state *state)
|
||||
{
|
||||
PyObject *op;
|
||||
WORKSTACK_FOR_EACH(&state->unreachable, op) {
|
||||
|
|
@ -1527,10 +1527,6 @@ clear_weakrefs(struct collection_state *state, bool enqueue_callbacks)
|
|||
_PyWeakref_ClearRef(wr);
|
||||
_PyObject_ASSERT((PyObject *)wr, wr->wr_object == Py_None);
|
||||
|
||||
if (!enqueue_callbacks) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We do not invoke callbacks for weakrefs that are themselves
|
||||
// unreachable. This is partly for historical reasons: weakrefs
|
||||
// predate safe object finalization, and a weakref that is itself
|
||||
|
|
@ -2216,7 +2212,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
|
|||
interp->gc.long_lived_total = state->long_lived_total;
|
||||
|
||||
// Clear weakrefs and enqueue callbacks (but do not call them).
|
||||
clear_weakrefs(state, true);
|
||||
clear_weakrefs(state);
|
||||
_PyEval_StartTheWorld(interp);
|
||||
|
||||
// Deallocate any object from the refcount merge step
|
||||
|
|
@ -2227,19 +2223,11 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
|
|||
call_weakref_callbacks(state);
|
||||
finalize_garbage(state);
|
||||
|
||||
_PyEval_StopTheWorld(interp);
|
||||
// Handle any objects that may have resurrected after the finalization.
|
||||
_PyEval_StopTheWorld(interp);
|
||||
err = handle_resurrected_objects(state);
|
||||
// Clear free lists in all threads
|
||||
_PyGC_ClearAllFreeLists(interp);
|
||||
if (err == 0) {
|
||||
// Clear weakrefs to objects in the unreachable set. No Python-level
|
||||
// code must be allowed to access those unreachable objects. During
|
||||
// delete_garbage(), finalizers outside the unreachable set might
|
||||
// run and create new weakrefs. If those weakrefs were not cleared,
|
||||
// they could reveal unreachable objects.
|
||||
clear_weakrefs(state, false);
|
||||
}
|
||||
_PyEval_StartTheWorld(interp);
|
||||
|
||||
if (err < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue