]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116604: Check for `gcstate->enabled` in _Py_RunGC in free-threaded build (#116663)
authorSam Gross <colesbury@gmail.com>
Tue, 12 Mar 2024 17:12:02 +0000 (13:12 -0400)
committerGitHub <noreply@github.com>
Tue, 12 Mar 2024 17:12:02 +0000 (17:12 +0000)
This isn't strictly necessary because the implementation of `gc_should_collect`
already checks `gcstate->enabled` in the free-threaded build, but it seems
like a good idea until the common pieces of gc.c and gc_free_threading.c are
refactored out.

Python/gc_free_threading.c

index 59e76012f8fc5009a1ce30f44024fd1302e33b3d..2b13d1f005dd9723c6a778320907b8abacf7709c 100644 (file)
@@ -1603,6 +1603,10 @@ _PyObject_GC_Link(PyObject *op)
 void
 _Py_RunGC(PyThreadState *tstate)
 {
+    GCState *gcstate = get_gc_state();
+    if (!gcstate->enabled) {
+        return;
+    }
     gc_collect_main(tstate, 0, _Py_GC_REASON_HEAP);
 }