diff options
author | Victor Stinner <vstinner@python.org> | 2021-01-12 09:29:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 09:29:45 (GMT) |
commit | 44bf57aca627bd11a08b12fe4e4b6a0e1d268862 (patch) | |
tree | 8a4fd654a088bf39e0cc1cf21f799c05ee5b2bd3 /Python/pystate.c | |
parent | fb35fa49d192368e94ffec09c092260ed0fea2e1 (diff) | |
download | cpython-44bf57aca627bd11a08b12fe4e4b6a0e1d268862.zip cpython-44bf57aca627bd11a08b12fe4e4b6a0e1d268862.tar.gz cpython-44bf57aca627bd11a08b12fe4e4b6a0e1d268862.tar.bz2 |
bpo-42882: _PyRuntimeState_Init() leaves unicode next_index unchanged (GH-24193)
Fix the _PyUnicode_FromId() function (_Py_IDENTIFIER(var) API) when
Py_Initialize() / Py_Finalize() is called multiple times:
preserve _PyRuntime.unicode_ids.next_index value.
Use _PyRuntimeState_INIT macro instead memset(0) to reset
_PyRuntimeState members to zero.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index c791b23..ebf76a0 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -54,6 +54,9 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime) void *open_code_hook = runtime->open_code_hook; void *open_code_userdata = runtime->open_code_userdata; _Py_AuditHookEntry *audit_hook_head = runtime->audit_hook_head; + // bpo-42882: Preserve next_index value if Py_Initialize()/Py_Finalize() + // is called multiple times. + int64_t unicode_next_index = runtime->unicode_ids.next_index; memset(runtime, 0, sizeof(*runtime)); @@ -90,7 +93,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime) if (runtime->unicode_ids.lock == NULL) { return _PyStatus_NO_MEMORY(); } - runtime->unicode_ids.next_index = 0; + runtime->unicode_ids.next_index = unicode_next_index; return _PyStatus_OK(); } |