mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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.
This commit is contained in:
parent
fb35fa49d1
commit
44bf57aca6
3 changed files with 11 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue