Skip to content

Commit e00fbc2

Browse files
committed
gh-153568: Skip GC pause without the GIL
1 parent e6bd93f commit e00fbc2

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Parser/asdl_c.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,15 +2116,20 @@ class PartingShots(StaticVisitor):
21162116
if (state == NULL) {
21172117
return NULL;
21182118
}
2119+
#ifndef Py_GIL_DISABLED
21192120
// Freshly converted AST nodes cannot be part of a reference cycle yet,
21202121
// so a garbage collection while building them cannot free anything of
21212122
// this tree and only pays to traverse its half-built nodes. Pause the
2122-
// collector while the conversion runs.
2123+
// collector while the conversion runs. PyGC_Disable() is interpreter-wide,
2124+
// so this optimization is not safe in a free-threaded build.
21232125
int gc_was_enabled = PyGC_Disable();
2126+
#endif
21242127
PyObject *result = ast2obj_mod(state, t);
2128+
#ifndef Py_GIL_DISABLED
21252129
if (gc_was_enabled) {
21262130
PyGC_Enable();
21272131
}
2132+
#endif
21282133
21292134
return result;
21302135
}

Python/Python-ast.c

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)