From 5871eb9e916f60c990f20c3ce2170f29908762e3 Mon Sep 17 00:00:00 2001 From: Allan Feldman Date: Mon, 20 Apr 2020 10:52:49 -0400 Subject: [PATCH] Run finalizers before invoking weakref callbacks. --- Modules/gcmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 5727820f09..7ef3264b4e 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -1252,15 +1252,15 @@ collect(PyThreadState *tstate, int generation, } } + /* Call tp_finalize on objects which have one. */ + finalize_garbage(tstate, &unreachable); + /* Clear weakrefs and invoke callbacks as necessary. */ m += handle_weakrefs(&unreachable, old); validate_list(old, collecting_clear_unreachable_clear); validate_list(&unreachable, collecting_set_unreachable_clear); - /* Call tp_finalize on objects which have one. */ - finalize_garbage(tstate, &unreachable); - /* Handle any objects that may have resurrected after the call * to 'finalize_garbage' and continue the collection with the * objects that are still unreachable */ -- 2.25.1