diff options
author | neonene <53406459+neonene@users.noreply.github.com> | 2025-05-27 02:46:49 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-26 11:46:49 -0600 |
commit | c60f39ada625562bff26400f304690c19fe9f504 (patch) | |
tree | 91f7f6ab694110bf2a94a7f7a781369803396209 /Python/crossinterp.c | |
parent | b8a885ce6318c5f1e916e19e2961434d096c5cef (diff) | |
download | cpython-c60f39ada625562bff26400f304690c19fe9f504.tar.gz cpython-c60f39ada625562bff26400f304690c19fe9f504.zip |
gh-134557: Suppress immortalization in _PyCode_GetScriptXIData under free-threading (gh-134686)
Disable immortalization around Py_CompileString*().
The same approach as 332356b that fixed the refleaks in compile() and eval().
E: 09e72cf can pass test_capi, test_sys and test__interpchannels with this patch for me.
Diffstat (limited to 'Python/crossinterp.c')
-rw-r--r-- | Python/crossinterp.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c index 26eecdddf4b..13d91c508c4 100644 --- a/Python/crossinterp.c +++ b/Python/crossinterp.c @@ -908,8 +908,15 @@ get_script_xidata(PyThreadState *tstate, PyObject *obj, int pure, } goto error; } +#ifdef Py_GIL_DISABLED + // Don't immortalize code constants to avoid memory leaks. + ((_PyThreadStateImpl *)tstate)->suppress_co_const_immortalization++; +#endif code = Py_CompileStringExFlags( script, filename, Py_file_input, &cf, optimize); +#ifdef Py_GIL_DISABLED + ((_PyThreadStateImpl *)tstate)->suppress_co_const_immortalization--; +#endif Py_XDECREF(ref); if (code == NULL) { goto error; |