mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
gh-118527: Intern code consts in free-threaded build (#118667)
We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
This commit is contained in:
parent
8d8275b0cf
commit
723d4d2fe8
14 changed files with 375 additions and 18 deletions
|
@ -866,8 +866,21 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
|
|||
if (str == NULL)
|
||||
goto error;
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// gh-118527: Disable immortalization of code constants for explicit
|
||||
// compile() calls to get consistent frozen outputs between the default
|
||||
// and free-threaded builds.
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
int old_value = interp->gc.immortalize.enable_on_thread_created;
|
||||
interp->gc.immortalize.enable_on_thread_created = 0;
|
||||
#endif
|
||||
|
||||
result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
interp->gc.immortalize.enable_on_thread_created = old_value;
|
||||
#endif
|
||||
|
||||
Py_XDECREF(source_copy);
|
||||
goto finally;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue