https://github.com/python/cpython/commit/dcfb21d8b4c930c4295cd9a75814316e5b103683
commit: dcfb21d8b4c930c4295cd9a75814316e5b103683
branch: 3.12
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2024-03-12T23:38:20Z
summary:
[3.12] gh-116604: Correctly honor the gc status when calling _Py_RunGC
(GH-116628) (#116653)
files:
A Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-24-59.gh-issue-116604.LCEzAT.rst
M Lib/test/test_gc.py
M Modules/gcmodule.c
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index db7cb9ace6e5f3..81bb5bb288ef31 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1387,6 +1387,31 @@ def __del__(self):
# empty __dict__.
self.assertEqual(x, None)
+ def test_indirect_calls_with_gc_disabled(self):
+ junk = []
+ i = 0
+ detector = GC_Detector()
+ while not detector.gc_happened:
+ i += 1
+ if i > 10000:
+ self.fail("gc didn't happen after 10000 iterations")
+ junk.append([]) # this will eventually trigger gc
+
+ try:
+ gc.disable()
+ junk = []
+ i = 0
+ detector = GC_Detector()
+ while not detector.gc_happened:
+ i += 1
+ if i > 10000:
+ break
+ junk.append([]) # this may eventually trigger gc (if it is
enabled)
+
+ self.assertEqual(i, 10001)
+ finally:
+ gc.enable()
+
class PythonFinalizationTests(unittest.TestCase):
def test_ast_fini(self):
diff --git a/Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-24-59.gh-issue-116604.LCEzAT.rst b/Misc/NEWS.d/next/Core
and Builtins/2024-03-11-22-24-59.gh-issue-116604.LCEzAT.rst
new file mode 100644
index 00000000000000..516edfa9e6cedf
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-24-59.gh-issue-116604.LCEzAT.rst
@@ -0,0 +1,3 @@
+Respect the status of the garbage collector when indirect calls are made via
+:c:func:`PyErr_CheckSignals` and the evaluation breaker. Patch by Pablo
+Galindo
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 149a6a022d08ce..c9b5aab8598f17 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -2288,6 +2288,9 @@ void
_Py_RunGC(PyThreadState *tstate)
{
GCState *gcstate = &tstate->interp->gc;
+ if (!gcstate->enabled) {
+ return;
+ }
gcstate->collecting = 1;
gc_collect_generations(tstate);
gcstate->collecting = 0;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]