mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-40910: Export Py_GetArgcArgv() function (GH-20721)
Export explicitly the Py_GetArgcArgv() function to the C API and document the function. Previously, it was exported implicitly which no longer works since Python is built with -fvisibility=hidden. * Add PyConfig._orig_argv member. * Py_InitializeFromConfig() no longer calls _PyConfig_Write() twice. * PyConfig_Read() no longer initializes Py_GetArgcArgv(): it is now _PyConfig_Write() responsibility. * _PyConfig_Write() result type becomes PyStatus instead of void. * Write an unit test on Py_GetArgcArgv().
This commit is contained in:
parent
8f023a2f66
commit
e81f6e687d
10 changed files with 131 additions and 22 deletions
|
@ -580,7 +580,7 @@ _Py_HashRandomization_Init(const PyConfig *config)
|
|||
res = pyurandom(secret, secret_size, 0, 0);
|
||||
if (res < 0) {
|
||||
return _PyStatus_ERR("failed to get random numbers "
|
||||
"to initialize Python");
|
||||
"to initialize Python");
|
||||
}
|
||||
}
|
||||
return _PyStatus_OK();
|
||||
|
|
|
@ -548,8 +548,6 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
|
|||
}
|
||||
|
||||
|
||||
/* Make the *original* argc/argv available to other modules.
|
||||
This is rare, but it is needed by the secureware extension. */
|
||||
void
|
||||
Py_GetArgcArgv(int *argc, wchar_t ***argv)
|
||||
{
|
||||
|
@ -859,6 +857,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
|
|||
COPY_ATTR(pathconfig_warnings);
|
||||
COPY_ATTR(_init_main);
|
||||
COPY_ATTR(_isolated_interpreter);
|
||||
COPY_WSTRLIST(_orig_argv);
|
||||
|
||||
#undef COPY_ATTR
|
||||
#undef COPY_WSTR_ATTR
|
||||
|
@ -960,6 +959,7 @@ config_as_dict(const PyConfig *config)
|
|||
SET_ITEM_INT(pathconfig_warnings);
|
||||
SET_ITEM_INT(_init_main);
|
||||
SET_ITEM_INT(_isolated_interpreter);
|
||||
SET_ITEM_WSTRLIST(_orig_argv);
|
||||
|
||||
return dict;
|
||||
|
||||
|
@ -1856,7 +1856,7 @@ config_init_stdio(const PyConfig *config)
|
|||
|
||||
- set Py_xxx global configuration variables
|
||||
- initialize C standard streams (stdin, stdout, stderr) */
|
||||
void
|
||||
PyStatus
|
||||
_PyConfig_Write(const PyConfig *config, _PyRuntimeState *runtime)
|
||||
{
|
||||
config_set_global_vars(config);
|
||||
|
@ -1870,6 +1870,13 @@ _PyConfig_Write(const PyConfig *config, _PyRuntimeState *runtime)
|
|||
preconfig->isolated = config->isolated;
|
||||
preconfig->use_environment = config->use_environment;
|
||||
preconfig->dev_mode = config->dev_mode;
|
||||
|
||||
if (_Py_SetArgcArgv(config->_orig_argv.length,
|
||||
config->_orig_argv.items) < 0)
|
||||
{
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2493,7 +2500,6 @@ PyStatus
|
|||
PyConfig_Read(PyConfig *config)
|
||||
{
|
||||
PyStatus status;
|
||||
PyWideStringList orig_argv = _PyWideStringList_INIT;
|
||||
|
||||
status = _Py_PreInitializeFromConfig(config, NULL);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
|
@ -2502,8 +2508,13 @@ PyConfig_Read(PyConfig *config)
|
|||
|
||||
config_get_global_vars(config);
|
||||
|
||||
if (_PyWideStringList_Copy(&orig_argv, &config->argv) < 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
if (config->_orig_argv.length == 0
|
||||
&& !(config->argv.length == 1
|
||||
&& wcscmp(config->argv.items[0], L"") == 0))
|
||||
{
|
||||
if (_PyWideStringList_Copy(&config->_orig_argv, &config->argv) < 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
}
|
||||
|
||||
_PyPreCmdline precmdline = _PyPreCmdline_INIT;
|
||||
|
@ -2534,11 +2545,6 @@ PyConfig_Read(PyConfig *config)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (_Py_SetArgcArgv(orig_argv.length, orig_argv.items) < 0) {
|
||||
status = _PyStatus_NO_MEMORY();
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Check config consistency */
|
||||
assert(config->isolated >= 0);
|
||||
assert(config->use_environment >= 0);
|
||||
|
@ -2591,11 +2597,11 @@ PyConfig_Read(PyConfig *config)
|
|||
assert(config->check_hash_pycs_mode != NULL);
|
||||
assert(config->_install_importlib >= 0);
|
||||
assert(config->pathconfig_warnings >= 0);
|
||||
assert(_PyWideStringList_CheckConsistency(&config->_orig_argv));
|
||||
|
||||
status = _PyStatus_OK();
|
||||
|
||||
done:
|
||||
_PyWideStringList_Clear(&orig_argv);
|
||||
_PyPreCmdline_Clear(&precmdline);
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -460,7 +460,10 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
|
|||
return _PyStatus_ERR("can't make main interpreter");
|
||||
}
|
||||
|
||||
_PyConfig_Write(config, runtime);
|
||||
status = _PyConfig_Write(config, runtime);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = _PyInterpreterState_SetConfig(interp, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
|
@ -486,7 +489,10 @@ pycore_init_runtime(_PyRuntimeState *runtime,
|
|||
return _PyStatus_ERR("main interpreter already initialized");
|
||||
}
|
||||
|
||||
_PyConfig_Write(config, runtime);
|
||||
PyStatus status = _PyConfig_Write(config, runtime);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Py_Finalize leaves _Py_Finalizing set in order to help daemon
|
||||
* threads behave a little more gracefully at interpreter shutdown.
|
||||
|
@ -499,7 +505,7 @@ pycore_init_runtime(_PyRuntimeState *runtime,
|
|||
*/
|
||||
_PyRuntimeState_SetFinalizing(runtime, NULL);
|
||||
|
||||
PyStatus status = _Py_HashRandomization_Init(config);
|
||||
status = _Py_HashRandomization_Init(config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
@ -746,8 +752,6 @@ pyinit_config(_PyRuntimeState *runtime,
|
|||
PyThreadState **tstate_p,
|
||||
const PyConfig *config)
|
||||
{
|
||||
_PyConfig_Write(config, runtime);
|
||||
|
||||
PyStatus status = pycore_init_runtime(runtime, config);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue