Skip to content

Commit dafd62e

Browse files
committed
Address review: use wrapper functions instead of low-level accessors
Use _Py_IsCoreInitialized() in preconfig.c and Py_IsInitialized() in Py_InitializeEx(), removing the unnecessary runtime local variable. Thanks picnixz!
1 parent 2e3aa7e commit dafd62e

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

Python/preconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ _PyPreConfig_Write(const PyPreConfig *src_config)
928928
return status;
929929
}
930930

931-
if (_PyRuntimeState_GetCoreInitialized(&_PyRuntime)) {
931+
if (_Py_IsCoreInitialized()) {
932932
/* bpo-34008: Calling this functions after Py_Initialize() ignores
933933
the new configuration. */
934934
return _PyStatus_OK();

Python/pylifecycle.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,9 +1505,8 @@ Py_InitializeEx(int install_sigs)
15051505
if (_PyStatus_EXCEPTION(status)) {
15061506
Py_ExitStatusException(status);
15071507
}
1508-
_PyRuntimeState *runtime = &_PyRuntime;
15091508

1510-
if (_PyRuntimeState_GetInitialized(runtime)) {
1509+
if (Py_IsInitialized()) {
15111510
/* bpo-33932: Calling Py_Initialize() twice does nothing. */
15121511
return;
15131512
}

Python/sysmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Data members:
3333
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
3434
#include "pycore_pymem.h" // _PyMem_DefaultRawFree()
3535
#include "pycore_pystate.h" // _PyThreadState_GET()
36-
#include "pycore_runtime.h" // _PyRuntimeState_GetInitialized()
3736
#include "pycore_pystats.h" // _Py_PrintSpecializationStats()
3837
#include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags()
3938
#include "pycore_sysmodule.h" // export _PySys_GetSizeOf()
@@ -472,7 +471,7 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
472471
PySys_AddAuditHook() can be called before Python is initialized. */
473472
_PyRuntimeState *runtime = &_PyRuntime;
474473
PyThreadState *tstate;
475-
if (_PyRuntimeState_GetInitialized(runtime)) {
474+
if (Py_IsInitialized()) {
476475
tstate = _PyThreadState_GET();
477476
}
478477
else {

0 commit comments

Comments
 (0)