8000 [3.12] gh-116604: Correctly honor the gc status when calling _Py_RunG… · python/cpython@dcfb21d · GitHub
[go: up one dir, main page]

Skip to content

Commit dcfb21d

Browse files
authored
[3.12] gh-116604: Correctly honor the gc status when calling _Py_RunGC (GH-116628) (#116653)
1 parent f9d1ec8 commit dcfb21d

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Lib/test/test_gc.py

Lines changed: 25 additions & 0 deletions
< 8000 td data-grid-cell-id="diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7-1389-1400-2" data-line-anchor="diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7R1400" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
try:
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,31 @@ def __del__(self):
13871387
# empty __dict__.
13881388
self.assertEqual(x, None)
13891389

1390+
def test_indirect_calls_with_gc_disabled(self):
1391+
junk = []
1392+
i = 0
1393+
detector = GC_Detector()
1394+
while not detector.gc_happened:
1395+
i += 1
1396+
if i > 10000:
1397+
self.fail("gc didn't happen after 10000 iterations")
1398+
junk.append([]) # this will eventually trigger gc
1399+
1400
1401+
gc.disable()
1402+
junk = []
1403+
i = 0
1404+
detector = GC_Detector()
1405+
while not detector.gc_happened:
1406+
i += 1
1407+
if i > 10000:
1408+
break
1409+
junk.append([]) # this may eventually trigger gc (if it is enabled)
1410+
1411+
self.assertEqual(i, 10001)
1412+
finally:
1413+
gc.enable()
1414+
13901415

13911416
class PythonFinalizationTests(unittest.TestCase):
13921417
def test_ast_fini(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Respect the status of the garbage collector when indirect calls are made via
2+
:c:func:`PyErr_CheckSignals` and the evaluation breaker. Patch by Pablo
3+
Galindo

Modules/gcmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,9 @@ void
22882288
_Py_RunGC(PyThreadState *tstate)
22892289
{
22902290
GCState *gcstate = &tstate->interp->gc;
2291+
if (!gcstate->enabled) {
2292+
return;
2293+
}
22912294
gcstate->collecting = 1;
22922295
gc_collect_generations(tstate);
22932296
gcstate->collecting = 0;

0 commit comments

Comments
 (0)
0