diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-27 14:39:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 14:39:22 (GMT) |
commit | 331a6a56e9a9c72f3e4605987fabdaec72677702 (patch) | |
tree | 49d20cedd9df4371f2410b2fb24255535ca02c50 /Include/cpython | |
parent | 8cd5165ba05ff57cfdbbc71c393bddad1ce1ab87 (diff) | |
download | cpython-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 'Include/cpython')
-rw-r--r-- | Include/cpython/initconfig.h (renamed from Include/cpython/coreconfig.h) | 139 | ||||
-rw-r--r-- | Include/cpython/pylifecycle.h | 30 | ||||
-rw-r--r-- | Include/cpython/pystate.h | 4 |
3 files changed, 82 insertions, 91 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/initconfig.h index ef5fde2..a98b91a 100644 --- a/Include/cpython/coreconfig.h +++ b/Include/cpython/initconfig.h @@ -5,56 +5,49 @@ extern "C" { #endif -/* --- _PyInitError ----------------------------------------------- */ +/* --- PyStatus ----------------------------------------------- */ typedef struct { enum { - _Py_INIT_ERR_TYPE_OK=0, - _Py_INIT_ERR_TYPE_ERROR=1, - _Py_INIT_ERR_TYPE_EXIT=2 + _PyStatus_TYPE_OK=0, + _PyStatus_TYPE_ERROR=1, + _PyStatus_TYPE_EXIT=2 } _type; - const char *_func; + const char *func; const char *err_msg; int exitcode; -} _PyInitError; +} PyStatus; -PyAPI_FUNC(_PyInitError) _PyInitError_Ok(void); -PyAPI_FUNC(_PyInitError) _PyInitError_Error(const char *err_msg); -PyAPI_FUNC(_PyInitError) _PyInitError_NoMemory(void); -PyAPI_FUNC(_PyInitError) _PyInitError_Exit(int exitcode); -PyAPI_FUNC(int) _PyInitError_IsError(_PyInitError err); -PyAPI_FUNC(int) _PyInitError_IsExit(_PyInitError err); -PyAPI_FUNC(int) _PyInitError_Failed(_PyInitError err); +PyAPI_FUNC(PyStatus) PyStatus_Ok(void); +PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg); +PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void); +PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode); +PyAPI_FUNC(int) PyStatus_IsError(PyStatus err); +PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err); +PyAPI_FUNC(int) PyStatus_Exception(PyStatus err); -/* --- _PyWstrList ------------------------------------------------ */ +/* --- PyWideStringList ------------------------------------------------ */ typedef struct { /* If length is greater than zero, items must be non-NULL and all items strings must be non-NULL */ Py_ssize_t length; wchar_t **items; -} _PyWstrList; +} PyWideStringList; +PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list, + const wchar_t *item); -/* --- _PyPreConfig ----------------------------------------------- */ - -#define _Py_CONFIG_VERSION 1 - -typedef enum { - /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */ - _PyConfig_INIT_COMPAT = 1, - _PyConfig_INIT_PYTHON = 2, - _PyConfig_INIT_ISOLATED = 3 -} _PyConfigInitEnum; +/* --- PyPreConfig ----------------------------------------------- */ typedef struct { int _config_version; /* Internal configuration version, used for ABI compatibility */ int _config_init; /* _PyConfigInitEnum value */ - /* Parse _Py_PreInitializeFromArgs() arguments? - See _PyCoreConfig.parse_argv */ + /* Parse Py_PreInitializeFromBytesArgs() arguments? + See PyConfig.parse_argv */ int parse_argv; /* If greater than 0, enable isolated mode: sys.path contains @@ -124,22 +117,22 @@ typedef struct { /* Memory allocator: PYTHONMALLOC env var. See PyMemAllocatorName for valid values. */ int allocator; -} _PyPreConfig; +} PyPreConfig; -PyAPI_FUNC(void) _PyPreConfig_InitPythonConfig(_PyPreConfig *config); -PyAPI_FUNC(void) _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config); +PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config); +PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config); -/* --- _PyCoreConfig ---------------------------------------------- */ +/* --- PyConfig ---------------------------------------------- */ typedef struct { int _config_version; /* Internal configuration version, used for ABI compatibility */ int _config_init; /* _PyConfigInitEnum value */ - int isolated; /* Isolated mode? see _PyPreConfig.isolated */ - int use_environment; /* Use environment variables? see _PyPreConfig.use_environment */ - int dev_mode; /* Development mode? See _PyPreConfig.dev_mode */ + int isolated; /* Isolated mode? see PyPreConfig.isolated */ + int use_environment; /* Use environment variables? see PyPreConfig.use_environment */ + int dev_mode; /* Development mode? See PyPreConfig.dev_mode */ /* Install signal handlers? Yes by default. */ int install_signal_handlers; @@ -207,7 +200,7 @@ typedef struct { If argv is empty, an empty string is added to ensure that sys.argv always exists and is never empty. */ - _PyWstrList argv; + PyWideStringList argv; /* Program name: @@ -219,8 +212,8 @@ typedef struct { - Use "python" on Windows, or "python3 on other platforms. */ wchar_t *program_name; - _PyWstrList xoptions; /* Command line -X options */ - _PyWstrList warnoptions; /* Warnings options */ + PyWideStringList xoptions; /* Command line -X options */ + PyWideStringList warnoptions; /* Warnings options */ /* If equal to zero, disable the import of the module site and the site-dependent manipulations of sys.path that it entails. Also disable @@ -347,17 +340,37 @@ typedef struct { int legacy_windows_stdio; #endif + /* Value of the --check-hash-based-pycs command line option: + + - "default" means the 'check_source' flag in hash-based pycs + determines invalidation + - "always" causes the interpreter to hash the source file for + invalidation regardless of value of 'check_source' bit + - "never" causes the interpreter to always assume hash-based pycs are + valid + + The default value is "default". + + See PEP 552 "Deterministic pycs" for more details. */ + wchar_t *check_hash_pycs_mode; + /* --- Path configuration inputs ------------ */ - wchar_t *module_search_path_env; /* PYTHONPATH environment variable */ + /* If greater than 0, suppress _PyPathConfig_Calculate() warnings on Unix. + The parameter has no effect on Windows. + + If set to -1 (default), inherit !Py_FrozenFlag value. */ + int pathconfig_warnings; + + wchar_t *pythonpath_env; /* PYTHONPATH environment variable */ wchar_t *home; /* PYTHONHOME environment variable, see also Py_SetPythonHome(). */ /* --- Path configuration outputs ----------- */ - int use_module_search_paths; /* If non-zero, use module_search_paths */ - _PyWstrList module_search_paths; /* sys.path paths. Computed if - use_module_search_paths is equal + int module_search_paths_set; /* If non-zero, use module_search_paths */ + PyWideStringList module_search_paths; /* sys.path paths. Computed if + module_search_paths_set is equal to zero. */ wchar_t *executable; /* sys.executable */ @@ -384,48 +397,28 @@ typedef struct { Needed by freeze_importlib. */ int _install_importlib; - /* Value of the --check-hash-based-pycs command line option: - - - "default" means the 'check_source' flag in hash-based pycs - determines invalidation - - "always" causes the interpreter to hash the source file for - invalidation regardless of value of 'check_source' bit - - "never" causes the interpreter to always assume hash-based pycs are - valid - - The default value is "default". - - See PEP 552 "Deterministic pycs" for more details. */ - wchar_t *check_hash_pycs_mode; - - /* If greater than 0, suppress _PyPathConfig_Calculate() warnings on Unix. - The parameter has no effect on Windows. - - If set to -1 (default), inherit !Py_FrozenFlag value. */ - int pathconfig_warnings; - /* If equal to 0, stop Python initialization before the "main" phase */ int _init_main; -} _PyCoreConfig; +} PyConfig; -PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config); -PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetString( - _PyCoreConfig *config, +PyAPI_FUNC(PyStatus) PyConfig_InitPythonConfig(PyConfig *config); +PyAPI_FUNC(PyStatus) PyConfig_InitIsolatedConfig(PyConfig *config); +PyAPI_FUNC(void) PyConfig_Clear(PyConfig *); +PyAPI_FUNC(PyStatus) PyConfig_SetString( + PyConfig *config, wchar_t **config_str, const wchar_t *str); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_DecodeLocale( - _PyCoreConfig *config, +PyAPI_FUNC(PyStatus) PyConfig_SetBytesString( + PyConfig *config, wchar_t **config_str, const char *str); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetArgv( - _PyCoreConfig *config, +PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config); +PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv( + PyConfig *config, Py_ssize_t argc, char * const *argv); -PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetWideArgv(_PyCoreConfig *config, +PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv); diff --git a/Include/cpython/pylifecycle.h b/Include/cpython/pylifecycle.h index ba56664..2f3a0db 100644 --- a/Include/cpython/pylifecycle.h +++ b/Include/cpython/pylifecycle.h @@ -14,14 +14,14 @@ PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, /* PEP 432 Multi-phase initialization API (Private while provisional!) */ -PyAPI_FUNC(_PyInitError) _Py_PreInitialize( - const _PyPreConfig *src_config); -PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromArgs( - const _PyPreConfig *src_config, +PyAPI_FUNC(PyStatus) Py_PreInitialize( + const PyPreConfig *src_config); +PyAPI_FUNC(PyStatus) Py_PreInitializeFromBytesArgs( + const PyPreConfig *src_config, Py_ssize_t argc, char **argv); -PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromWideArgs( - const _PyPreConfig *src_config, +PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs( + const PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv); @@ -30,22 +30,22 @@ PyAPI_FUNC(int) _Py_IsCoreInitialized(void); /* Initialization and finalization */ -PyAPI_FUNC(_PyInitError) _Py_InitializeFromConfig( - const _PyCoreConfig *config); -PyAPI_FUNC(_PyInitError) _Py_InitializeFromArgs( - const _PyCoreConfig *config, +PyAPI_FUNC(PyStatus) Py_InitializeFromConfig( + const PyConfig *config); +PyAPI_FUNC(PyStatus) _Py_InitializeFromArgs( + const PyConfig *config, Py_ssize_t argc, char * const *argv); -PyAPI_FUNC(_PyInitError) _Py_InitializeFromWideArgs( - const _PyCoreConfig *config, +PyAPI_FUNC(PyStatus) _Py_InitializeFromWideArgs( + const PyConfig *config, Py_ssize_t argc, wchar_t * const *argv); -PyAPI_FUNC(_PyInitError) _Py_InitializeMain(void); +PyAPI_FUNC(PyStatus) _Py_InitializeMain(void); -PyAPI_FUNC(int) _Py_RunMain(void); +PyAPI_FUNC(int) Py_RunMain(void); -PyAPI_FUNC(void) _Py_NO_RETURN _Py_ExitInitError(_PyInitError err); +PyAPI_FUNC(void) _Py_NO_RETURN Py_ExitStatusException(PyStatus err); /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level * exit functions. diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 94331f3..6b7663f 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -6,13 +6,11 @@ extern "C" { #endif -#include "cpython/coreconfig.h" +#include "cpython/initconfig.h" PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int); -PyAPI_FUNC(_PyCoreConfig *) _PyInterpreterState_GetCoreConfig(PyInterpreterState *); - PyAPI_FUNC(PyObject *) _PyInterpreterState_GetMainModule(PyInterpreterState *); /* State unique per thread */ |