summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-27 14:39:22 (GMT)
committerGitHub <noreply@github.com>2019-05-27 14:39:22 (GMT)
commit331a6a56e9a9c72f3e4605987fabdaec72677702 (patch)
tree49d20cedd9df4371f2410b2fb24255535ca02c50 /Python/sysmodule.c
parent8cd5165ba05ff57cfdbbc71c393bddad1ce1ab87 (diff)
downloadcpython-331a6a56e9a9c72f3e4605987fabdaec72677702.zip
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.gz
cpython-331a6a56e9a9c72f3e4605987fabdaec72677702.tar.bz2
bpo-36763: Implement the PEP 587 (GH-13592)
* Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 08a1a29..24018e2 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -17,7 +17,7 @@ Data members:
#include "Python.h"
#include "code.h"
#include "frameobject.h"
-#include "pycore_coreconfig.h"
+#include "pycore_initconfig.h"
#include "pycore_pylifecycle.h"
#include "pycore_pymem.h"
#include "pycore_pathconfig.h"
@@ -752,7 +752,7 @@ sys_getfilesystemencoding_impl(PyObject *module)
/*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
- const _PyCoreConfig *config = &interp->core_config;
+ const PyConfig *config = &interp->config;
return PyUnicode_FromWideChar(config->filesystem_encoding, -1);
}
@@ -767,7 +767,7 @@ sys_getfilesystemencodeerrors_impl(PyObject *module)
/*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
- const _PyCoreConfig *config = &interp->core_config;
+ const PyConfig *config = &interp->config;
return PyUnicode_FromWideChar(config->filesystem_errors, -1);
}
@@ -2475,8 +2475,8 @@ make_flags(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
int pos = 0;
PyObject *seq;
- const _PyPreConfig *preconfig = &runtime->preconfig;
- const _PyCoreConfig *config = &interp->core_config;
+ const PyPreConfig *preconfig = &runtime->preconfig;
+ const PyConfig *config = &interp->config;
seq = PyStructSequence_New(&FlagsType);
if (seq == NULL)
@@ -2690,7 +2690,7 @@ static struct PyModuleDef sysmodule = {
} \
} while (0)
-static _PyInitError
+static PyStatus
_PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject *sysdict)
{
@@ -2827,13 +2827,13 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
if (PyErr_Occurred()) {
goto err_occurred;
}
- return _Py_INIT_OK();
+ return _PyStatus_OK();
type_init_failed:
- return _Py_INIT_ERR("failed to initialize a type");
+ return _PyStatus_ERR("failed to initialize a type");
err_occurred:
- return _Py_INIT_ERR("can't initialize sys module");
+ return _PyStatus_ERR("can't initialize sys module");
}
#undef SET_SYS_FROM_STRING
@@ -2885,7 +2885,7 @@ error:
static PyObject*
-sys_create_xoptions_dict(const _PyCoreConfig *config)
+sys_create_xoptions_dict(const PyConfig *config)
{
Py_ssize_t nxoption = config->xoptions.length;
wchar_t * const * xoptions = config->xoptions.items;
@@ -2910,12 +2910,12 @@ int
_PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
PyObject *sysdict = interp->sysdict;
- const _PyCoreConfig *config = &interp->core_config;
+ const PyConfig *config = &interp->config;
int res;
#define COPY_LIST(KEY, VALUE) \
do { \
- PyObject *list = _PyWstrList_AsList(&(VALUE)); \
+ PyObject *list = _PyWideStringList_AsList(&(VALUE)); \
if (list == NULL) { \
return -1; \
} \
@@ -3003,7 +3003,7 @@ err_occurred:
infrastructure for the io module in place.
Use UTF-8/surrogateescape and ignore EAGAIN errors. */
-_PyInitError
+PyStatus
_PySys_SetPreliminaryStderr(PyObject *sysdict)
{
PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr));
@@ -3017,56 +3017,56 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict)
goto error;
}
Py_DECREF(pstderr);
- return _Py_INIT_OK();
+ return _PyStatus_OK();
error:
Py_XDECREF(pstderr);
- return _Py_INIT_ERR("can't set preliminary stderr");
+ return _PyStatus_ERR("can't set preliminary stderr");
}
/* Create sys module without all attributes: _PySys_InitMain() should be called
later to add remaining attributes. */
-_PyInitError
+PyStatus
_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject **sysmod_p)
{
PyObject *modules = PyDict_New();
if (modules == NULL) {
- return _Py_INIT_ERR("can't make modules dictionary");
+ return _PyStatus_ERR("can't make modules dictionary");
}
interp->modules = modules;
PyObject *sysmod = _PyModule_CreateInitialized(&sysmodule, PYTHON_API_VERSION);
if (sysmod == NULL) {
- return _Py_INIT_ERR("failed to create a module object");
+ return _PyStatus_ERR("failed to create a module object");
}
PyObject *sysdict = PyModule_GetDict(sysmod);
if (sysdict == NULL) {
- return _Py_INIT_ERR("can't initialize sys dict");
+ return _PyStatus_ERR("can't initialize sys dict");
}
Py_INCREF(sysdict);
interp->sysdict = sysdict;
if (PyDict_SetItemString(sysdict, "modules", interp->modules) < 0) {
- return _Py_INIT_ERR("can't initialize sys module");
+ return _PyStatus_ERR("can't initialize sys module");
}
- _PyInitError err = _PySys_SetPreliminaryStderr(sysdict);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ PyStatus status = _PySys_SetPreliminaryStderr(sysdict);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
- err = _PySys_InitCore(runtime, interp, sysdict);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ status = _PySys_InitCore(runtime, interp, sysdict);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
}
_PyImport_FixupBuiltin(sysmod, "sys", interp->modules);
*sysmod_p = sysmod;
- return _Py_INIT_OK();
+ return _PyStatus_OK();
}
@@ -3156,7 +3156,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
if (updatepath) {
/* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path.
If argv[0] is a symlink, use the real path. */
- const _PyWstrList argv_list = {.length = argc, .items = argv};
+ const PyWideStringList argv_list = {.length = argc, .items = argv};
PyObject *path0 = NULL;
if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) {
if (path0 == NULL) {