mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-116604: Correctly honor the gc status when calling _Py_RunGC (GH-116628) (#116653)
This commit is contained in:
parent
f9d1ec8e80
commit
dcfb21d8b4
3 changed files with 31 additions and 0 deletions
|
@ -1387,6 +1387,31 @@ class GCTogglingTests(unittest.TestCase):
|
|||
# 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):
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue