diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-12-03 17:26:25 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 17:26:25 (GMT) |
| commit | 49da170709dd47c49bfc1e5d4b5d46122a049a3b (patch) | |
| tree | ffe9d0289f8a1098ec779d9c97371ab0e38771bd /Include | |
| parent | b49e902b81a0ead84e2002f94a2a2b2ae9b09ada (diff) | |
| download | cpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.zip cpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.tar.gz cpython-49da170709dd47c49bfc1e5d4b5d46122a049a3b.tar.bz2 | |
[3.12] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-125205)
Fix a crash caused by immortal interned strings being shared between
sub-interpreters that use basic single-phase init. In that case, the string
can be used by an interpreter that outlives the interpreter that created and
interned it. For interpreters that share obmalloc state, also share the
interned dict with the main interpreter.
This is an un-revert of gh-124646 that then addresses the Py_TRACE_REFS
failures identified by gh-124785 (i.e. backporting gh-125709 too).
(cherry picked from commit f2cb39947093feda3ff85b8dc820922cc5e5f954, AKA gh-124865)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Include')
| -rw-r--r-- | Include/internal/pycore_object_state.h | 8 | ||||
| -rw-r--r-- | Include/internal/pycore_runtime_init.h | 7 |
2 files changed, 7 insertions, 8 deletions
diff --git a/Include/internal/pycore_object_state.h b/Include/internal/pycore_object_state.h index 65feb5a..6e07b1a 100644 --- a/Include/internal/pycore_object_state.h +++ b/Include/internal/pycore_object_state.h @@ -24,7 +24,13 @@ struct _py_object_state { * together via the _ob_prev and _ob_next members of a PyObject, which * exist only in a Py_TRACE_REFS build. */ - PyObject refchain; + PyObject *refchain; + /* In most cases, refchain points to _refchain_obj. + * In sub-interpreters that share objmalloc state with the main interp, + * refchain points to the main interpreter's _refchain_obj, and their own + * _refchain_obj is unused. + */ + PyObject _refchain_obj; #endif int _not_used; }; diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index e5f9e17..ad90ea6 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -132,15 +132,8 @@ extern PyTypeObject _PyExc_MemoryError; .context_ver = 1, \ } -#ifdef Py_TRACE_REFS -# define _py_object_state_INIT(INTERP) \ - { \ - .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \ - } -#else # define _py_object_state_INIT(INTERP) \ { 0 } -#endif // global objects |
