mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +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
|
@ -51,6 +51,8 @@ typedef struct _Py_AuditHookEntry {
|
|||
|
||||
struct _Py_unicode_runtime_ids {
|
||||
PyThread_type_lock lock;
|
||||
// next_index value must be preserved when Py_Initialize()/Py_Finalize()
|
||||
// is called multiple times: see _PyUnicode_FromId() implementation.
|
||||
Py_ssize_t next_index;
|
||||
};
|
||||
|
||||
|
@ -107,6 +109,8 @@ typedef struct pyruntimestate {
|
|||
|
||||
PyPreConfig preconfig;
|
||||
|
||||
// Audit values must be preserved when Py_Initialize()/Py_Finalize()
|
||||
// is called multiple times.
|
||||
Py_OpenCodeHookFunction open_code_hook;
|
||||
void *open_code_userdata;
|
||||
_Py_AuditHookEntry *audit_hook_head;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Fix the :c:func:`_PyUnicode_FromId` function (_Py_IDENTIFIER(var) API) when
|
||||
:c:func:`Py_Initialize` / :c:func:`Py_Finalize` is called multiple times:
|
||||
preserve ``_PyRuntime.unicode_ids.next_index`` value.
|
|
@ -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