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()
This commit is contained in:
Victor Stinner 2019-05-27 16:39:22 +02:00 committed by GitHub
parent 8cd5165ba0
commit 331a6a56e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 3229 additions and 2165 deletions

View File

@ -21,6 +21,7 @@ document the API functions in detail.
abstract.rst
concrete.rst
init.rst
init_config.rst
memory.rst
objimpl.rst
apiabiversion.rst

1018
Doc/c-api/init_config.rst Normal file

File diff suppressed because it is too large Load Diff

View File

@ -42,6 +42,13 @@ the same library that the Python runtime is using.
``Py_InspectFlag`` is not set.
.. c:function:: int Py_BytesMain(int argc, char **argv)
Similar to :c:func:`Py_Main` but *argv* is an array of bytes strings.
.. versionadded:: 3.8
.. c:function:: int PyRun_AnyFile(FILE *fp, const char *filename)
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving

View File

@ -182,6 +182,61 @@ Would print ``x*9 + 15=42``.
(Contributed by Eric V. Smith and Larry Hastings in :issue:`36817`.)
PEP 587: Python Initialization Configuration
--------------------------------------------
The :pep:`587` adds a new C API to configure the Python Initialization
providing finer control on the whole configuration and better error reporting.
New structures:
* :c:type:`PyConfig`
* :c:type:`PyPreConfig`
* :c:type:`PyStatus`
* :c:type:`PyWideStringList`
New functions:
* :c:func:`PyConfig_Clear`
* :c:func:`PyConfig_InitIsolatedConfig`
* :c:func:`PyConfig_InitPythonConfig`
* :c:func:`PyConfig_Read`
* :c:func:`PyConfig_SetArgv`
* :c:func:`PyConfig_SetBytesArgv`
* :c:func:`PyConfig_SetBytesString`
* :c:func:`PyConfig_SetString`
* :c:func:`PyPreConfig_InitIsolatedConfig`
* :c:func:`PyPreConfig_InitPythonConfig`
* :c:func:`PyStatus_Error`
* :c:func:`PyStatus_Exception`
* :c:func:`PyStatus_Exit`
* :c:func:`PyStatus_IsError`
* :c:func:`PyStatus_IsExit`
* :c:func:`PyStatus_NoMemory`
* :c:func:`PyStatus_Ok`
* :c:func:`PyWideStringList_Append`
* :c:func:`PyWideStringList_Insert`
* :c:func:`Py_BytesMain`
* :c:func:`Py_ExitStatusException`
* :c:func:`Py_InitializeFromConfig`
* :c:func:`Py_PreInitialize`
* :c:func:`Py_PreInitializeFromArgs`
* :c:func:`Py_PreInitializeFromBytesArgs`
* :c:func:`Py_RunMain`
This PEP also adds ``_PyRuntimeState.preconfig`` (:c:type:`PyPreConfig` type)
and ``PyInterpreterState.config`` (:c:type:`PyConfig` type) fields to these
internal structures. ``PyInterpreterState.config`` becomes the new
reference configuration, replacing global configuration variables and
other private variables.
See :ref:`Python Initialization Configuration <init-config>` for the
documentation.
See :pep:`587` for a full description.
(Contributed by Victor Stinner in :issue:`36763`.)
Other Language Changes
======================

View File

@ -129,7 +129,7 @@
#include "codecs.h"
#include "pyerrors.h"
#include "cpython/coreconfig.h"
#include "cpython/initconfig.h"
#include "pystate.h"
#include "context.h"

View File

@ -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);

View File

@ -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.

View File

@ -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 */

View File

@ -1,163 +0,0 @@
#ifndef Py_INTERNAL_CORECONFIG_H
#define Py_INTERNAL_CORECONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_pystate.h" /* _PyRuntimeState */
/* --- _PyInitError ----------------------------------------------- */
/* Almost all errors causing Python initialization to fail */
#ifdef _MSC_VER
/* Visual Studio 2015 doesn't implement C99 __func__ in C */
# define _Py_INIT_GET_FUNC() __FUNCTION__
#else
# define _Py_INIT_GET_FUNC() __func__
#endif
#define _Py_INIT_OK() \
(_PyInitError){._type = _Py_INIT_ERR_TYPE_OK,}
/* other fields are set to 0 */
#define _Py_INIT_ERR(ERR_MSG) \
(_PyInitError){ \
._type = _Py_INIT_ERR_TYPE_ERROR, \
._func = _Py_INIT_GET_FUNC(), \
.err_msg = (ERR_MSG)}
/* other fields are set to 0 */
#define _Py_INIT_NO_MEMORY() _Py_INIT_ERR("memory allocation failed")
#define _Py_INIT_EXIT(EXITCODE) \
(_PyInitError){ \
._type = _Py_INIT_ERR_TYPE_EXIT, \
.exitcode = (EXITCODE)}
#define _Py_INIT_IS_ERROR(err) \
(err._type == _Py_INIT_ERR_TYPE_ERROR)
#define _Py_INIT_IS_EXIT(err) \
(err._type == _Py_INIT_ERR_TYPE_EXIT)
#define _Py_INIT_FAILED(err) \
(err._type != _Py_INIT_ERR_TYPE_OK)
/* --- _PyWstrList ------------------------------------------------ */
#define _PyWstrList_INIT (_PyWstrList){.length = 0, .items = NULL}
#ifndef NDEBUG
PyAPI_FUNC(int) _PyWstrList_CheckConsistency(const _PyWstrList *list);
#endif
PyAPI_FUNC(void) _PyWstrList_Clear(_PyWstrList *list);
PyAPI_FUNC(int) _PyWstrList_Copy(_PyWstrList *list,
const _PyWstrList *list2);
PyAPI_FUNC(int) _PyWstrList_Append(_PyWstrList *list,
const wchar_t *item);
PyAPI_FUNC(PyObject*) _PyWstrList_AsList(const _PyWstrList *list);
PyAPI_FUNC(int) _PyWstrList_Extend(_PyWstrList *list,
const _PyWstrList *list2);
/* --- _PyArgv ---------------------------------------------------- */
typedef struct {
Py_ssize_t argc;
int use_bytes_argv;
char * const *bytes_argv;
wchar_t * const *wchar_argv;
} _PyArgv;
PyAPI_FUNC(_PyInitError) _PyArgv_AsWstrList(const _PyArgv *args,
_PyWstrList *list);
/* --- Helper functions ------------------------------------------- */
PyAPI_FUNC(int) _Py_str_to_int(
const char *str,
int *result);
PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
const _PyWstrList *xoptions,
const wchar_t *name);
PyAPI_FUNC(const char*) _Py_GetEnv(
int use_environment,
const char *name);
PyAPI_FUNC(void) _Py_get_env_flag(
int use_environment,
int *flag,
const char *name);
/* Py_GetArgcArgv() helper */
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
/* --- _PyPreCmdline ------------------------------------------------- */
typedef struct {
_PyWstrList argv;
_PyWstrList xoptions; /* "-X value" option */
int isolated; /* -I option */
int use_environment; /* -E option */
int dev_mode; /* -X dev and PYTHONDEVMODE */
} _PyPreCmdline;
#define _PyPreCmdline_INIT \
(_PyPreCmdline){ \
.use_environment = -1, \
.isolated = -1, \
.dev_mode = -1}
/* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
PyAPI_FUNC(void) _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
PyAPI_FUNC(_PyInitError) _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
const _PyArgv *args);
PyAPI_FUNC(int) _PyPreCmdline_SetCoreConfig(
const _PyPreCmdline *cmdline,
_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyPreCmdline_Read(_PyPreCmdline *cmdline,
const _PyPreConfig *preconfig);
/* --- _PyPreConfig ----------------------------------------------- */
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(_PyPreConfig *config);
PyAPI_FUNC(void) _PyPreConfig_InitFromCoreConfig(
_PyPreConfig *config,
const _PyCoreConfig *coreconfig);
PyAPI_FUNC(void) _PyPreConfig_InitFromPreConfig(
_PyPreConfig *config,
const _PyPreConfig *config2);
PyAPI_FUNC(void) _PyPreConfig_Copy(_PyPreConfig *config,
const _PyPreConfig *config2);
PyAPI_FUNC(PyObject*) _PyPreConfig_AsDict(const _PyPreConfig *config);
PyAPI_FUNC(void) _PyPreConfig_GetCoreConfig(_PyPreConfig *config,
const _PyCoreConfig *core_config);
PyAPI_FUNC(_PyInitError) _PyPreConfig_Read(_PyPreConfig *config,
const _PyArgv *args);
PyAPI_FUNC(_PyInitError) _PyPreConfig_Write(const _PyPreConfig *config);
/* --- _PyCoreConfig ---------------------------------------------- */
PyAPI_FUNC(void) _PyCoreConfig_InitCompatConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Copy(
_PyCoreConfig *config,
const _PyCoreConfig *config2);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
const _PyCoreConfig *config);
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config,
_PyRuntimeState *runtime);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPyArgv(
_PyCoreConfig *config,
const _PyArgv *args);
/* --- Function used for testing ---------------------------------- */
PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_CORECONFIG_H */

View File

@ -0,0 +1,168 @@
#ifndef Py_INTERNAL_CORECONFIG_H
#define Py_INTERNAL_CORECONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_pystate.h" /* _PyRuntimeState */
/* --- PyStatus ----------------------------------------------- */
/* Almost all errors causing Python initialization to fail */
#ifdef _MSC_VER
/* Visual Studio 2015 doesn't implement C99 __func__ in C */
# define _PyStatus_GET_FUNC() __FUNCTION__
#else
# define _PyStatus_GET_FUNC() __func__
#endif
#define _PyStatus_OK() \
(PyStatus){._type = _PyStatus_TYPE_OK,}
/* other fields are set to 0 */
#define _PyStatus_ERR(ERR_MSG) \
(PyStatus){ \
._type = _PyStatus_TYPE_ERROR, \
.func = _PyStatus_GET_FUNC(), \
.err_msg = (ERR_MSG)}
/* other fields are set to 0 */
#define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
#define _PyStatus_EXIT(EXITCODE) \
(PyStatus){ \
._type = _PyStatus_TYPE_EXIT, \
.exitcode = (EXITCODE)}
#define _PyStatus_IS_ERROR(err) \
(err._type == _PyStatus_TYPE_ERROR)
#define _PyStatus_IS_EXIT(err) \
(err._type == _PyStatus_TYPE_EXIT)
#define _PyStatus_EXCEPTION(err) \
(err._type != _PyStatus_TYPE_OK)
/* --- PyWideStringList ------------------------------------------------ */
#define PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
#ifndef NDEBUG
PyAPI_FUNC(int) _PyWideStringList_CheckConsistency(const PyWideStringList *list);
#endif
PyAPI_FUNC(void) _PyWideStringList_Clear(PyWideStringList *list);
PyAPI_FUNC(int) _PyWideStringList_Copy(PyWideStringList *list,
const PyWideStringList *list2);
PyAPI_FUNC(PyStatus) _PyWideStringList_Extend(PyWideStringList *list,
const PyWideStringList *list2);
PyAPI_FUNC(PyObject*) _PyWideStringList_AsList(const PyWideStringList *list);
/* --- _PyArgv ---------------------------------------------------- */
typedef struct {
Py_ssize_t argc;
int use_bytes_argv;
char * const *bytes_argv;
wchar_t * const *wchar_argv;
} _PyArgv;
PyAPI_FUNC(PyStatus) _PyArgv_AsWstrList(const _PyArgv *args,
PyWideStringList *list);
/* --- Helper functions ------------------------------------------- */
PyAPI_FUNC(int) _Py_str_to_int(
const char *str,
int *result);
PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
const PyWideStringList *xoptions,
const wchar_t *name);
PyAPI_FUNC(const char*) _Py_GetEnv(
int use_environment,
const char *name);
PyAPI_FUNC(void) _Py_get_env_flag(
int use_environment,
int *flag,
const char *name);
/* Py_GetArgcArgv() helper */
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
/* --- _PyPreCmdline ------------------------------------------------- */
typedef struct {
PyWideStringList argv;
PyWideStringList xoptions; /* "-X value" option */
int isolated; /* -I option */
int use_environment; /* -E option */
int dev_mode; /* -X dev and PYTHONDEVMODE */
} _PyPreCmdline;
#define _PyPreCmdline_INIT \
(_PyPreCmdline){ \
.use_environment = -1, \
.isolated = -1, \
.dev_mode = -1}
/* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
extern PyStatus _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
const _PyArgv *args);
extern PyStatus _PyPreCmdline_SetConfig(
const _PyPreCmdline *cmdline,
PyConfig *config);
extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
const PyPreConfig *preconfig);
/* --- PyPreConfig ----------------------------------------------- */
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
extern void _PyPreConfig_InitFromConfig(
PyPreConfig *preconfig,
const PyConfig *config);
extern void _PyPreConfig_InitFromPreConfig(
PyPreConfig *preconfig,
const PyPreConfig *config2);
extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig);
extern void _PyPreConfig_GetConfig(PyPreConfig *preconfig,
const PyConfig *config);
extern PyStatus _PyPreConfig_Read(PyPreConfig *preconfig,
const _PyArgv *args);
extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig);
/* --- PyConfig ---------------------------------------------- */
#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;
PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
extern PyStatus _PyConfig_Copy(
PyConfig *config,
const PyConfig *config2);
extern PyStatus _PyConfig_InitPathConfig(PyConfig *config);
extern PyStatus _PyConfig_SetPathConfig(
const PyConfig *config);
extern void _PyConfig_Write(const PyConfig *config,
_PyRuntimeState *runtime);
extern PyStatus _PyConfig_SetPyArgv(
PyConfig *config,
const _PyArgv *args);
/* --- Function used for testing ---------------------------------- */
PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_CORECONFIG_H */

View File

@ -37,17 +37,17 @@ typedef struct _PyPathConfig {
PyAPI_DATA(_PyPathConfig) _Py_path_config;
PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
const struct _PyPathConfig *config);
extern void _PyPathConfig_ClearGlobal(void);
extern PyStatus _PyPathConfig_SetGlobal(
const struct _PyPathConfig *pathconfig);
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
_PyPathConfig *config,
const _PyCoreConfig *core_config);
PyAPI_FUNC(int) _PyPathConfig_ComputeSysPath0(
const _PyWstrList *argv,
extern PyStatus _PyPathConfig_Calculate(
_PyPathConfig *pathconfig,
const PyConfig *config);
extern int _PyPathConfig_ComputeSysPath0(
const PyWideStringList *argv,
PyObject **path0);
PyAPI_FUNC(int) _Py_FindEnvConfigValue(
extern int _Py_FindEnvConfigValue(
FILE *env_file,
const wchar_t *key,
wchar_t *value,

View File

@ -8,20 +8,20 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_coreconfig.h" /* _PyArgv */
#include "pycore_initconfig.h" /* _PyArgv */
#include "pycore_pystate.h" /* _PyRuntimeState */
/* True if the main interpreter thread exited due to an unhandled
* KeyboardInterrupt exception, suggesting the user pressed ^C. */
PyAPI_DATA(int) _Py_UnhandledKeyboardInterrupt;
PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv);
extern int _Py_SetFileSystemEncoding(
const char *encoding,
const char *errors);
extern void _Py_ClearFileSystemEncoding(void);
extern _PyInitError _PyUnicode_InitEncodings(PyInterpreterState *interp);
extern PyStatus _PyUnicode_InitEncodings(PyInterpreterState *interp);
#ifdef MS_WINDOWS
extern int _PyUnicode_EnableLegacyWindowsFSEncoding(void);
#endif
@ -32,30 +32,30 @@ PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);
/* Various one-time initializers */
extern _PyInitError _PyUnicode_Init(void);
extern PyStatus _PyUnicode_Init(void);
extern int _PyStructSequence_Init(void);
extern int _PyLong_Init(void);
extern _PyInitError _PyFaulthandler_Init(int enable);
extern PyStatus _PyFaulthandler_Init(int enable);
extern int _PyTraceMalloc_Init(int enable);
extern PyObject * _PyBuiltin_Init(void);
extern _PyInitError _PySys_Create(
extern PyStatus _PySys_Create(
_PyRuntimeState *runtime,
PyInterpreterState *interp,
PyObject **sysmod_p);
extern _PyInitError _PySys_SetPreliminaryStderr(PyObject *sysdict);
extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict);
extern int _PySys_InitMain(
_PyRuntimeState *runtime,
PyInterpreterState *interp);
extern _PyInitError _PyImport_Init(PyInterpreterState *interp);
extern _PyInitError _PyExc_Init(void);
extern _PyInitError _PyErr_Init(void);
extern _PyInitError _PyBuiltins_AddExceptions(PyObject * bltinmod);
extern _PyInitError _PyImportHooks_Init(void);
extern PyStatus _PyImport_Init(PyInterpreterState *interp);
extern PyStatus _PyExc_Init(void);
extern PyStatus _PyErr_Init(void);
extern PyStatus _PyBuiltins_AddExceptions(PyObject * bltinmod);
extern PyStatus _PyImportHooks_Init(void);
extern int _PyFloat_Init(void);
extern _PyInitError _Py_HashRandomization_Init(const _PyCoreConfig *);
extern PyStatus _Py_HashRandomization_Init(const PyConfig *);
extern _PyInitError _PyTypes_Init(void);
extern _PyInitError _PyImportZip_Init(PyInterpreterState *interp);
extern PyStatus _PyTypes_Init(void);
extern PyStatus _PyImportZip_Init(PyInterpreterState *interp);
/* Various internal finalizers */
@ -94,11 +94,11 @@ extern void _PyGILState_Fini(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(_PyRuntimeState *runtime);
PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromPyArgv(
const _PyPreConfig *src_config,
PyAPI_FUNC(PyStatus) _Py_PreInitializeFromPyArgv(
const PyPreConfig *src_config,
const _PyArgv *args);
PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromCoreConfig(
const _PyCoreConfig *coreconfig,
PyAPI_FUNC(PyStatus) _Py_PreInitializeFromConfig(
const PyConfig *config,
const _PyArgv *args);

View File

@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
#include "cpython/coreconfig.h"
#include "cpython/initconfig.h"
#include "fileobject.h"
#include "pystate.h"
#include "pythread.h"
@ -106,7 +106,7 @@ struct _is {
_Py_error_handler error_handler;
} fs_codec;
_PyCoreConfig core_config;
PyConfig config;
#ifdef HAVE_DLOPEN
int dlopenflags;
#endif
@ -193,7 +193,7 @@ struct _gilstate_runtime_state {
/* Full Python runtime state */
typedef struct pyruntimestate {
/* Is Python pre-initialized? Set to 1 by _Py_PreInitialize() */
/* Is Python pre-initialized? Set to 1 by Py_PreInitialize() */
int pre_initialized;
/* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
@ -234,7 +234,7 @@ typedef struct pyruntimestate {
struct _ceval_runtime_state ceval;
struct _gilstate_runtime_state gilstate;
_PyPreConfig preconfig;
PyPreConfig preconfig;
Py_OpenCodeHookFunction open_code_hook;
void *open_code_userdata;
@ -248,13 +248,13 @@ typedef struct pyruntimestate {
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
PyAPI_DATA(_PyRuntimeState) _PyRuntime;
PyAPI_FUNC(_PyInitError) _PyRuntimeState_Init(_PyRuntimeState *runtime);
PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
/* Initialize _PyRuntimeState.
Return NULL on success, or return an error message on failure. */
PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void);
PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void);
PyAPI_FUNC(void) _PyRuntime_Finalize(void);
@ -307,7 +307,7 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
struct _gilstate_runtime_state *gilstate,
PyThreadState *newts);
PyAPI_FUNC(_PyInitError) _PyInterpreterState_Enable(_PyRuntimeState *runtime);
PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyGILState_Reinit(_PyRuntimeState *runtime);

View File

@ -272,7 +272,7 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
def test_run_main(self):
out, err = self.run_embedded_interpreter("test_run_main")
self.assertEqual(out.rstrip(), "_Py_RunMain(): sys.argv=['-c', 'arg2']")
self.assertEqual(out.rstrip(), "Py_RunMain(): sys.argv=['-c', 'arg2']")
self.assertEqual(err, '')
@ -321,7 +321,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'use_environment',
]
CORE_CONFIG_COMPAT = {
CONFIG_COMPAT = {
'_config_init': API_COMPAT,
'isolated': 0,
'use_environment': 1,
@ -349,7 +349,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'xoptions': [],
'warnoptions': [],
'module_search_path_env': None,
'pythonpath_env': None,
'home': None,
'executable': GET_DEFAULT_CONFIG,
@ -386,16 +386,16 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'_init_main': 1,
}
if MS_WINDOWS:
CORE_CONFIG_COMPAT.update({
CONFIG_COMPAT.update({
'legacy_windows_stdio': 0,
})
CORE_CONFIG_PYTHON = dict(CORE_CONFIG_COMPAT,
CONFIG_PYTHON = dict(CONFIG_COMPAT,
_config_init=API_PYTHON,
configure_c_stdio=1,
parse_argv=1,
)
CORE_CONFIG_ISOLATED = dict(CORE_CONFIG_COMPAT,
CONFIG_ISOLATED = dict(CONFIG_COMPAT,
_config_init=API_ISOLATED,
isolated=1,
use_environment=0,
@ -408,7 +408,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
pathconfig_warnings=0,
)
if MS_WINDOWS:
CORE_CONFIG_ISOLATED['legacy_windows_stdio'] = 0
CONFIG_ISOLATED['legacy_windows_stdio'] = 0
# global config
DEFAULT_GLOBAL_CONFIG = {
@ -535,12 +535,12 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
if expected['program_name'] is self.GET_DEFAULT_CONFIG:
expected['program_name'] = './_testembed'
core_config = configs['core_config']
config = configs['config']
for key, value in expected.items():
if value is self.GET_DEFAULT_CONFIG:
expected[key] = core_config[key]
expected[key] = config[key]
prepend_path = expected['module_search_path_env']
prepend_path = expected['pythonpath_env']
if prepend_path is not None:
expected['module_search_paths'] = [prepend_path, *expected['module_search_paths']]
if add_path is not None:
@ -550,34 +550,34 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
if key not in expected_preconfig:
expected_preconfig[key] = expected[key]
def check_pre_config(self, config, expected):
pre_config = dict(config['pre_config'])
def check_pre_config(self, configs, expected):
pre_config = dict(configs['pre_config'])
for key, value in list(expected.items()):
if value is self.IGNORE_CONFIG:
del pre_config[key]
del expected[key]
self.assertEqual(pre_config, expected)
def check_core_config(self, config, expected):
core_config = dict(config['core_config'])
def check_config(self, configs, expected):
config = dict(configs['config'])
for key, value in list(expected.items()):
if value is self.IGNORE_CONFIG:
del core_config[key]
del config[key]
del expected[key]
self.assertEqual(core_config, expected)
self.assertEqual(config, expected)
def check_global_config(self, config):
pre_config = config['pre_config']
core_config = config['core_config']
def check_global_config(self, configs):
pre_config = configs['pre_config']
config = configs['config']
expected = dict(self.DEFAULT_GLOBAL_CONFIG)
for item in self.COPY_GLOBAL_CONFIG:
if len(item) == 3:
global_key, core_key, opposite = item
expected[global_key] = 0 if core_config[core_key] else 1
expected[global_key] = 0 if config[core_key] else 1
else:
global_key, core_key = item
expected[global_key] = core_config[core_key]
expected[global_key] = config[core_key]
for item in self.COPY_GLOBAL_PRE_CONFIG:
if len(item) == 3:
global_key, core_key, opposite = item
@ -586,9 +586,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
global_key, core_key = item
expected[global_key] = pre_config[core_key]
self.assertEqual(config['global_config'], expected)
self.assertEqual(configs['global_config'], expected)
def check_config(self, testname, expected_config=None,
def check_all_configs(self, testname, expected_config=None,
expected_preconfig=None, add_path=None, stderr=None,
*, api):
env = dict(os.environ)
@ -610,11 +610,11 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
expected_config = {}
if api == API_PYTHON:
default_config = self.CORE_CONFIG_PYTHON
default_config = self.CONFIG_PYTHON
elif api == API_ISOLATED:
default_config = self.CORE_CONFIG_ISOLATED
default_config = self.CONFIG_ISOLATED
else:
default_config = self.CORE_CONFIG_COMPAT
default_config = self.CONFIG_COMPAT
expected_config = dict(default_config, **expected_config)
self.get_expected_config(expected_preconfig,
@ -627,22 +627,22 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
if stderr is not None:
self.assertEqual(err.rstrip(), stderr)
try:
config = json.loads(out)
configs = json.loads(out)
except json.JSONDecodeError:
self.fail(f"fail to decode stdout: {out!r}")
self.check_pre_config(config, expected_preconfig)
self.check_core_config(config, expected_config)
self.check_global_config(config)
self.check_pre_config(configs, expected_preconfig)
self.check_config(configs, expected_config)
self.check_global_config(configs)
def test_init_default_config(self):
self.check_config("test_init_initialize_config", api=API_COMPAT)
self.check_all_configs("test_init_initialize_config", api=API_COMPAT)
def test_preinit_compat_config(self):
self.check_config("test_preinit_compat_config", api=API_COMPAT)
self.check_all_configs("test_preinit_compat_config", api=API_COMPAT)
def test_init_compat_config(self):
self.check_config("test_init_compat_config", api=API_COMPAT)
self.check_all_configs("test_init_compat_config", api=API_COMPAT)
def test_init_global_config(self):
preconfig = {
@ -664,8 +664,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'user_site_directory': 0,
'pathconfig_warnings': 0,
}
self.check_config("test_init_global_config", config, preconfig,
api=API_COMPAT)
self.check_all_configs("test_init_global_config", config, preconfig,
api=API_COMPAT)
def test_init_from_config(self):
preconfig = {
@ -689,7 +689,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'program_name': './conf_program_name',
'argv': ['-c', 'arg2'],
'parse_argv': 1,
'xoptions': ['core_xoption1=3', 'core_xoption2=', 'core_xoption3'],
'xoptions': ['xoption1=3', 'xoption2=', 'xoption3'],
'warnoptions': ['error::ResourceWarning', 'default::BytesWarning'],
'run_command': 'pass\n',
@ -709,8 +709,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'check_hash_pycs_mode': 'always',
'pathconfig_warnings': 0,
}
self.check_config("test_init_from_config", config, preconfig,
api=API_COMPAT)
self.check_all_configs("test_init_from_config", config, preconfig,
api=API_COMPAT)
def test_init_compat_env(self):
preconfig = {
@ -724,7 +724,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'malloc_stats': 1,
'inspect': 1,
'optimization_level': 2,
'module_search_path_env': '/my/path',
'pythonpath_env': '/my/path',
'pycache_prefix': 'env_pycache_prefix',
'write_bytecode': 0,
'verbose': 1,
@ -735,8 +735,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'faulthandler': 1,
'warnoptions': ['EnvVar'],
}
self.check_config("test_init_compat_env", config, preconfig,
api=API_COMPAT)
self.check_all_configs("test_init_compat_env", config, preconfig,
api=API_COMPAT)
def test_init_python_env(self):
preconfig = {
@ -751,7 +751,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'malloc_stats': 1,
'inspect': 1,
'optimization_level': 2,
'module_search_path_env': '/my/path',
'pythonpath_env': '/my/path',
'pycache_prefix': 'env_pycache_prefix',
'write_bytecode': 0,
'verbose': 1,
@ -762,24 +762,24 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'faulthandler': 1,
'warnoptions': ['EnvVar'],
}
self.check_config("test_init_python_env", config, preconfig,
api=API_PYTHON)
self.check_all_configs("test_init_python_env", config, preconfig,
api=API_PYTHON)
def test_init_env_dev_mode(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_DEBUG)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
self.check_config("test_init_env_dev_mode", config, preconfig,
api=API_COMPAT)
self.check_all_configs("test_init_env_dev_mode", config, preconfig,
api=API_COMPAT)
def test_init_env_dev_mode_alloc(self):
preconfig = dict(allocator=PYMEM_ALLOCATOR_MALLOC)
config = dict(dev_mode=1,
faulthandler=1,
warnoptions=['default'])
self.check_config("test_init_env_dev_mode_alloc", config, preconfig,
api=API_COMPAT)
self.check_all_configs("test_init_env_dev_mode_alloc", config, preconfig,
api=API_COMPAT)
def test_init_dev_mode(self):
preconfig = {
@ -790,8 +790,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'dev_mode': 1,
'warnoptions': ['default'],
}
self.check_config("test_init_dev_mode", config, preconfig,
api=API_PYTHON)
self.check_all_configs("test_init_dev_mode", config, preconfig,
api=API_PYTHON)
def test_preinit_parse_argv(self):
# Pre-initialize implicitly using argv: make sure that -X dev
@ -807,8 +807,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'warnoptions': ['default'],
'xoptions': ['dev'],
}
self.check_config("test_preinit_parse_argv", config, preconfig,
api=API_PYTHON)
self.check_all_configs("test_preinit_parse_argv", config, preconfig,
api=API_PYTHON)
def test_preinit_dont_parse_argv(self):
# -X dev must be ignored by isolated preconfiguration
@ -820,8 +820,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
"-X", "dev", "-X", "utf8", "script.py"],
'isolated': 0,
}
self.check_config("test_preinit_dont_parse_argv", config, preconfig,
api=API_ISOLATED)
self.check_all_configs("test_preinit_dont_parse_argv", config, preconfig,
api=API_ISOLATED)
def test_init_isolated_flag(self):
config = {
@ -829,7 +829,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("test_init_isolated_flag", config, api=API_PYTHON)
self.check_all_configs("test_init_isolated_flag", config, api=API_PYTHON)
def test_preinit_isolated1(self):
# _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
@ -838,7 +838,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("test_preinit_isolated1", config, api=API_COMPAT)
self.check_all_configs("test_preinit_isolated1", config, api=API_COMPAT)
def test_preinit_isolated2(self):
# _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
@ -847,19 +847,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'use_environment': 0,
'user_site_directory': 0,
}
self.check_config("test_preinit_isolated2", config, api=API_COMPAT)
self.check_all_configs("test_preinit_isolated2", config, api=API_COMPAT)
def test_preinit_isolated_config(self):
self.check_config("test_preinit_isolated_config", api=API_ISOLATED)
self.check_all_configs("test_preinit_isolated_config", api=API_ISOLATED)
def test_init_isolated_config(self):
self.check_config("test_init_isolated_config", api=API_ISOLATED)
self.check_all_configs("test_init_isolated_config", api=API_ISOLATED)
def test_preinit_python_config(self):
self.check_config("test_preinit_python_config", api=API_PYTHON)
self.check_all_configs("test_preinit_python_config", api=API_PYTHON)
def test_init_python_config(self):
self.check_config("test_init_python_config", api=API_PYTHON)
self.check_all_configs("test_init_python_config", api=API_PYTHON)
def test_init_dont_configure_locale(self):
# _PyPreConfig.configure_locale=0
@ -867,64 +867,64 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'configure_locale': 0,
'coerce_c_locale': 0,
}
self.check_config("test_init_dont_configure_locale", {}, preconfig,
api=API_PYTHON)
self.check_all_configs("test_init_dont_configure_locale", {}, preconfig,
api=API_PYTHON)
def test_init_read_set(self):
core_config = {
config = {
'program_name': './init_read_set',
'executable': 'my_executable',
}
self.check_config("test_init_read_set", core_config,
api=API_PYTHON,
add_path="init_read_set_path")
self.check_all_configs("test_init_read_set", config,
api=API_PYTHON,
add_path="init_read_set_path")
def test_init_run_main(self):
code = ('import _testinternalcapi, json; '
'print(json.dumps(_testinternalcapi.get_configs()))')
core_config = {
config = {
'argv': ['-c', 'arg2'],
'program_name': './python3',
'run_command': code + '\n',
'parse_argv': 1,
}
self.check_config("test_init_run_main", core_config, api=API_PYTHON)
self.check_all_configs("test_init_run_main", config, api=API_PYTHON)
def test_init_main(self):
code = ('import _testinternalcapi, json; '
'print(json.dumps(_testinternalcapi.get_configs()))')
core_config = {
config = {
'argv': ['-c', 'arg2'],
'program_name': './python3',
'run_command': code + '\n',
'parse_argv': 1,
'_init_main': 0,
}
self.check_config("test_init_main", core_config,
api=API_PYTHON,
stderr="Run Python code before _Py_InitializeMain")
self.check_all_configs("test_init_main", config,
api=API_PYTHON,
stderr="Run Python code before _Py_InitializeMain")
def test_init_parse_argv(self):
core_config = {
config = {
'parse_argv': 1,
'argv': ['-c', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
'run_command': 'pass\n',
'use_environment': 0,
}
self.check_config("test_init_parse_argv", core_config, api=API_PYTHON)
self.check_all_configs("test_init_parse_argv", config, api=API_PYTHON)
def test_init_dont_parse_argv(self):
pre_config = {
'parse_argv': 0,
}
core_config = {
config = {
'parse_argv': 0,
'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
}
self.check_config("test_init_dont_parse_argv", core_config, pre_config,
api=API_PYTHON)
self.check_all_configs("test_init_dont_parse_argv", config, pre_config,
api=API_PYTHON)
class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):

View File

@ -322,7 +322,7 @@ PYTHON_OBJS= \
Python/ceval.o \
Python/codecs.o \
Python/compile.o \
Python/coreconfig.o \
Python/context.o \
Python/dynamic_annotations.o \
Python/errors.o \
Python/frozenmain.o \
@ -333,8 +333,10 @@ PYTHON_OBJS= \
Python/getplatform.o \
Python/getversion.o \
Python/graminit.o \
Python/hamt.o \
Python/import.o \
Python/importdl.o \
Python/initconfig.o \
Python/marshal.o \
Python/modsupport.o \
Python/mysnprintf.o \
@ -349,8 +351,6 @@ PYTHON_OBJS= \
Python/pylifecycle.o \
Python/pymath.o \
Python/pystate.o \
Python/context.o \
Python/hamt.o \
Python/pythonrun.o \
Python/pytime.o \
Python/bootstrap_hash.o \
@ -1052,9 +1052,9 @@ PYTHON_HEADERS= \
$(srcdir)/Include/Python-ast.h \
\
$(srcdir)/Include/cpython/abstract.h \
$(srcdir)/Include/cpython/coreconfig.h \
$(srcdir)/Include/cpython/dictobject.h \
$(srcdir)/Include/cpython/fileobject.h \
$(srcdir)/Include/cpython/initconfig.h \
$(srcdir)/Include/cpython/interpreteridobject.h \
$(srcdir)/Include/cpython/object.h \
$(srcdir)/Include/cpython/objimpl.h \
@ -1072,11 +1072,11 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_ceval.h \
$(srcdir)/Include/internal/pycore_condvar.h \
$(srcdir)/Include/internal/pycore_context.h \
$(srcdir)/Include/internal/pycore_coreconfig.h \
$(srcdir)/Include/internal/pycore_fileutils.h \
$(srcdir)/Include/internal/pycore_getopt.h \
$(srcdir)/Include/internal/pycore_gil.h \
$(srcdir)/Include/internal/pycore_hamt.h \
$(srcdir)/Include/internal/pycore_initconfig.h \
$(srcdir)/Include/internal/pycore_object.h \
$(srcdir)/Include/internal/pycore_pathconfig.h \
$(srcdir)/Include/internal/pycore_pyerrors.h \

View File

@ -0,0 +1 @@
Implement the :pep:`587` "Python Initialization Configuration".

View File

@ -377,7 +377,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
{
PyObject *RawIO_class = (PyObject *)&PyFileIO_Type;
#ifdef MS_WINDOWS
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type;
encoding = "utf-8";

View File

@ -288,7 +288,7 @@ iobase_finalize(PyObject *self)
shutdown issues). */
if (res == NULL) {
#ifndef Py_DEBUG
const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
const PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (config->dev_mode) {
PyErr_WriteUnraisable(self);
}

View File

@ -9,7 +9,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
static PyObject *

View File

@ -1,5 +1,5 @@
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_traceback.h"
#include "pythread.h"
#include <signal.h>
@ -1315,7 +1315,7 @@ faulthandler_init_enable(void)
return 0;
}
_PyInitError
PyStatus
_PyFaulthandler_Init(int enable)
{
#ifdef HAVE_SIGALTSTACK
@ -1340,17 +1340,17 @@ _PyFaulthandler_Init(int enable)
thread.cancel_event = PyThread_allocate_lock();
thread.running = PyThread_allocate_lock();
if (!thread.cancel_event || !thread.running) {
return _Py_INIT_ERR("failed to allocate locks for faulthandler");
return _PyStatus_ERR("failed to allocate locks for faulthandler");
}
PyThread_acquire_lock(thread.cancel_event, 1);
#endif
if (enable) {
if (faulthandler_init_enable() < 0) {
return _Py_INIT_ERR("failed to enable faulthandler");
return _PyStatus_ERR("failed to enable faulthandler");
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
void _PyFaulthandler_Fini(void)

View File

@ -1,7 +1,7 @@
/* Return the initial module search path. */
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "osdefs.h"
#include "pycore_fileutils.h"
#include "pycore_pathconfig.h"
@ -115,10 +115,10 @@ extern "C" {
#define DECODE_LOCALE_ERR(NAME, LEN) \
((LEN) == (size_t)-2) \
? _Py_INIT_ERR("cannot decode " NAME) \
: _Py_INIT_NO_MEMORY()
? _PyStatus_ERR("cannot decode " NAME) \
: _PyStatus_NO_MEMORY()
#define PATHLEN_ERR() _Py_INIT_ERR("path configuration: path too long")
#define PATHLEN_ERR() _PyStatus_ERR("path configuration: path too long")
typedef struct {
wchar_t *path_env; /* PATH environment variable */
@ -236,7 +236,7 @@ isdir(wchar_t *filename)
/* Add a path component, by appending stuff to buffer.
buflen: 'buffer' length in characters including trailing NUL. */
static _PyInitError
static PyStatus
joinpath(wchar_t *buffer, const wchar_t *stuff, size_t buflen)
{
size_t n, k;
@ -261,7 +261,7 @@ joinpath(wchar_t *buffer, const wchar_t *stuff, size_t buflen)
wcsncpy(buffer+n, stuff, k);
buffer[n+k] = '\0';
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -280,7 +280,7 @@ safe_wcscpy(wchar_t *dst, const wchar_t *src, size_t n)
/* copy_absolute requires that path be allocated at least
'pathlen' characters (including trailing NUL). */
static _PyInitError
static PyStatus
copy_absolute(wchar_t *path, const wchar_t *p, size_t pathlen)
{
if (p[0] == SEP) {
@ -294,38 +294,38 @@ copy_absolute(wchar_t *path, const wchar_t *p, size_t pathlen)
if (safe_wcscpy(path, p, pathlen) < 0) {
return PATHLEN_ERR();
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
if (p[0] == '.' && p[1] == SEP) {
p += 2;
}
_PyInitError err = joinpath(path, p, pathlen);
if (_Py_INIT_FAILED(err)) {
return err;
PyStatus status = joinpath(path, p, pathlen);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* path_len: path length in characters including trailing NUL */
static _PyInitError
static PyStatus
absolutize(wchar_t *path, size_t path_len)
{
if (path[0] == SEP) {
return _Py_INIT_OK();
return _PyStatus_OK();
}
wchar_t abs_path[MAXPATHLEN+1];
_PyInitError err = copy_absolute(abs_path, path, Py_ARRAY_LENGTH(abs_path));
if (_Py_INIT_FAILED(err)) {
return err;
PyStatus status = copy_absolute(abs_path, path, Py_ARRAY_LENGTH(abs_path));
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (safe_wcscpy(path, abs_path, path_len) < 0) {
return PATHLEN_ERR();
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -335,14 +335,14 @@ absolutize(wchar_t *path, size_t path_len)
#endif
/* pathlen: 'path' length in characters including trailing NUL */
static _PyInitError
static PyStatus
add_exe_suffix(wchar_t *progpath, size_t progpathlen)
{
/* Check for already have an executable suffix */
size_t n = wcslen(progpath);
size_t s = wcslen(EXE_SUFFIX);
if (wcsncasecmp(EXE_SUFFIX, progpath + n - s, s) == 0) {
return _Py_INIT_OK();
return _PyStatus_OK();
}
if (n + s >= progpathlen) {
@ -356,7 +356,7 @@ add_exe_suffix(wchar_t *progpath, size_t progpathlen)
progpath[n] = '\0';
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
#endif
@ -364,43 +364,43 @@ add_exe_suffix(wchar_t *progpath, size_t progpathlen)
/* search_for_prefix requires that argv0_path be no more than MAXPATHLEN
bytes long.
*/
static _PyInitError
search_for_prefix(const _PyCoreConfig *core_config, PyCalculatePath *calculate,
static PyStatus
search_for_prefix(const PyConfig *config, PyCalculatePath *calculate,
wchar_t *prefix, size_t prefix_len,
int *found)
{
_PyInitError err;
PyStatus status;
size_t n;
wchar_t *vpath;
/* If PYTHONHOME is set, we believe it unconditionally */
if (core_config->home) {
if (safe_wcscpy(prefix, core_config->home, prefix_len) < 0) {
if (config->home) {
if (safe_wcscpy(prefix, config->home, prefix_len) < 0) {
return PATHLEN_ERR();
}
wchar_t *delim = wcschr(prefix, DELIM);
if (delim) {
*delim = L'\0';
}
err = joinpath(prefix, calculate->lib_python, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, calculate->lib_python, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(prefix, LANDMARK, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, LANDMARK, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Check to see if argv[0] is in the build directory */
if (safe_wcscpy(prefix, calculate->argv0_path, prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(prefix, L"Modules/Setup.local", prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, L"Modules/Setup.local", prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (isfile(prefix)) {
@ -410,48 +410,48 @@ search_for_prefix(const _PyCoreConfig *core_config, PyCalculatePath *calculate,
if (safe_wcscpy(prefix, calculate->argv0_path, prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(prefix, vpath, prefix_len);
status = joinpath(prefix, vpath, prefix_len);
PyMem_RawFree(vpath);
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(prefix, L"Lib", prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, L"Lib", prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(prefix, LANDMARK, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, LANDMARK, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (ismodule(prefix, prefix_len)) {
*found = -1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
}
}
/* Search from argv0_path, until root is found */
err = copy_absolute(prefix, calculate->argv0_path, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = copy_absolute(prefix, calculate->argv0_path, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
do {
n = wcslen(prefix);
err = joinpath(prefix, calculate->lib_python, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, calculate->lib_python, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(prefix, LANDMARK, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, LANDMARK, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (ismodule(prefix, prefix_len)) {
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
prefix[n] = L'\0';
reduce(prefix);
@ -461,59 +461,59 @@ search_for_prefix(const _PyCoreConfig *core_config, PyCalculatePath *calculate,
if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(prefix, calculate->lib_python, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, calculate->lib_python, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(prefix, LANDMARK, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, LANDMARK, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (ismodule(prefix, prefix_len)) {
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Fail */
*found = 0;
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
calculate_prefix(const _PyCoreConfig *core_config,
static PyStatus
calculate_prefix(const PyConfig *config,
PyCalculatePath *calculate, wchar_t *prefix, size_t prefix_len)
{
_PyInitError err;
PyStatus status;
err = search_for_prefix(core_config, calculate, prefix, prefix_len,
status = search_for_prefix(config, calculate, prefix, prefix_len,
&calculate->prefix_found);
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (!calculate->prefix_found) {
if (core_config->pathconfig_warnings) {
if (config->pathconfig_warnings) {
fprintf(stderr,
"Could not find platform independent libraries <prefix>\n");
}
if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(prefix, calculate->lib_python, prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(prefix, calculate->lib_python, prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
else {
reduce(prefix);
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
static PyStatus
calculate_reduce_prefix(PyCalculatePath *calculate,
wchar_t *prefix, size_t prefix_len)
{
@ -536,45 +536,45 @@ calculate_reduce_prefix(PyCalculatePath *calculate,
return PATHLEN_ERR();
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* search_for_exec_prefix requires that argv0_path be no more than
MAXPATHLEN bytes long.
*/
static _PyInitError
search_for_exec_prefix(const _PyCoreConfig *core_config,
static PyStatus
search_for_exec_prefix(const PyConfig *config,
PyCalculatePath *calculate,
wchar_t *exec_prefix, size_t exec_prefix_len,
int *found)
{
_PyInitError err;
PyStatus status;
size_t n;
/* If PYTHONHOME is set, we believe it unconditionally */
if (core_config->home) {
wchar_t *delim = wcschr(core_config->home, DELIM);
if (config->home) {
wchar_t *delim = wcschr(config->home, DELIM);
if (delim) {
if (safe_wcscpy(exec_prefix, delim+1, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
}
else {
if (safe_wcscpy(exec_prefix, core_config->home, exec_prefix_len) < 0) {
if (safe_wcscpy(exec_prefix, config->home, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
}
err = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Check to see if argv[0] is in the build directory. "pybuilddir.txt"
@ -583,9 +583,9 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
if (safe_wcscpy(exec_prefix, calculate->argv0_path, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(exec_prefix, L"pybuilddir.txt", exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, L"pybuilddir.txt", exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (isfile(exec_prefix)) {
@ -609,36 +609,36 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
if (safe_wcscpy(exec_prefix, calculate->argv0_path, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(exec_prefix, pybuilddir, exec_prefix_len);
status = joinpath(exec_prefix, pybuilddir, exec_prefix_len);
PyMem_RawFree(pybuilddir );
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
*found = -1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
}
/* Search from argv0_path, until root is found */
err = copy_absolute(exec_prefix, calculate->argv0_path, exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = copy_absolute(exec_prefix, calculate->argv0_path, exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
do {
n = wcslen(exec_prefix);
err = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (isdir(exec_prefix)) {
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
exec_prefix[n] = L'\0';
reduce(exec_prefix);
@ -648,58 +648,58 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
if (safe_wcscpy(exec_prefix, calculate->exec_prefix, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, L"lib-dynload", exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (isdir(exec_prefix)) {
*found = 1;
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Fail */
*found = 0;
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
calculate_exec_prefix(const _PyCoreConfig *core_config,
static PyStatus
calculate_exec_prefix(const PyConfig *config,
PyCalculatePath *calculate,
wchar_t *exec_prefix, size_t exec_prefix_len)
{
_PyInitError err;
PyStatus status;
err = search_for_exec_prefix(core_config, calculate,
status = search_for_exec_prefix(config, calculate,
exec_prefix, exec_prefix_len,
&calculate->exec_prefix_found);
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (!calculate->exec_prefix_found) {
if (core_config->pathconfig_warnings) {
if (config->pathconfig_warnings) {
fprintf(stderr,
"Could not find platform dependent libraries <exec_prefix>\n");
}
if (safe_wcscpy(exec_prefix, calculate->exec_prefix, exec_prefix_len) < 0) {
return PATHLEN_ERR();
}
err = joinpath(exec_prefix, L"lib/lib-dynload", exec_prefix_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(exec_prefix, L"lib/lib-dynload", exec_prefix_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
/* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
static PyStatus
calculate_reduce_exec_prefix(PyCalculatePath *calculate,
wchar_t *exec_prefix, size_t exec_prefix_len)
{
@ -716,15 +716,15 @@ calculate_reduce_exec_prefix(PyCalculatePath *calculate,
return PATHLEN_ERR();
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
calculate_program_full_path(const _PyCoreConfig *core_config,
PyCalculatePath *calculate, _PyPathConfig *config)
static PyStatus
calculate_program_full_path(const PyConfig *config,
PyCalculatePath *calculate, _PyPathConfig *pathconfig)
{
_PyInitError err;
PyStatus status;
wchar_t program_full_path[MAXPATHLEN + 1];
const size_t program_full_path_len = Py_ARRAY_LENGTH(program_full_path);
memset(program_full_path, 0, sizeof(program_full_path));
@ -743,8 +743,8 @@ calculate_program_full_path(const _PyCoreConfig *core_config,
* other way to find a directory to start the search from. If
* $PATH isn't exported, you lose.
*/
if (wcschr(core_config->program_name, SEP)) {
if (safe_wcscpy(program_full_path, core_config->program_name,
if (wcschr(config->program_name, SEP)) {
if (safe_wcscpy(program_full_path, config->program_name,
program_full_path_len) < 0) {
return PATHLEN_ERR();
}
@ -795,10 +795,10 @@ calculate_program_full_path(const _PyCoreConfig *core_config,
}
}
err = joinpath(program_full_path, core_config->program_name,
status = joinpath(program_full_path, config->program_name,
program_full_path_len);
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (isxfile(program_full_path)) {
@ -816,9 +816,9 @@ calculate_program_full_path(const _PyCoreConfig *core_config,
program_full_path[0] = '\0';
}
if (program_full_path[0] != SEP && program_full_path[0] != '\0') {
err = absolutize(program_full_path, program_full_path_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = absolutize(program_full_path, program_full_path_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
#if defined(__CYGWIN__) || defined(__MINGW32__)
@ -828,22 +828,22 @@ calculate_program_full_path(const _PyCoreConfig *core_config,
* path (bpo-28441).
*/
if (program_full_path[0] != '\0') {
err = add_exe_suffix(program_full_path, program_full_path_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = add_exe_suffix(program_full_path, program_full_path_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
#endif
config->program_full_path = _PyMem_RawWcsdup(program_full_path);
if (config->program_full_path == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->program_full_path = _PyMem_RawWcsdup(program_full_path);
if (pathconfig->program_full_path == NULL) {
return _PyStatus_NO_MEMORY();
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
static PyStatus
calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_path)
{
const size_t argv0_path_len = Py_ARRAY_LENGTH(calculate->argv0_path);
@ -871,7 +871,7 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
** be running the interpreter in the build directory, so we use the
** build-directory-specific logic to find Lib and such.
*/
_PyInitError err;
PyStatus status;
size_t len;
wchar_t* wbuf = Py_DecodeLocale(modPath, &len);
if (wbuf == NULL) {
@ -882,15 +882,15 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
return PATHLEN_ERR();
}
reduce(calculate->argv0_path);
err = joinpath(calculate->argv0_path, calculate->lib_python, argv0_path_len);
if (_Py_INIT_FAILED(err)) {
status = joinpath(calculate->argv0_path, calculate->lib_python, argv0_path_len);
if (_PyStatus_EXCEPTION(status)) {
PyMem_RawFree(wbuf);
return err;
return status;
}
err = joinpath(calculate->argv0_path, LANDMARK, argv0_path_len);
if (_Py_INIT_FAILED(err)) {
status = joinpath(calculate->argv0_path, LANDMARK, argv0_path_len);
if (_PyStatus_EXCEPTION(status)) {
PyMem_RawFree(wbuf);
return err;
return status;
}
if (!ismodule(calculate->argv0_path,
Py_ARRAY_LENGTH(calculate->argv0_path))) {
@ -925,11 +925,11 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
}
else {
/* Interpret relative to program_full_path */
_PyInitError err;
PyStatus status;
reduce(calculate->argv0_path);
err = joinpath(calculate->argv0_path, tmpbuffer, argv0_path_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(calculate->argv0_path, tmpbuffer, argv0_path_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
linklen = _Py_wreadlink(calculate->argv0_path, tmpbuffer, buflen);
@ -939,7 +939,7 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
reduce(calculate->argv0_path);
/* At this point, argv0_path is guaranteed to be less than
MAXPATHLEN bytes long. */
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -947,10 +947,10 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
executable's directory and then in the parent directory.
If found, open it for use when searching for prefixes.
*/
static _PyInitError
static PyStatus
calculate_read_pyenv(PyCalculatePath *calculate)
{
_PyInitError err;
PyStatus status;
wchar_t tmpbuffer[MAXPATHLEN+1];
const size_t buflen = Py_ARRAY_LENGTH(tmpbuffer);
wchar_t *env_cfg = L"pyvenv.cfg";
@ -960,9 +960,9 @@ calculate_read_pyenv(PyCalculatePath *calculate)
return PATHLEN_ERR();
}
err = joinpath(tmpbuffer, env_cfg, buflen);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(tmpbuffer, env_cfg, buflen);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
env_file = _Py_wfopen(tmpbuffer, L"r");
if (env_file == NULL) {
@ -970,9 +970,9 @@ calculate_read_pyenv(PyCalculatePath *calculate)
reduce(tmpbuffer);
reduce(tmpbuffer);
err = joinpath(tmpbuffer, env_cfg, buflen);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(tmpbuffer, env_cfg, buflen);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
env_file = _Py_wfopen(tmpbuffer, L"r");
@ -982,7 +982,7 @@ calculate_read_pyenv(PyCalculatePath *calculate)
}
if (env_file == NULL) {
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Look for a 'home' variable and set argv0_path to it, if found */
@ -993,14 +993,14 @@ calculate_read_pyenv(PyCalculatePath *calculate)
}
}
fclose(env_file);
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
static PyStatus
calculate_zip_path(PyCalculatePath *calculate, const wchar_t *prefix)
{
_PyInitError err;
PyStatus status;
const size_t zip_path_len = Py_ARRAY_LENGTH(calculate->zip_path);
if (safe_wcscpy(calculate->zip_path, prefix, zip_path_len) < 0) {
return PATHLEN_ERR();
@ -1016,29 +1016,29 @@ calculate_zip_path(PyCalculatePath *calculate, const wchar_t *prefix)
return PATHLEN_ERR();
}
}
err = joinpath(calculate->zip_path, L"lib/python00.zip", zip_path_len);
if (_Py_INIT_FAILED(err)) {
return err;
status = joinpath(calculate->zip_path, L"lib/python00.zip", zip_path_len);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* Replace "00" with version */
size_t bufsz = wcslen(calculate->zip_path);
calculate->zip_path[bufsz - 6] = VERSION[0];
calculate->zip_path[bufsz - 5] = VERSION[2];
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
calculate_module_search_path(const _PyCoreConfig *core_config,
static PyStatus
calculate_module_search_path(const PyConfig *config,
PyCalculatePath *calculate,
const wchar_t *prefix, const wchar_t *exec_prefix,
_PyPathConfig *config)
_PyPathConfig *pathconfig)
{
/* Calculate size of return buffer */
size_t bufsz = 0;
if (core_config->module_search_path_env != NULL) {
bufsz += wcslen(core_config->module_search_path_env) + 1;
if (config->pythonpath_env != NULL) {
bufsz += wcslen(config->pythonpath_env) + 1;
}
wchar_t *defpath = calculate->pythonpath;
@ -1067,13 +1067,13 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
/* Allocate the buffer */
wchar_t *buf = PyMem_RawMalloc(bufsz * sizeof(wchar_t));
if (buf == NULL) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
buf[0] = '\0';
/* Run-time value of $PYTHONPATH goes first */
if (core_config->module_search_path_env) {
wcscpy(buf, core_config->module_search_path_env);
if (config->pythonpath_env) {
wcscpy(buf, config->pythonpath_env);
wcscat(buf, delimiter);
}
@ -1115,14 +1115,14 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
/* Finally, on goes the directory for dynamic-load modules */
wcscat(buf, exec_prefix);
config->module_search_path = buf;
return _Py_INIT_OK();
pathconfig->module_search_path = buf;
return _PyStatus_OK();
}
static _PyInitError
static PyStatus
calculate_init(PyCalculatePath *calculate,
const _PyCoreConfig *core_config)
const PyConfig *config)
{
size_t len;
const char *path = getenv("PATH");
@ -1149,7 +1149,7 @@ calculate_init(PyCalculatePath *calculate,
if (!calculate->lib_python) {
return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -1164,108 +1164,108 @@ calculate_free(PyCalculatePath *calculate)
}
static _PyInitError
calculate_path_impl(const _PyCoreConfig *core_config,
PyCalculatePath *calculate, _PyPathConfig *config)
static PyStatus
calculate_path_impl(const PyConfig *config,
PyCalculatePath *calculate, _PyPathConfig *pathconfig)
{
_PyInitError err;
PyStatus status;
err = calculate_program_full_path(core_config, calculate, config);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_program_full_path(config, calculate, pathconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = calculate_argv0_path(calculate, config->program_full_path);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_argv0_path(calculate, pathconfig->program_full_path);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = calculate_read_pyenv(calculate);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_read_pyenv(calculate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
wchar_t prefix[MAXPATHLEN+1];
memset(prefix, 0, sizeof(prefix));
err = calculate_prefix(core_config, calculate,
status = calculate_prefix(config, calculate,
prefix, Py_ARRAY_LENGTH(prefix));
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = calculate_zip_path(calculate, prefix);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_zip_path(calculate, prefix);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
wchar_t exec_prefix[MAXPATHLEN+1];
memset(exec_prefix, 0, sizeof(exec_prefix));
err = calculate_exec_prefix(core_config, calculate,
status = calculate_exec_prefix(config, calculate,
exec_prefix, Py_ARRAY_LENGTH(exec_prefix));
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if ((!calculate->prefix_found || !calculate->exec_prefix_found) &&
core_config->pathconfig_warnings)
config->pathconfig_warnings)
{
fprintf(stderr,
"Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n");
}
err = calculate_module_search_path(core_config, calculate,
prefix, exec_prefix, config);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_module_search_path(config, calculate,
prefix, exec_prefix, pathconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
err = calculate_reduce_prefix(calculate, prefix, Py_ARRAY_LENGTH(prefix));
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_reduce_prefix(calculate, prefix, Py_ARRAY_LENGTH(prefix));
if (_PyStatus_EXCEPTION(status)) {
return status;
}
config->prefix = _PyMem_RawWcsdup(prefix);
if (config->prefix == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->prefix = _PyMem_RawWcsdup(prefix);
if (pathconfig->prefix == NULL) {
return _PyStatus_NO_MEMORY();
}
err = calculate_reduce_exec_prefix(calculate,
status = calculate_reduce_exec_prefix(calculate,
exec_prefix, Py_ARRAY_LENGTH(exec_prefix));
if (_Py_INIT_FAILED(err)) {
return err;
if (_PyStatus_EXCEPTION(status)) {
return status;
}
config->exec_prefix = _PyMem_RawWcsdup(exec_prefix);
if (config->exec_prefix == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->exec_prefix = _PyMem_RawWcsdup(exec_prefix);
if (pathconfig->exec_prefix == NULL) {
return _PyStatus_NO_MEMORY();
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
_PyInitError
_PyPathConfig_Calculate_impl(_PyPathConfig *config, const _PyCoreConfig *core_config)
PyStatus
_PyPathConfig_Calculate(_PyPathConfig *pathconfig, const PyConfig *config)
{
_PyInitError err;
PyStatus status;
PyCalculatePath calculate;
memset(&calculate, 0, sizeof(calculate));
err = calculate_init(&calculate, core_config);
if (_Py_INIT_FAILED(err)) {
status = calculate_init(&calculate, config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
err = calculate_path_impl(core_config, &calculate, config);
if (_Py_INIT_FAILED(err)) {
status = calculate_path_impl(config, &calculate, pathconfig);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
err = _Py_INIT_OK();
status = _PyStatus_OK();
done:
calculate_free(&calculate);
return err;
return status;
}
#ifdef __cplusplus

View File

@ -1,7 +1,7 @@
/* Python interpreter main program */
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_pylifecycle.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
@ -33,14 +33,14 @@ extern "C" {
/* --- pymain_init() ---------------------------------------------- */
static _PyInitError
static PyStatus
pymain_init(const _PyArgv *args)
{
_PyInitError err;
PyStatus status;
err = _PyRuntime_Initialize();
if (_Py_INIT_FAILED(err)) {
return err;
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* 754 requires that FP exceptions run in "no stop" mode by default,
@ -52,29 +52,36 @@ pymain_init(const _PyArgv *args)
fedisableexcept(FE_OVERFLOW);
#endif
_PyPreConfig preconfig;
_PyPreConfig_InitPythonConfig(&preconfig);
err = _Py_PreInitializeFromPyArgv(&preconfig, args);
if (_Py_INIT_FAILED(err)) {
return err;
PyPreConfig preconfig;
PyPreConfig_InitPythonConfig(&preconfig);
status = _Py_PreInitializeFromPyArgv(&preconfig, args);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_Py_INIT_FAILED(err)) {
return err;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* pass NULL as the config: config is read from command line arguments,
environment variables, configuration files */
if (args->use_bytes_argv) {
return _Py_InitializeFromArgs(&config,
args->argc, args->bytes_argv);
status = PyConfig_SetBytesArgv(&config, args->argc, args->bytes_argv);
}
else {
return _Py_InitializeFromWideArgs(&config,
args->argc, args->wchar_argv);
status = PyConfig_SetArgv(&config, args->argc, args->wchar_argv);
}
if (_PyStatus_EXCEPTION(status)) {
return status;
}
status = Py_InitializeFromConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
return _PyStatus_OK();
}
@ -82,13 +89,17 @@ pymain_init(const _PyArgv *args)
/* Non-zero if filename, command (-c) or module (-m) is set
on the command line */
#define RUN_CODE(config) \
(config->run_command != NULL || config->run_filename != NULL \
|| config->run_module != NULL)
static inline int config_run_code(const PyConfig *config)
{
return (config->run_command != NULL
|| config->run_filename != NULL
|| config->run_module != NULL);
}
/* Return non-zero is stdin is a TTY or if -i command line option is used */
static int
stdin_is_interactive(const _PyCoreConfig *config)
stdin_is_interactive(const PyConfig *config)
{
return (isatty(fileno(stdin)) || config->interactive);
}
@ -181,13 +192,13 @@ pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0)
static void
pymain_header(const _PyCoreConfig *config)
pymain_header(const PyConfig *config)
{
if (config->quiet) {
return;
}
if (!config->verbose && (RUN_CODE(config) || !stdin_is_interactive(config))) {
if (!config->verbose && (config_run_code(config) || !stdin_is_interactive(config))) {
return;
}
@ -199,12 +210,12 @@ pymain_header(const _PyCoreConfig *config)
static void
pymain_import_readline(const _PyCoreConfig *config)
pymain_import_readline(const PyConfig *config)
{
if (config->isolated) {
return;
}
if (!config->inspect && RUN_CODE(config)) {
if (!config->inspect && config_run_code(config)) {
return;
}
if (!isatty(fileno(stdin))) {
@ -293,7 +304,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0)
static int
pymain_run_file(_PyCoreConfig *config, PyCompilerFlags *cf)
pymain_run_file(PyConfig *config, PyCompilerFlags *cf)
{
const wchar_t *filename = config->run_filename;
FILE *fp = _Py_wfopen(filename, L"rb");
@ -362,7 +373,7 @@ pymain_run_file(_PyCoreConfig *config, PyCompilerFlags *cf)
static int
pymain_run_startup(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode)
pymain_run_startup(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
{
const char *startup = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP");
if (startup == NULL) {
@ -421,7 +432,7 @@ error:
static int
pymain_run_stdin(_PyCoreConfig *config, PyCompilerFlags *cf)
pymain_run_stdin(PyConfig *config, PyCompilerFlags *cf)
{
if (stdin_is_interactive(config)) {
config->inspect = 0;
@ -448,7 +459,7 @@ pymain_run_stdin(_PyCoreConfig *config, PyCompilerFlags *cf)
static void
pymain_repl(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode)
pymain_repl(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
{
/* Check this environment variable at the end, to give programs the
opportunity to set it from Python. */
@ -457,7 +468,7 @@ pymain_repl(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode)
Py_InspectFlag = 1;
}
if (!(config->inspect && stdin_is_interactive(config) && RUN_CODE(config))) {
if (!(config->inspect && stdin_is_interactive(config) && config_run_code(config))) {
return;
}
@ -477,7 +488,7 @@ pymain_run_python(int *exitcode)
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
/* pymain_run_stdin() modify the config */
_PyCoreConfig *config = &interp->core_config;
PyConfig *config = &interp->config;
PyObject *main_importer_path = NULL;
if (config->run_filename != NULL) {
@ -590,20 +601,20 @@ exit_sigint(void)
static void _Py_NO_RETURN
pymain_exit_error(_PyInitError err)
pymain_exit_error(PyStatus status)
{
if (_Py_INIT_IS_EXIT(err)) {
if (_PyStatus_IS_EXIT(status)) {
/* If it's an error rather than a regular exit, leave Python runtime
alive: _Py_ExitInitError() uses the current exception and use
alive: Py_ExitStatusException() uses the current exception and use
sys.stdout in this case. */
pymain_free();
}
_Py_ExitInitError(err);
Py_ExitStatusException(status);
}
int
_Py_RunMain(void)
Py_RunMain(void)
{
int exitcode = 0;
@ -628,16 +639,16 @@ _Py_RunMain(void)
static int
pymain_main(_PyArgv *args)
{
_PyInitError err = pymain_init(args);
if (_Py_INIT_IS_EXIT(err)) {
PyStatus status = pymain_init(args);
if (_PyStatus_IS_EXIT(status)) {
pymain_free();
return err.exitcode;
return status.exitcode;
}
if (_Py_INIT_FAILED(err)) {
pymain_exit_error(err);
if (_PyStatus_EXCEPTION(status)) {
pymain_exit_error(status);
}
return _Py_RunMain();
return Py_RunMain();
}
@ -654,7 +665,7 @@ Py_Main(int argc, wchar_t **argv)
int
_Py_UnixMain(int argc, char **argv)
Py_BytesMain(int argc, char **argv)
{
_PyArgv args = {
.argc = argc,

View File

@ -999,7 +999,7 @@ bytearray_repr(PyByteArrayObject *self)
static PyObject *
bytearray_str(PyObject *op)
{
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (config->bytes_warning) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"str() on a bytearray instance", 1)) {
@ -1025,7 +1025,7 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
if (rc < 0)
return NULL;
if (rc) {
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytearray and string", 1))

View File

@ -1421,7 +1421,7 @@ bytes_repr(PyObject *op)
static PyObject *
bytes_str(PyObject *op)
{
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (config->bytes_warning) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"str() on a bytes instance", 1)) {
@ -1579,7 +1579,7 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
/* Make sure both arguments are strings. */
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (config->bytes_warning && (op == Py_EQ || op == Py_NE)) {
rc = PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type);

View File

@ -6,7 +6,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
@ -2499,13 +2499,13 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
#endif
#endif /* MS_WINDOWS */
_PyInitError
PyStatus
_PyExc_Init(void)
{
#define PRE_INIT(TYPE) \
if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \
return _Py_INIT_ERR("exceptions bootstrapping error."); \
return _PyStatus_ERR("exceptions bootstrapping error."); \
} \
Py_INCREF(PyExc_ ## TYPE); \
}
@ -2515,7 +2515,7 @@ _PyExc_Init(void)
PyObject *_code = PyLong_FromLong(CODE); \
assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) \
return _Py_INIT_ERR("errmap insertion problem."); \
return _PyStatus_ERR("errmap insertion problem."); \
Py_DECREF(_code); \
} while (0)
@ -2589,14 +2589,14 @@ _PyExc_Init(void)
PRE_INIT(TimeoutError);
if (preallocate_memerrors() < 0) {
return _Py_INIT_ERR("Could not preallocate MemoryError object");
return _PyStatus_ERR("Could not preallocate MemoryError object");
}
/* Add exceptions to errnomap */
if (!errnomap) {
errnomap = PyDict_New();
if (!errnomap) {
return _Py_INIT_ERR("Cannot allocate map from errnos to OSError subclasses");
return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses");
}
}
@ -2622,7 +2622,7 @@ _PyExc_Init(void)
ADD_ERRNO(ProcessLookupError, ESRCH);
ADD_ERRNO(TimeoutError, ETIMEDOUT);
return _Py_INIT_OK();
return _PyStatus_OK();
#undef PRE_INIT
#undef ADD_ERRNO
@ -2630,12 +2630,12 @@ _PyExc_Init(void)
/* Add exception types to the builtins module */
_PyInitError
PyStatus
_PyBuiltins_AddExceptions(PyObject *bltinmod)
{
#define POST_INIT(TYPE) \
if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
return _Py_INIT_ERR("Module dictionary insertion problem."); \
return _PyStatus_ERR("Module dictionary insertion problem."); \
}
#define INIT_ALIAS(NAME, TYPE) \
@ -2644,7 +2644,7 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)
Py_XDECREF(PyExc_ ## NAME); \
PyExc_ ## NAME = PyExc_ ## TYPE; \
if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
return _Py_INIT_ERR("Module dictionary insertion problem."); \
return _PyStatus_ERR("Module dictionary insertion problem."); \
} \
} while (0)
@ -2652,7 +2652,7 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)
bdict = PyModule_GetDict(bltinmod);
if (bdict == NULL) {
return _Py_INIT_ERR("exceptions bootstrapping error.");
return _PyStatus_ERR("exceptions bootstrapping error.");
}
POST_INIT(BaseException);
@ -2729,7 +2729,7 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)
POST_INIT(ProcessLookupError);
POST_INIT(TimeoutError);
return _Py_INIT_OK();
return _PyStatus_OK();
#undef POST_INIT
#undef INIT_ALIAS

View File

@ -104,7 +104,7 @@ static void
show_alloc(void)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
if (!interp->core_config.show_alloc_count) {
if (!interp->config.show_alloc_count) {
return;
}

View File

@ -590,7 +590,7 @@ _PyModule_ClearDict(PyObject *d)
Py_ssize_t pos;
PyObject *key, *value;
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
/* First, clear only names starting with a single underscore */
pos = 0;
@ -677,7 +677,7 @@ module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc)
static void
module_dealloc(PyModuleObject *m)
{
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
PyObject_GC_UnTrack(m);
if (verbose && m->md_name) {

View File

@ -2,7 +2,7 @@
/* Generic object operations; and implementation of None */
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_object.h"
#include "pycore_pystate.h"
#include "pycore_context.h"
@ -124,7 +124,7 @@ void
_Py_dump_counts(FILE* f)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
if (!interp->core_config.show_alloc_count) {
if (!interp->config.show_alloc_count) {
return;
}
@ -1767,13 +1767,13 @@ PyObject _Py_NotImplementedStruct = {
1, &_PyNotImplemented_Type
};
_PyInitError
PyStatus
_PyTypes_Init(void)
{
#define INIT_TYPE(TYPE, NAME) \
do { \
if (PyType_Ready(TYPE) < 0) { \
return _Py_INIT_ERR("Can't initialize " NAME " type"); \
return _PyStatus_ERR("Can't initialize " NAME " type"); \
} \
} while (0)
@ -1843,7 +1843,7 @@ _PyTypes_Init(void)
INIT_TYPE(&PyCoro_Type, "coroutine");
INIT_TYPE(&_PyCoroWrapper_Type, "coroutine wrapper");
INIT_TYPE(&_PyInterpreterID_Type, "interpreter ID");
return _Py_INIT_OK();
return _PyStatus_OK();
#undef INIT_TYPE
}

View File

@ -46,7 +46,7 @@ static void
show_track(void)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
if (!interp->core_config.show_alloc_count) {
if (!interp->config.show_alloc_count) {
return;
}

View File

@ -40,7 +40,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_fileutils.h"
#include "pycore_object.h"
#include "pycore_pylifecycle.h"
@ -3549,9 +3549,9 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
interp->fs_codec.errors);
}
else {
const _PyCoreConfig *config = &interp->core_config;
const wchar_t *filesystem_errors = interp->config.filesystem_errors;
_Py_error_handler errors;
errors = get_error_handler_wide(config->filesystem_errors);
errors = get_error_handler_wide(filesystem_errors);
assert(errors != _Py_ERROR_UNKNOWN);
return unicode_encode_utf8(unicode, errors, NULL);
}
@ -3567,9 +3567,9 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
interp->fs_codec.errors);
}
else {
const _PyCoreConfig *config = &interp->core_config;
const wchar_t *filesystem_errors = interp->config.filesystem_errors;
_Py_error_handler errors;
errors = get_error_handler_wide(config->filesystem_errors);
errors = get_error_handler_wide(filesystem_errors);
assert(errors != _Py_ERROR_UNKNOWN);
return unicode_encode_locale(unicode, errors, 0);
}
@ -3787,9 +3787,9 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
NULL);
}
else {
const _PyCoreConfig *config = &interp->core_config;
const wchar_t *filesystem_errors = interp->config.filesystem_errors;
_Py_error_handler errors;
errors = get_error_handler_wide(config->filesystem_errors);
errors = get_error_handler_wide(filesystem_errors);
assert(errors != _Py_ERROR_UNKNOWN);
return unicode_decode_utf8(s, size, errors, NULL, NULL);
}
@ -3805,9 +3805,9 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
interp->fs_codec.errors);
}
else {
const _PyCoreConfig *config = &interp->core_config;
const wchar_t *filesystem_errors = interp->config.filesystem_errors;
_Py_error_handler errors;
errors = get_error_handler_wide(config->filesystem_errors);
errors = get_error_handler_wide(filesystem_errors);
return unicode_decode_locale(s, size, errors, 0);
}
#endif
@ -15200,7 +15200,7 @@ PyTypeObject PyUnicode_Type = {
/* Initialize the Unicode implementation */
_PyInitError
PyStatus
_PyUnicode_Init(void)
{
/* XXX - move this array to unicodectype.c ? */
@ -15218,12 +15218,12 @@ _PyUnicode_Init(void)
/* Init the implementation */
_Py_INCREF_UNICODE_EMPTY();
if (!unicode_empty) {
return _Py_INIT_ERR("Can't create empty string");
return _PyStatus_ERR("Can't create empty string");
}
Py_DECREF(unicode_empty);
if (PyType_Ready(&PyUnicode_Type) < 0) {
return _Py_INIT_ERR("Can't initialize unicode type");
return _PyStatus_ERR("Can't initialize unicode type");
}
/* initialize the linebreak bloom filter */
@ -15232,15 +15232,15 @@ _PyUnicode_Init(void)
Py_ARRAY_LENGTH(linebreak));
if (PyType_Ready(&EncodingMapType) < 0) {
return _Py_INIT_ERR("Can't initialize encoding map type");
return _PyStatus_ERR("Can't initialize encoding map type");
}
if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
return _Py_INIT_ERR("Can't initialize field name iterator type");
return _PyStatus_ERR("Can't initialize field name iterator type");
}
if (PyType_Ready(&PyFormatterIter_Type) < 0) {
return _Py_INIT_ERR("Can't initialize formatter iter type");
return _PyStatus_ERR("Can't initialize formatter iter type");
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* Finalize the Unicode implementation */
@ -15718,23 +15718,23 @@ error:
}
static _PyInitError
static PyStatus
init_stdio_encoding(PyInterpreterState *interp)
{
/* Update the stdio encoding to the normalized Python codec name. */
_PyCoreConfig *config = &interp->core_config;
PyConfig *config = &interp->config;
if (config_get_codec_name(&config->stdio_encoding) < 0) {
return _Py_INIT_ERR("failed to get the Python codec name "
return _PyStatus_ERR("failed to get the Python codec name "
"of the stdio encoding");
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static int
init_fs_codec(PyInterpreterState *interp)
{
_PyCoreConfig *config = &interp->core_config;
PyConfig *config = &interp->config;
_Py_error_handler error_handler;
error_handler = get_error_handler_wide(config->filesystem_errors);
@ -15778,31 +15778,31 @@ init_fs_codec(PyInterpreterState *interp)
}
static _PyInitError
static PyStatus
init_fs_encoding(PyInterpreterState *interp)
{
/* Update the filesystem encoding to the normalized Python codec name.
For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii"
(Python codec name). */
_PyCoreConfig *config = &interp->core_config;
PyConfig *config = &interp->config;
if (config_get_codec_name(&config->filesystem_encoding) < 0) {
return _Py_INIT_ERR("failed to get the Python codec "
return _PyStatus_ERR("failed to get the Python codec "
"of the filesystem encoding");
}
if (init_fs_codec(interp) < 0) {
return _Py_INIT_ERR("cannot initialize filesystem codec");
return _PyStatus_ERR("cannot initialize filesystem codec");
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
_PyInitError
PyStatus
_PyUnicode_InitEncodings(PyInterpreterState *interp)
{
_PyInitError err = init_fs_encoding(interp);
if (_Py_INIT_FAILED(err)) {
return err;
PyStatus status = init_fs_encoding(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
return init_stdio_encoding(interp);
@ -15814,7 +15814,7 @@ int
_PyUnicode_EnableLegacyWindowsFSEncoding(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
_PyCoreConfig *config = &interp->core_config;
PyConfig *config = &interp->config;
/* Set the filesystem encoding to mbcs/replace (PEP 529) */
wchar_t *encoding = _PyMem_RawWcsdup(L"mbcs");

View File

@ -80,7 +80,7 @@
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_pystate.h"
#include "osdefs.h"
#include <wchar.h>
@ -272,10 +272,10 @@ typedef HRESULT(__stdcall *PPathCchCanonicalizeEx) (PWSTR pszPathOut, size_t cch
PCWSTR pszPathIn, unsigned long dwFlags);
static PPathCchCanonicalizeEx _PathCchCanonicalizeEx;
static _PyInitError canonicalize(wchar_t *buffer, const wchar_t *path)
static PyStatus canonicalize(wchar_t *buffer, const wchar_t *path)
{
if (buffer == NULL) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
if (_PathCchCanonicalizeEx_Initialized == 0) {
@ -291,15 +291,15 @@ static _PyInitError canonicalize(wchar_t *buffer, const wchar_t *path)
if (_PathCchCanonicalizeEx) {
if (FAILED(_PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
return _Py_INIT_ERR("buffer overflow in getpathp.c's canonicalize()");
return _PyStatus_ERR("buffer overflow in getpathp.c's canonicalize()");
}
}
else {
if (!PathCanonicalizeW(buffer, path)) {
return _Py_INIT_ERR("buffer overflow in getpathp.c's canonicalize()");
return _PyStatus_ERR("buffer overflow in getpathp.c's canonicalize()");
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -529,9 +529,9 @@ _Py_GetDLLPath(void)
}
static _PyInitError
get_program_full_path(const _PyCoreConfig *core_config,
PyCalculatePath *calculate, _PyPathConfig *config)
static PyStatus
get_program_full_path(const PyConfig *config,
PyCalculatePath *calculate, _PyPathConfig *pathconfig)
{
const wchar_t *pyvenv_launcher;
wchar_t program_full_path[MAXPATHLEN+1];
@ -544,19 +544,19 @@ get_program_full_path(const _PyCoreConfig *core_config,
wcscpy_s(program_full_path, MAXPATHLEN+1, pyvenv_launcher);
} else if (!GetModuleFileNameW(NULL, program_full_path, MAXPATHLEN)) {
/* GetModuleFileName should never fail when passed NULL */
return _Py_INIT_ERR("Cannot determine program path");
return _PyStatus_ERR("Cannot determine program path");
}
config->program_full_path = PyMem_RawMalloc(
pathconfig->program_full_path = PyMem_RawMalloc(
sizeof(wchar_t) * (MAXPATHLEN + 1));
return canonicalize(config->program_full_path,
return canonicalize(pathconfig->program_full_path,
program_full_path);
}
static int
read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
read_pth_file(_PyPathConfig *pathconfig, wchar_t *prefix, const wchar_t *path)
{
FILE *sp_file = _Py_wfopen(path, L"r");
if (sp_file == NULL) {
@ -565,8 +565,8 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
wcscpy_s(prefix, MAXPATHLEN+1, path);
reduce(prefix);
config->isolated = 1;
config->site_import = 0;
pathconfig->isolated = 1;
pathconfig->site_import = 0;
size_t bufsiz = MAXPATHLEN;
size_t prefixlen = wcslen(prefix);
@ -594,7 +594,7 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
}
if (strcmp(line, "import site") == 0) {
config->site_import = 1;
pathconfig->site_import = 1;
continue;
}
else if (strncmp(line, "import ", 7) == 0) {
@ -642,7 +642,7 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
}
fclose(sp_file);
config->module_search_path = buf;
pathconfig->module_search_path = buf;
return 1;
error:
@ -654,25 +654,25 @@ error:
static void
calculate_init(PyCalculatePath *calculate,
const _PyCoreConfig *core_config)
const PyConfig *config)
{
calculate->home = core_config->home;
calculate->home = config->home;
calculate->path_env = _wgetenv(L"PATH");
}
static int
get_pth_filename(wchar_t *spbuffer, _PyPathConfig *config)
get_pth_filename(wchar_t *spbuffer, _PyPathConfig *pathconfig)
{
if (config->dll_path[0]) {
if (!change_ext(spbuffer, config->dll_path, L"._pth") &&
if (pathconfig->dll_path[0]) {
if (!change_ext(spbuffer, pathconfig->dll_path, L"._pth") &&
exists(spbuffer))
{
return 1;
}
}
if (config->program_full_path[0]) {
if (!change_ext(spbuffer, config->program_full_path, L"._pth") &&
if (pathconfig->program_full_path[0]) {
if (!change_ext(spbuffer, pathconfig->program_full_path, L"._pth") &&
exists(spbuffer))
{
return 1;
@ -683,15 +683,15 @@ get_pth_filename(wchar_t *spbuffer, _PyPathConfig *config)
static int
calculate_pth_file(_PyPathConfig *config, wchar_t *prefix)
calculate_pth_file(_PyPathConfig *pathconfig, wchar_t *prefix)
{
wchar_t spbuffer[MAXPATHLEN+1];
if (!get_pth_filename(spbuffer, config)) {
if (!get_pth_filename(spbuffer, pathconfig)) {
return 0;
}
return read_pth_file(config, prefix, spbuffer);
return read_pth_file(pathconfig, prefix, spbuffer);
}
@ -735,7 +735,7 @@ calculate_pyvenv_file(PyCalculatePath *calculate)
}
#define INIT_ERR_BUFFER_OVERFLOW() _Py_INIT_ERR("buffer overflow")
#define INIT_ERR_BUFFER_OVERFLOW() _PyStatus_ERR("buffer overflow")
static void
@ -760,9 +760,9 @@ calculate_home_prefix(PyCalculatePath *calculate, wchar_t *prefix)
}
static _PyInitError
calculate_module_search_path(const _PyCoreConfig *core_config,
PyCalculatePath *calculate, _PyPathConfig *config,
static PyStatus
calculate_module_search_path(const PyConfig *config,
PyCalculatePath *calculate, _PyPathConfig *pathconfig,
wchar_t *prefix)
{
int skiphome = calculate->home==NULL ? 0 : 1;
@ -772,7 +772,7 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
#endif
/* We only use the default relative PYTHONPATH if we haven't
anything better to use! */
int skipdefault = (core_config->module_search_path_env != NULL ||
int skipdefault = (config->pythonpath_env != NULL ||
calculate->home != NULL ||
calculate->machine_path != NULL ||
calculate->user_path != NULL);
@ -811,8 +811,8 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
bufsz += wcslen(calculate->machine_path) + 1;
}
bufsz += wcslen(calculate->zip_path) + 1;
if (core_config->module_search_path_env != NULL) {
bufsz += wcslen(core_config->module_search_path_env) + 1;
if (config->pythonpath_env != NULL) {
bufsz += wcslen(config->pythonpath_env) + 1;
}
wchar_t *buf, *start_buf;
@ -820,21 +820,21 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
if (buf == NULL) {
/* We can't exit, so print a warning and limp along */
fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
if (core_config->module_search_path_env) {
if (config->pythonpath_env) {
fprintf(stderr, "Using environment $PYTHONPATH.\n");
config->module_search_path = core_config->module_search_path_env;
pathconfig->module_search_path = config->pythonpath_env;
}
else {
fprintf(stderr, "Using default static path.\n");
config->module_search_path = PYTHONPATH;
pathconfig->module_search_path = PYTHONPATH;
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
start_buf = buf;
if (core_config->module_search_path_env) {
if (config->pythonpath_env) {
if (wcscpy_s(buf, bufsz - (buf - start_buf),
core_config->module_search_path_env)) {
config->pythonpath_env)) {
return INIT_ERR_BUFFER_OVERFLOW();
}
buf = wcschr(buf, L'\0');
@ -941,38 +941,38 @@ calculate_module_search_path(const _PyCoreConfig *core_config,
}
}
config->module_search_path = start_buf;
return _Py_INIT_OK();
pathconfig->module_search_path = start_buf;
return _PyStatus_OK();
}
static _PyInitError
calculate_path_impl(const _PyCoreConfig *core_config,
PyCalculatePath *calculate, _PyPathConfig *config)
static PyStatus
calculate_path_impl(const PyConfig *config,
PyCalculatePath *calculate, _PyPathConfig *pathconfig)
{
_PyInitError err;
PyStatus status;
assert(config->dll_path == NULL);
assert(pathconfig->dll_path == NULL);
config->dll_path = _Py_GetDLLPath();
if (config->dll_path == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->dll_path = _Py_GetDLLPath();
if (pathconfig->dll_path == NULL) {
return _PyStatus_NO_MEMORY();
}
err = get_program_full_path(core_config, calculate, config);
if (_Py_INIT_FAILED(err)) {
return err;
status = get_program_full_path(config, calculate, pathconfig);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* program_full_path guaranteed \0 terminated in MAXPATH+1 bytes. */
wcscpy_s(calculate->argv0_path, MAXPATHLEN+1, config->program_full_path);
wcscpy_s(calculate->argv0_path, MAXPATHLEN+1, pathconfig->program_full_path);
reduce(calculate->argv0_path);
wchar_t prefix[MAXPATHLEN+1];
memset(prefix, 0, sizeof(prefix));
/* Search for a sys.path file */
if (calculate_pth_file(config, prefix)) {
if (calculate_pth_file(pathconfig, prefix)) {
goto done;
}
@ -980,27 +980,27 @@ calculate_path_impl(const _PyCoreConfig *core_config,
/* Calculate zip archive path from DLL or exe path */
change_ext(calculate->zip_path,
config->dll_path[0] ? config->dll_path : config->program_full_path,
pathconfig->dll_path[0] ? pathconfig->dll_path : pathconfig->program_full_path,
L".zip");
calculate_home_prefix(calculate, prefix);
err = calculate_module_search_path(core_config, calculate, config, prefix);
if (_Py_INIT_FAILED(err)) {
return err;
status = calculate_module_search_path(config, calculate, pathconfig, prefix);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
done:
config->prefix = _PyMem_RawWcsdup(prefix);
if (config->prefix == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->prefix = _PyMem_RawWcsdup(prefix);
if (pathconfig->prefix == NULL) {
return _PyStatus_NO_MEMORY();
}
config->exec_prefix = _PyMem_RawWcsdup(prefix);
if (config->exec_prefix == NULL) {
return _Py_INIT_NO_MEMORY();
pathconfig->exec_prefix = _PyMem_RawWcsdup(prefix);
if (pathconfig->exec_prefix == NULL) {
return _PyStatus_NO_MEMORY();
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -1012,24 +1012,24 @@ calculate_free(PyCalculatePath *calculate)
}
_PyInitError
_PyPathConfig_Calculate_impl(_PyPathConfig *config, const _PyCoreConfig *core_config)
PyStatus
_PyPathConfig_Calculate(_PyPathConfig *pathconfig, const PyConfig *config)
{
PyCalculatePath calculate;
memset(&calculate, 0, sizeof(calculate));
calculate_init(&calculate, core_config);
calculate_init(&calculate, config);
_PyInitError err = calculate_path_impl(core_config, &calculate, config);
if (_Py_INIT_FAILED(err)) {
PyStatus status = calculate_path_impl(config, &calculate, pathconfig);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
err = _Py_INIT_OK();
status = _PyStatus_OK();
done:
calculate_free(&calculate);
return err;
return status;
}

View File

@ -127,9 +127,9 @@
<ClInclude Include="..\Include\complexobject.h" />
<ClInclude Include="..\Include\context.h" />
<ClInclude Include="..\Include\cpython\abstract.h" />
<ClInclude Include="..\Include\cpython\coreconfig.h" />
<ClInclude Include="..\Include\cpython\dictobject.h" />
<ClInclude Include="..\Include\cpython\fileobject.h" />
<ClInclude Include="..\Include\cpython\initconfig.h" />
<ClInclude Include="..\Include\cpython\object.h" />
<ClInclude Include="..\Include\cpython\objimpl.h" />
<ClInclude Include="..\Include\cpython\pyerrors.h" />
@ -161,11 +161,11 @@
<ClInclude Include="..\Include\internal\pycore_ceval.h" />
<ClInclude Include="..\Include\internal\pycore_condvar.h" />
<ClInclude Include="..\Include\internal\pycore_context.h" />
<ClInclude Include="..\Include\internal\pycore_coreconfig.h" />
<ClInclude Include="..\Include\internal\pycore_fileutils.h" />
<ClInclude Include="..\Include\internal\pycore_getopt.h" />
<ClInclude Include="..\Include\internal\pycore_gil.h" />
<ClInclude Include="..\Include\internal\pycore_hamt.h" />
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
<ClInclude Include="..\Include\internal\pycore_object.h" />
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
@ -420,7 +420,6 @@
<ClCompile Include="..\Python\codecs.c" />
<ClCompile Include="..\Python\compile.c" />
<ClCompile Include="..\Python\context.c" />
<ClCompile Include="..\Python\coreconfig.c" />
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
@ -438,6 +437,7 @@
<ClCompile Include="..\Python\hamt.c" />
<ClCompile Include="..\Python\import.c" />
<ClCompile Include="..\Python\importdl.c" />
<ClCompile Include="..\Python\initconfig.c" />
<ClCompile Include="..\Python\marshal.c" />
<ClCompile Include="..\Python\modsupport.c" />
<ClCompile Include="..\Python\mysnprintf.c" />

View File

@ -84,15 +84,15 @@
<ClInclude Include="..\Include\cpython\abstract.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\coreconfig.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\dictobject.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\fileobject.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\initconfig.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\cpython\object.h">
<Filter>Include</Filter>
</ClInclude>
@ -186,9 +186,6 @@
<ClInclude Include="..\Include\internal\pycore_context.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_coreconfig.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_fileutils.h">
<Filter>Include</Filter>
</ClInclude>
@ -201,6 +198,9 @@
<ClInclude Include="..\Include\internal\pycore_hamt.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_initconfig.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_object.h">
<Filter>Include</Filter>
</ClInclude>
@ -920,9 +920,6 @@
<ClCompile Include="..\Python\compile.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\coreconfig.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\context.h">
<Filter>Python</Filter>
</ClCompile>
@ -977,6 +974,9 @@
<ClCompile Include="..\Python\importdl.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\initconfig.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\marshal.c">
<Filter>Python</Filter>
</ClCompile>

View File

@ -36,7 +36,7 @@ main(int argc, char *argv[])
const char *name, *inpath, *outpath;
char buf[100];
FILE *infile = NULL, *outfile = NULL;
struct _Py_stat_struct status;
struct _Py_stat_struct stat;
size_t text_size, data_size, i, n;
char *text = NULL;
unsigned char *data;
@ -56,11 +56,11 @@ main(int argc, char *argv[])
fprintf(stderr, "cannot open '%s' for reading\n", inpath);
goto error;
}
if (_Py_fstat_noraise(fileno(infile), &status)) {
if (_Py_fstat_noraise(fileno(infile), &stat)) {
fprintf(stderr, "cannot fstat '%s'\n", inpath);
goto error;
}
text_size = (size_t)status.st_size;
text_size = (size_t)stat.st_size;
text = (char *) malloc(text_size + 1);
if (text == NULL) {
fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size);
@ -76,32 +76,32 @@ main(int argc, char *argv[])
}
text[text_size] = '\0';
_PyInitError err;
_PyCoreConfig config;
PyStatus status;
PyConfig config;
err = _PyCoreConfig_InitIsolatedConfig(&config);
if (_PyInitError_Failed(err)) {
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
config.site_import = 0;
err = _PyCoreConfig_SetString(&config, &config.program_name,
status = PyConfig_SetString(&config, &config.program_name,
L"./_freeze_importlib");
if (_PyInitError_Failed(err)) {
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
/* Don't install importlib, since it could execute outdated bytecode. */
config._install_importlib = 0;
config._init_main = 0;
err = _Py_InitializeFromConfig(&config);
_PyCoreConfig_Clear(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
PyConfig_Clear(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
sprintf(buf, "<frozen %s>", name);

View File

@ -4,7 +4,7 @@
#endif
#include <Python.h>
#include "pycore_coreconfig.h" /* FIXME: PEP 587 makes these functions public */
#include "pycore_initconfig.h" /* FIXME: PEP 587 makes these functions public */
#include <Python.h>
#include "pythread.h"
#include <inttypes.h>
@ -328,25 +328,25 @@ static int test_init_initialize_config(void)
static int check_init_compat_config(int preinit)
{
_PyInitError err;
PyStatus status;
if (preinit) {
_PyPreConfig preconfig;
PyPreConfig preconfig;
_PyPreConfig_InitCompatConfig(&preconfig);
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
}
_PyCoreConfig config;
_PyCoreConfig_InitCompatConfig(&config);
PyConfig config;
_PyConfig_InitCompatConfig(&config);
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
@ -418,9 +418,9 @@ static int test_init_global_config(void)
static int test_init_from_config(void)
{
_PyInitError err;
PyStatus status;
_PyPreConfig preconfig;
PyPreConfig preconfig;
_PyPreConfig_InitCompatConfig(&preconfig);
putenv("PYTHONMALLOC=malloc_debug");
@ -430,14 +430,14 @@ static int test_init_from_config(void)
Py_UTF8Mode = 0;
preconfig.utf8_mode = 1;
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
/* Test _Py_InitializeFromConfig() */
_PyCoreConfig config;
_PyCoreConfig_InitCompatConfig(&config);
/* Test Py_InitializeFromConfig() */
PyConfig config;
_PyConfig_InitCompatConfig(&config);
config.install_signal_handlers = 0;
/* FIXME: test use_environment */
@ -481,9 +481,9 @@ static int test_init_from_config(void)
config.parse_argv = 1;
static wchar_t* xoptions[3] = {
L"core_xoption1=3",
L"core_xoption2=",
L"core_xoption3",
L"xoption1=3",
L"xoption2=",
L"xoption3",
};
config.xoptions.length = Py_ARRAY_LENGTH(xoptions);
config.xoptions.items = xoptions;
@ -494,7 +494,7 @@ static int test_init_from_config(void)
config.warnoptions.length = Py_ARRAY_LENGTH(warnoptions);
config.warnoptions.items = warnoptions;
/* FIXME: test module_search_path_env */
/* FIXME: test pythonpath_env */
/* FIXME: test home */
/* FIXME: test path config: module_search_path .. dll_path */
@ -553,9 +553,9 @@ static int test_init_from_config(void)
Py_FrozenFlag = 0;
config.pathconfig_warnings = 0;
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -565,12 +565,12 @@ static int test_init_from_config(void)
static int check_init_parse_argv(int parse_argv)
{
_PyInitError err;
PyStatus status;
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
static wchar_t* argv[] = {
@ -587,9 +587,9 @@ static int check_init_parse_argv(int parse_argv)
config.argv.items = argv;
config.parse_argv = parse_argv;
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -652,20 +652,20 @@ static int test_init_compat_env(void)
static int test_init_python_env(void)
{
_PyInitError err;
PyStatus status;
set_all_env_vars();
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -708,13 +708,13 @@ static int test_init_env_dev_mode_alloc(void)
static int test_init_isolated_flag(void)
{
_PyInitError err;
PyStatus status;
/* Test _PyCoreConfig.isolated=1 */
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
/* Test PyConfig.isolated=1 */
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
Py_IsolatedFlag = 0;
@ -724,9 +724,9 @@ static int test_init_isolated_flag(void)
config.program_name = L"./_testembed";
set_all_env_vars();
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -734,28 +734,28 @@ static int test_init_isolated_flag(void)
}
/* _PyPreConfig.isolated=1, _PyCoreConfig.isolated=0 */
/* PyPreConfig.isolated=1, PyConfig.isolated=0 */
static int test_preinit_isolated1(void)
{
_PyInitError err;
PyStatus status;
_PyPreConfig preconfig;
PyPreConfig preconfig;
_PyPreConfig_InitCompatConfig(&preconfig);
preconfig.isolated = 1;
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
_PyCoreConfig config;
_PyCoreConfig_InitCompatConfig(&config);
PyConfig config;
_PyConfig_InitCompatConfig(&config);
config.program_name = L"./_testembed";
set_all_env_vars();
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -763,23 +763,23 @@ static int test_preinit_isolated1(void)
}
/* _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1 */
/* PyPreConfig.isolated=0, PyConfig.isolated=1 */
static int test_preinit_isolated2(void)
{
_PyInitError err;
PyStatus status;
_PyPreConfig preconfig;
PyPreConfig preconfig;
_PyPreConfig_InitCompatConfig(&preconfig);
preconfig.isolated = 0;
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
/* Test _PyCoreConfig.isolated=1 */
_PyCoreConfig config;
_PyCoreConfig_InitCompatConfig(&config);
/* Test PyConfig.isolated=1 */
PyConfig config;
_PyConfig_InitCompatConfig(&config);
Py_IsolatedFlag = 0;
config.isolated = 1;
@ -788,9 +788,9 @@ static int test_preinit_isolated2(void)
config.program_name = L"./_testembed";
set_all_env_vars();
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -800,10 +800,10 @@ static int test_preinit_isolated2(void)
static int test_preinit_dont_parse_argv(void)
{
_PyInitError err;
PyStatus status;
_PyPreConfig preconfig;
_PyPreConfig_InitIsolatedConfig(&preconfig);
PyPreConfig preconfig;
PyPreConfig_InitIsolatedConfig(&preconfig);
preconfig.isolated = 0;
@ -814,15 +814,15 @@ static int test_preinit_dont_parse_argv(void)
L"-X", L"dev",
L"-X", L"utf8",
L"script.py"};
err = _Py_PreInitializeFromWideArgs(&preconfig, Py_ARRAY_LENGTH(argv), argv);
if (_PyInitError_Failed(err)) {
status = Py_PreInitializeFromArgs(&preconfig, Py_ARRAY_LENGTH(argv), argv);
if (PyStatus_Exception(status)) {
goto failed;
}
_PyCoreConfig config;
PyConfig config;
err = _PyCoreConfig_InitIsolatedConfig(&config);
if (_PyInitError_Failed(err)) {
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
@ -830,70 +830,70 @@ static int test_preinit_dont_parse_argv(void)
/* Pre-initialize implicitly using argv: make sure that -X dev
is used to configure the allocation in preinitialization */
err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (_PyInitError_Failed(err)) {
status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (PyStatus_Exception(status)) {
goto failed;
}
err = _PyCoreConfig_SetString(&config, &config.program_name,
status = PyConfig_SetString(&config, &config.program_name,
L"./_testembed");
if (_PyInitError_Failed(err)) {
if (PyStatus_Exception(status)) {
goto failed;
}
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
_PyCoreConfig_Clear(&config);
PyConfig_Clear(&config);
dump_config();
Py_Finalize();
return 0;
failed:
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
static int test_preinit_parse_argv(void)
{
_PyInitError err;
_PyCoreConfig config;
PyStatus status;
PyConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
/* Pre-initialize implicitly using argv: make sure that -X dev
is used to configure the allocation in preinitialization */
wchar_t *argv[] = {L"python3", L"-X", L"dev", L"script.py"};
err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (_PyInitError_Failed(err)) {
status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (PyStatus_Exception(status)) {
goto failed;
}
err = _PyCoreConfig_SetString(&config, &config.program_name,
status = PyConfig_SetString(&config, &config.program_name,
L"./_testembed");
if (_PyInitError_Failed(err)) {
if (PyStatus_Exception(status)) {
goto failed;
}
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
_PyCoreConfig_Clear(&config);
PyConfig_Clear(&config);
dump_config();
Py_Finalize();
return 0;
failed:
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
@ -923,8 +923,8 @@ static void set_all_global_config_variables(void)
static int check_preinit_isolated_config(int preinit)
{
_PyInitError err;
_PyPreConfig *rt_preconfig;
PyStatus status;
PyPreConfig *rt_preconfig;
/* environment variables must be ignored */
set_all_env_vars();
@ -933,12 +933,12 @@ static int check_preinit_isolated_config(int preinit)
set_all_global_config_variables();
if (preinit) {
_PyPreConfig preconfig;
_PyPreConfig_InitIsolatedConfig(&preconfig);
PyPreConfig preconfig;
PyPreConfig_InitIsolatedConfig(&preconfig);
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
rt_preconfig = &_PyRuntime.preconfig;
@ -946,18 +946,18 @@ static int check_preinit_isolated_config(int preinit)
assert(rt_preconfig->use_environment == 0);
}
_PyCoreConfig config;
err = _PyCoreConfig_InitIsolatedConfig(&config);
if (_PyInitError_Failed(err)) {
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitIsolatedConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
rt_preconfig = &_PyRuntime.preconfig;
@ -984,7 +984,7 @@ static int test_init_isolated_config(void)
static int check_init_python_config(int preinit)
{
_PyInitError err;
PyStatus status;
/* global configuration variables must be ignored */
set_all_global_config_variables();
@ -1000,25 +1000,25 @@ static int check_init_python_config(int preinit)
#endif
if (preinit) {
_PyPreConfig preconfig;
_PyPreConfig_InitPythonConfig(&preconfig);
PyPreConfig preconfig;
PyPreConfig_InitPythonConfig(&preconfig);
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
}
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -1040,28 +1040,28 @@ static int test_init_python_config(void)
static int test_init_dont_configure_locale(void)
{
_PyInitError err;
PyStatus status;
_PyPreConfig preconfig;
_PyPreConfig_InitPythonConfig(&preconfig);
PyPreConfig preconfig;
PyPreConfig_InitPythonConfig(&preconfig);
preconfig.configure_locale = 0;
preconfig.coerce_c_locale = 1;
preconfig.coerce_c_locale_warn = 1;
err = _Py_PreInitialize(&preconfig);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_PreInitialize(&preconfig);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
@ -1072,19 +1072,19 @@ static int test_init_dont_configure_locale(void)
static int test_init_dev_mode(void)
{
_PyInitError err;
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
putenv("PYTHONFAULTHANDLER=");
putenv("PYTHONMALLOC=");
config.dev_mode = 1;
config.program_name = L"./_testembed";
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
dump_config();
Py_Finalize();
@ -1250,39 +1250,39 @@ static int test_audit_subinterpreter(void)
static int test_init_read_set(void)
{
_PyInitError err;
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
err = _PyCoreConfig_DecodeLocale(&config, &config.program_name,
status = PyConfig_SetBytesString(&config, &config.program_name,
"./init_read_set");
if (_PyInitError_Failed(err)) {
if (PyStatus_Exception(status)) {
goto fail;
}
err = _PyCoreConfig_Read(&config);
if (_PyInitError_Failed(err)) {
status = PyConfig_Read(&config);
if (PyStatus_Exception(status)) {
goto fail;
}
if (_PyWstrList_Append(&config.module_search_paths,
L"init_read_set_path") < 0) {
err = _PyInitError_NoMemory();
status = PyWideStringList_Append(&config.module_search_paths,
L"init_read_set_path");
if (PyStatus_Exception(status)) {
goto fail;
}
/* override executable computed by _PyCoreConfig_Read() */
err = _PyCoreConfig_SetString(&config, &config.executable, L"my_executable");
if (_PyInitError_Failed(err)) {
/* override executable computed by PyConfig_Read() */
status = PyConfig_SetString(&config, &config.executable, L"my_executable");
if (PyStatus_Exception(status)) {
goto fail;
}
err = _Py_InitializeFromConfig(&config);
_PyCoreConfig_Clear(&config);
if (_PyInitError_Failed(err)) {
status = Py_InitializeFromConfig(&config);
PyConfig_Clear(&config);
if (PyStatus_Exception(status)) {
goto fail;
}
dump_config();
@ -1290,7 +1290,7 @@ static int test_init_read_set(void)
return 0;
fail:
_Py_ExitInitError(err);
Py_ExitStatusException(status);
}
@ -1301,7 +1301,7 @@ wchar_t *init_main_argv[] = {
L"arg2"};
static void configure_init_main(_PyCoreConfig *config)
static void configure_init_main(PyConfig *config)
{
config->argv.length = Py_ARRAY_LENGTH(init_main_argv);
config->argv.items = init_main_argv;
@ -1312,38 +1312,38 @@ static void configure_init_main(_PyCoreConfig *config)
static int test_init_run_main(void)
{
_PyInitError err;
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyStatus status;
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
configure_init_main(&config);
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
return _Py_RunMain();
return Py_RunMain();
}
static int test_init_main(void)
{
_PyInitError err;
_PyCoreConfig config;
PyStatus status;
PyConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
configure_init_main(&config);
config._init_main = 0;
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
/* sys.stdout don't exist yet: it is created by _Py_InitializeMain() */
@ -1355,51 +1355,51 @@ static int test_init_main(void)
exit(1);
}
err = _Py_InitializeMain();
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = _Py_InitializeMain();
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
return _Py_RunMain();
return Py_RunMain();
}
static int test_run_main(void)
{
_PyInitError err;
_PyCoreConfig config;
PyStatus status;
PyConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
wchar_t *argv[] = {L"python3", L"-c",
(L"import sys; "
L"print(f'_Py_RunMain(): sys.argv={sys.argv}')"),
L"print(f'Py_RunMain(): sys.argv={sys.argv}')"),
L"arg2"};
err = _PyCoreConfig_SetWideArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (_PyInitError_Failed(err)) {
status = PyConfig_SetArgv(&config, Py_ARRAY_LENGTH(argv), argv);
if (PyStatus_Exception(status)) {
goto failed;
}
err = _PyCoreConfig_SetString(&config, &config.program_name,
status = PyConfig_SetString(&config, &config.program_name,
L"./python3");
if (_PyInitError_Failed(err)) {
if (PyStatus_Exception(status)) {
goto failed;
}
err = _Py_InitializeFromConfig(&config);
if (_PyInitError_Failed(err)) {
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto failed;
}
_PyCoreConfig_Clear(&config);
PyConfig_Clear(&config);
return _Py_RunMain();
return Py_RunMain();
failed:
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}

View File

@ -13,6 +13,6 @@ wmain(int argc, wchar_t **argv)
int
main(int argc, char **argv)
{
return _Py_UnixMain(argc, argv);
return Py_BytesMain(argc, argv);
}
#endif

View File

@ -2824,7 +2824,7 @@ _PyBuiltin_Init(void)
{
PyObject *mod, *dict, *debug;
const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
const PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (PyType_Ready(&PyFilter_Type) < 0 ||
PyType_Ready(&PyMap_Type) < 0 ||

View File

@ -1,5 +1,5 @@
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#ifdef MS_WINDOWS
# include <windows.h>
/* All sample MSDN wincrypt programs include the header below. It is at least
@ -547,14 +547,14 @@ _PyOS_URandomNonblock(void *buffer, Py_ssize_t size)
}
_PyInitError
_Py_HashRandomization_Init(const _PyCoreConfig *config)
PyStatus
_Py_HashRandomization_Init(const PyConfig *config)
{
void *secret = &_Py_HashSecret;
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
if (_Py_HashSecret_Initialized) {
return _Py_INIT_OK();
return _PyStatus_OK();
}
_Py_HashSecret_Initialized = 1;
@ -579,11 +579,11 @@ _Py_HashRandomization_Init(const _PyCoreConfig *config)
pyurandom() is non-blocking mode (blocking=0): see the PEP 524. */
res = pyurandom(secret, secret_size, 0, 0);
if (res < 0) {
return _Py_INIT_ERR("failed to get random numbers "
return _PyStatus_ERR("failed to get random numbers "
"to initialize Python");
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}

View File

@ -311,7 +311,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
PyCodeObject *co = NULL;
PyCompilerFlags local_flags;
int merged;
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (!__doc__) {
__doc__ = PyUnicode_InternFromString("__doc__");
@ -4782,7 +4782,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
return compiler_error(c, "'await' outside function");
}
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
c->u->u_scope_type != COMPILER_SCOPE_COMPREHENSION){
return compiler_error(c, "'await' outside async function");
}

View File

@ -20,7 +20,7 @@ dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
const char *pathname, FILE *fp)
{
int flags = BIND_FIRST | BIND_DEFERRED;
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
if (verbose) {
flags = BIND_FIRST | BIND_IMMEDIATE |
BIND_NONFATAL | BIND_VERBOSE;

View File

@ -2,7 +2,7 @@
/* Error handling */
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h"
#include "pycore_traceback.h"
@ -1090,16 +1090,16 @@ static PyStructSequence_Desc UnraisableHookArgs_desc = {
};
_PyInitError
PyStatus
_PyErr_Init(void)
{
if (UnraisableHookArgsType.tp_name == NULL) {
if (PyStructSequence_InitType2(&UnraisableHookArgsType,
&UnraisableHookArgs_desc) < 0) {
return _Py_INIT_ERR("failed to initialize UnraisableHookArgs type");
return _PyStatus_ERR("failed to initialize UnraisableHookArgs type");
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}

View File

@ -16,9 +16,9 @@ extern int PyInitFrozenExtensions(void);
int
Py_FrozenMain(int argc, char **argv)
{
_PyInitError err = _PyRuntime_Initialize();
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
PyStatus status = _PyRuntime_Initialize();
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
const char *p;
@ -39,11 +39,11 @@ Py_FrozenMain(int argc, char **argv)
}
}
_PyCoreConfig config;
err = _PyCoreConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) {
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig config;
status = PyConfig_InitPythonConfig(&config);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
@ -85,10 +85,10 @@ Py_FrozenMain(int argc, char **argv)
if (argc >= 1)
Py_SetProgramName(argv_copy[0]);
err = _Py_InitializeFromConfig(&config);
_PyCoreConfig_Clear(&config);
if (_PyInitError_Failed(err)) {
_Py_ExitInitError(err);
status = Py_InitializeFromConfig(&config);
PyConfig_Clear(&config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
#ifdef MS_WINDOWS

View File

@ -43,17 +43,17 @@ module _imp
/* Initialize things */
_PyInitError
PyStatus
_PyImport_Init(PyInterpreterState *interp)
{
interp->builtins_copy = PyDict_Copy(interp->builtins);
if (interp->builtins_copy == NULL) {
return _Py_INIT_ERR("Can't backup builtins dict");
return _PyStatus_ERR("Can't backup builtins dict");
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
_PyInitError
PyStatus
_PyImportHooks_Init(void)
{
PyObject *v, *path_hooks = NULL;
@ -82,15 +82,15 @@ _PyImportHooks_Init(void)
goto error;
}
Py_DECREF(path_hooks);
return _Py_INIT_OK();
return _PyStatus_OK();
error:
PyErr_Print();
return _Py_INIT_ERR("initializing sys.meta_path, sys.path_hooks, "
return _PyStatus_ERR("initializing sys.meta_path, sys.path_hooks, "
"or path_importer_cache failed");
}
_PyInitError
PyStatus
_PyImportZip_Init(PyInterpreterState *interp)
{
PyObject *path_hooks, *zipimport;
@ -102,7 +102,7 @@ _PyImportZip_Init(PyInterpreterState *interp)
goto error;
}
int verbose = interp->core_config.verbose;
int verbose = interp->config.verbose;
if (verbose) {
PySys_WriteStderr("# installing zipimport hook\n");
}
@ -138,11 +138,11 @@ _PyImportZip_Init(PyInterpreterState *interp)
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
error:
PyErr_Print();
return _Py_INIT_ERR("initializing zipimport failed");
return _PyStatus_ERR("initializing zipimport failed");
}
/* Locking primitives to prevent parallel imports of the same module
@ -418,7 +418,7 @@ PyImport_Cleanup(void)
/* XXX Perhaps these precautions are obsolete. Who knows? */
int verbose = interp->core_config.verbose;
int verbose = interp->config.verbose;
if (verbose) {
PySys_WriteStderr("# clear builtins._\n");
}
@ -766,7 +766,7 @@ _PyImport_FindExtensionObjectEx(PyObject *name, PyObject *filename,
PyMapping_DelItem(modules, name);
return NULL;
}
int verbose = _PyInterpreterState_Get()->core_config.verbose;
int verbose = _PyInterpreterState_Get()->config.verbose;
if (verbose) {
PySys_FormatStderr("import %U # previously loaded (%R)\n",
name, filename);
@ -1455,7 +1455,7 @@ remove_importlib_frames(PyInterpreterState *interp)
which end with a call to "_call_with_frames_removed". */
PyErr_Fetch(&exception, &value, &base_tb);
if (!exception || interp->core_config.verbose) {
if (!exception || interp->config.verbose) {
goto done;
}
@ -1655,7 +1655,7 @@ import_find_and_load(PyObject *abs_name)
_Py_IDENTIFIER(_find_and_load);
PyObject *mod = NULL;
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
int import_time = interp->core_config.import_time;
int import_time = interp->config.import_time;
static int import_level;
static _PyTime_t accumulated;
@ -2338,7 +2338,7 @@ PyInit__imp(void)
goto failure;
}
const wchar_t *mode = _PyInterpreterState_Get()->core_config.check_hash_pycs_mode;
const wchar_t *mode = _PyInterpreterState_Get()->config.check_hash_pycs_mode;
PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1);
if (pyc_mode == NULL) {
goto failure;

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
#include "Python.h"
#include "osdefs.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_fileutils.h"
#include "pycore_pathconfig.h"
#include "pycore_pymem.h"
@ -34,7 +34,7 @@ copy_wstr(wchar_t **dst, const wchar_t *src)
static void
_PyPathConfig_Clear(_PyPathConfig *config)
pathconfig_clear(_PyPathConfig *config)
{
/* _PyMem_SetDefaultAllocator() is needed to get a known memory allocator,
since Py_SetPath(), Py_SetPythonHome() and Py_SetProgramName() can be
@ -63,12 +63,11 @@ _PyPathConfig_Clear(_PyPathConfig *config)
}
/* Calculate the path configuration: initialize path_config from core_config */
static _PyInitError
_PyPathConfig_Calculate(_PyPathConfig *path_config,
const _PyCoreConfig *core_config)
/* Calculate the path configuration: initialize pathconfig from config */
static PyStatus
pathconfig_calculate(_PyPathConfig *pathconfig, const PyConfig *config)
{
_PyInitError err;
PyStatus status;
_PyPathConfig new_config = _PyPathConfig_INIT;
PyMemAllocatorEx old_alloc;
@ -76,40 +75,40 @@ _PyPathConfig_Calculate(_PyPathConfig *path_config,
/* Calculate program_full_path, prefix, exec_prefix,
dll_path (Windows), and module_search_path */
err = _PyPathConfig_Calculate_impl(&new_config, core_config);
if (_Py_INIT_FAILED(err)) {
goto err;
status = _PyPathConfig_Calculate(&new_config, config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
/* Copy home and program_name from core_config */
if (copy_wstr(&new_config.home, core_config->home) < 0) {
err = _Py_INIT_NO_MEMORY();
goto err;
/* Copy home and program_name from config */
if (copy_wstr(&new_config.home, config->home) < 0) {
status = _PyStatus_NO_MEMORY();
goto error;
}
if (copy_wstr(&new_config.program_name, core_config->program_name) < 0) {
err = _Py_INIT_NO_MEMORY();
goto err;
if (copy_wstr(&new_config.program_name, config->program_name) < 0) {
status = _PyStatus_NO_MEMORY();
goto error;
}
_PyPathConfig_Clear(path_config);
*path_config = new_config;
pathconfig_clear(pathconfig);
*pathconfig = new_config;
err = _Py_INIT_OK();
status = _PyStatus_OK();
goto done;
err:
_PyPathConfig_Clear(&new_config);
error:
pathconfig_clear(&new_config);
done:
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return err;
return status;
}
_PyInitError
PyStatus
_PyPathConfig_SetGlobal(const _PyPathConfig *config)
{
_PyInitError err;
PyStatus status;
_PyPathConfig new_config = _PyPathConfig_INIT;
PyMemAllocatorEx old_alloc;
@ -118,8 +117,8 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config)
#define COPY_ATTR(ATTR) \
do { \
if (copy_wstr(&new_config.ATTR, config->ATTR) < 0) { \
_PyPathConfig_Clear(&new_config); \
err = _Py_INIT_NO_MEMORY(); \
pathconfig_clear(&new_config); \
status = _PyStatus_NO_MEMORY(); \
goto done; \
} \
} while (0)
@ -134,15 +133,15 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config)
COPY_ATTR(program_name);
COPY_ATTR(home);
_PyPathConfig_Clear(&_Py_path_config);
pathconfig_clear(&_Py_path_config);
/* Steal new_config strings; don't clear new_config */
_Py_path_config = new_config;
err = _Py_INIT_OK();
status = _PyStatus_OK();
done:
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return err;
return status;
}
@ -152,14 +151,14 @@ _PyPathConfig_ClearGlobal(void)
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
_PyPathConfig_Clear(&_Py_path_config);
pathconfig_clear(&_Py_path_config);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}
static wchar_t*
_PyWstrList_Join(const _PyWstrList *list, wchar_t sep)
_PyWideStringList_Join(const PyWideStringList *list, wchar_t sep)
{
size_t len = 1; /* NUL terminator */
for (Py_ssize_t i=0; i < list->length; i++) {
@ -189,70 +188,69 @@ _PyWstrList_Join(const _PyWstrList *list, wchar_t sep)
}
/* Set the global path configuration from core_config. */
_PyInitError
_PyCoreConfig_SetPathConfig(const _PyCoreConfig *core_config)
/* Set the global path configuration from config. */
PyStatus
_PyConfig_SetPathConfig(const PyConfig *config)
{
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
_PyInitError err;
_PyPathConfig path_config = _PyPathConfig_INIT;
PyStatus status;
_PyPathConfig pathconfig = _PyPathConfig_INIT;
path_config.module_search_path = _PyWstrList_Join(&core_config->module_search_paths, DELIM);
if (path_config.module_search_path == NULL) {
pathconfig.module_search_path = _PyWideStringList_Join(&config->module_search_paths, DELIM);
if (pathconfig.module_search_path == NULL) {
goto no_memory;
}
if (copy_wstr(&path_config.program_full_path, core_config->executable) < 0) {
if (copy_wstr(&pathconfig.program_full_path, config->executable) < 0) {
goto no_memory;
}
if (copy_wstr(&path_config.prefix, core_config->prefix) < 0) {
if (copy_wstr(&pathconfig.prefix, config->prefix) < 0) {
goto no_memory;
}
if (copy_wstr(&path_config.exec_prefix, core_config->exec_prefix) < 0) {
if (copy_wstr(&pathconfig.exec_prefix, config->exec_prefix) < 0) {
goto no_memory;
}
#ifdef MS_WINDOWS
path_config.dll_path = _Py_GetDLLPath();
if (path_config.dll_path == NULL) {
pathconfig.dll_path = _Py_GetDLLPath();
if (pathconfig.dll_path == NULL) {
goto no_memory;
}
#endif
if (copy_wstr(&path_config.program_name, core_config->program_name) < 0) {
if (copy_wstr(&pathconfig.program_name, config->program_name) < 0) {
goto no_memory;
}
if (copy_wstr(&path_config.home, core_config->home) < 0) {
if (copy_wstr(&pathconfig.home, config->home) < 0) {
goto no_memory;
}
err = _PyPathConfig_SetGlobal(&path_config);
if (_Py_INIT_FAILED(err)) {
status = _PyPathConfig_SetGlobal(&pathconfig);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
err = _Py_INIT_OK();
status = _PyStatus_OK();
goto done;
no_memory:
err = _Py_INIT_NO_MEMORY();
status = _PyStatus_NO_MEMORY();
done:
_PyPathConfig_Clear(&path_config);
pathconfig_clear(&pathconfig);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return err;
return status;
}
static _PyInitError
core_config_init_module_search_paths(_PyCoreConfig *config,
_PyPathConfig *path_config)
static PyStatus
config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)
{
assert(!config->use_module_search_paths);
assert(!config->module_search_paths_set);
_PyWstrList_Clear(&config->module_search_paths);
_PyWideStringList_Clear(&config->module_search_paths);
const wchar_t *sys_path = path_config->module_search_path;
const wchar_t *sys_path = pathconfig->module_search_path;
const wchar_t delim = DELIM;
const wchar_t *p = sys_path;
while (1) {
@ -264,15 +262,15 @@ core_config_init_module_search_paths(_PyCoreConfig *config,
size_t path_len = (p - sys_path);
wchar_t *path = PyMem_RawMalloc((path_len + 1) * sizeof(wchar_t));
if (path == NULL) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
memcpy(path, sys_path, path_len * sizeof(wchar_t));
path[path_len] = L'\0';
int res = _PyWstrList_Append(&config->module_search_paths, path);
PyStatus status = PyWideStringList_Append(&config->module_search_paths, path);
PyMem_RawFree(path);
if (res < 0) {
return _Py_INIT_NO_MEMORY();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
if (*p == '\0') {
@ -280,96 +278,96 @@ core_config_init_module_search_paths(_PyCoreConfig *config,
}
sys_path = p + 1;
}
config->use_module_search_paths = 1;
return _Py_INIT_OK();
config->module_search_paths_set = 1;
return _PyStatus_OK();
}
static _PyInitError
_PyCoreConfig_CalculatePathConfig(_PyCoreConfig *config)
static PyStatus
config_calculate_pathconfig(PyConfig *config)
{
_PyPathConfig path_config = _PyPathConfig_INIT;
_PyInitError err;
_PyPathConfig pathconfig = _PyPathConfig_INIT;
PyStatus status;
err = _PyPathConfig_Calculate(&path_config, config);
if (_Py_INIT_FAILED(err)) {
status = pathconfig_calculate(&pathconfig, config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
if (!config->use_module_search_paths) {
err = core_config_init_module_search_paths(config, &path_config);
if (_Py_INIT_FAILED(err)) {
if (!config->module_search_paths_set) {
status = config_init_module_search_paths(config, &pathconfig);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
}
if (config->executable == NULL) {
if (copy_wstr(&config->executable,
path_config.program_full_path) < 0) {
pathconfig.program_full_path) < 0) {
goto no_memory;
}
}
if (config->prefix == NULL) {
if (copy_wstr(&config->prefix, path_config.prefix) < 0) {
if (copy_wstr(&config->prefix, pathconfig.prefix) < 0) {
goto no_memory;
}
}
if (config->exec_prefix == NULL) {
if (copy_wstr(&config->exec_prefix,
path_config.exec_prefix) < 0) {
pathconfig.exec_prefix) < 0) {
goto no_memory;
}
}
if (path_config.isolated != -1) {
config->isolated = path_config.isolated;
if (pathconfig.isolated != -1) {
config->isolated = pathconfig.isolated;
}
if (path_config.site_import != -1) {
config->site_import = path_config.site_import;
if (pathconfig.site_import != -1) {
config->site_import = pathconfig.site_import;
}
_PyPathConfig_Clear(&path_config);
return _Py_INIT_OK();
pathconfig_clear(&pathconfig);
return _PyStatus_OK();
no_memory:
err = _Py_INIT_NO_MEMORY();
status = _PyStatus_NO_MEMORY();
error:
_PyPathConfig_Clear(&path_config);
return err;
pathconfig_clear(&pathconfig);
return status;
}
_PyInitError
_PyCoreConfig_InitPathConfig(_PyCoreConfig *config)
PyStatus
_PyConfig_InitPathConfig(PyConfig *config)
{
/* Do we need to calculate the path? */
if (!config->use_module_search_paths
if (!config->module_search_paths_set
|| (config->executable == NULL)
|| (config->prefix == NULL)
|| (config->exec_prefix == NULL))
{
_PyInitError err = _PyCoreConfig_CalculatePathConfig(config);
if (_Py_INIT_FAILED(err)) {
return err;
PyStatus status = config_calculate_pathconfig(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
if (config->base_prefix == NULL) {
if (copy_wstr(&config->base_prefix, config->prefix) < 0) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
}
if (config->base_exec_prefix == NULL) {
if (copy_wstr(&config->base_exec_prefix,
config->exec_prefix) < 0) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -381,26 +379,26 @@ pathconfig_global_init(void)
return;
}
_PyInitError err;
_PyCoreConfig config;
_PyCoreConfig_InitCompatConfig(&config);
PyStatus status;
PyConfig config;
_PyConfig_InitCompatConfig(&config);
err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) {
status = PyConfig_Read(&config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
err = _PyCoreConfig_SetPathConfig(&config);
if (_Py_INIT_FAILED(err)) {
status = _PyConfig_SetPathConfig(&config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
_PyCoreConfig_Clear(&config);
PyConfig_Clear(&config);
return;
error:
_PyCoreConfig_Clear(&config);
_Py_ExitInitError(err);
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
@ -410,7 +408,7 @@ void
Py_SetPath(const wchar_t *path)
{
if (path == NULL) {
_PyPathConfig_Clear(&_Py_path_config);
pathconfig_clear(&_Py_path_config);
return;
}
@ -437,7 +435,7 @@ Py_SetPath(const wchar_t *path)
new_config.program_name = _Py_path_config.program_name;
_Py_path_config.program_name = NULL;
_PyPathConfig_Clear(&_Py_path_config);
pathconfig_clear(&_Py_path_config);
_Py_path_config = new_config;
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
@ -569,9 +567,9 @@ Py_GetProgramName(void)
Raise an exception and return -1 on error.
*/
int
_PyPathConfig_ComputeSysPath0(const _PyWstrList *argv, PyObject **path0_p)
_PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p)
{
assert(_PyWstrList_CheckConsistency(argv));
assert(_PyWideStringList_CheckConsistency(argv));
if (argv->length == 0) {
/* Leave sys.path unchanged if sys.argv is empty */

View File

@ -1,5 +1,5 @@
#include "Python.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_getopt.h"
#include "pycore_pystate.h" /* _PyRuntime_Initialize() */
#include <locale.h> /* setlocale() */
@ -7,8 +7,13 @@
#define DECODE_LOCALE_ERR(NAME, LEN) \
(((LEN) == -2) \
? _Py_INIT_ERR("cannot decode " NAME) \
: _Py_INIT_NO_MEMORY())
? _PyStatus_ERR("cannot decode " NAME) \
: _PyStatus_NO_MEMORY())
/* Forward declarations */
static void
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2);
/* --- File system encoding/errors -------------------------------- */
@ -67,22 +72,22 @@ _Py_SetFileSystemEncoding(const char *encoding, const char *errors)
/* --- _PyArgv ---------------------------------------------------- */
/* Decode bytes_argv using Py_DecodeLocale() */
_PyInitError
_PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
PyStatus
_PyArgv_AsWstrList(const _PyArgv *args, PyWideStringList *list)
{
_PyWstrList wargv = _PyWstrList_INIT;
PyWideStringList wargv = PyWideStringList_INIT;
if (args->use_bytes_argv) {
size_t size = sizeof(wchar_t*) * args->argc;
wargv.items = (wchar_t **)PyMem_RawMalloc(size);
if (wargv.items == NULL) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
for (Py_ssize_t i = 0; i < args->argc; i++) {
size_t len;
wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len);
if (arg == NULL) {
_PyWstrList_Clear(&wargv);
_PyWideStringList_Clear(&wargv);
return DECODE_LOCALE_ERR("command line arguments",
(Py_ssize_t)len);
}
@ -90,17 +95,17 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
wargv.length++;
}
_PyWstrList_Clear(list);
_PyWideStringList_Clear(list);
*list = wargv;
}
else {
wargv.length = args->argc;
wargv.items = (wchar_t **)args->wchar_argv;
if (_PyWstrList_Copy(list, &wargv) < 0) {
return _Py_INIT_NO_MEMORY();
if (_PyWideStringList_Copy(list, &wargv) < 0) {
return _PyStatus_NO_MEMORY();
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -109,12 +114,12 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
void
_PyPreCmdline_Clear(_PyPreCmdline *cmdline)
{
_PyWstrList_Clear(&cmdline->argv);
_PyWstrList_Clear(&cmdline->xoptions);
_PyWideStringList_Clear(&cmdline->argv);
_PyWideStringList_Clear(&cmdline->xoptions);
}
_PyInitError
PyStatus
_PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
{
return _PyArgv_AsWstrList(args, &cmdline->argv);
@ -122,7 +127,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
static void
_PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
precmdline_get_preconfig(_PyPreCmdline *cmdline, const PyPreConfig *config)
{
#define COPY_ATTR(ATTR) \
if (config->ATTR != -1) { \
@ -138,7 +143,7 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
static void
_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
precmdline_set_preconfig(const _PyPreCmdline *cmdline, PyPreConfig *config)
{
#define COPY_ATTR(ATTR) \
config->ATTR = cmdline->ATTR
@ -151,33 +156,34 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
}
int
_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config)
PyStatus
_PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config)
{
#define COPY_ATTR(ATTR) \
config->ATTR = cmdline->ATTR
if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) {
return -1;
PyStatus status = _PyWideStringList_Extend(&config->xoptions, &cmdline->xoptions);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
COPY_ATTR(isolated);
COPY_ATTR(use_environment);
COPY_ATTR(dev_mode);
return 0;
return _PyStatus_OK();
#undef COPY_ATTR
}
/* Parse the command line arguments */
static _PyInitError
static PyStatus
precmdline_parse_cmdline(_PyPreCmdline *cmdline)
{
const _PyWstrList *argv = &cmdline->argv;
const PyWideStringList *argv = &cmdline->argv;
_PyOS_ResetGetOpt();
/* Don't log parsing errors into stderr here: _PyCoreConfig_Read()
/* Don't log parsing errors into stderr here: PyConfig_Read()
is responsible for that */
_PyOS_opterr = 0;
do {
@ -199,32 +205,34 @@ precmdline_parse_cmdline(_PyPreCmdline *cmdline)
case 'X':
{
if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) {
return _Py_INIT_NO_MEMORY();
PyStatus status = PyWideStringList_Append(&cmdline->xoptions,
_PyOS_optarg);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
break;
}
default:
/* ignore other argument:
handled by _PyCoreConfig_Read() */
handled by PyConfig_Read() */
break;
}
} while (1);
return _Py_INIT_OK();
return _PyStatus_OK();
}
_PyInitError
_PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
PyStatus
_PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
{
_PyPreCmdline_GetPreConfig(cmdline, preconfig);
precmdline_get_preconfig(cmdline, preconfig);
if (preconfig->parse_argv) {
_PyInitError err = precmdline_parse_cmdline(cmdline);
if (_Py_INIT_FAILED(err)) {
return err;
PyStatus status = precmdline_parse_cmdline(cmdline);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
@ -254,15 +262,15 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
assert(cmdline->isolated >= 0);
assert(cmdline->dev_mode >= 0);
return _Py_INIT_OK();
return _PyStatus_OK();
}
/* --- _PyPreConfig ----------------------------------------------- */
/* --- PyPreConfig ----------------------------------------------- */
void
_PyPreConfig_InitCompatConfig(_PyPreConfig *config)
_PyPreConfig_InitCompatConfig(PyPreConfig *config)
{
memset(config, 0, sizeof(*config));
@ -291,7 +299,7 @@ _PyPreConfig_InitCompatConfig(_PyPreConfig *config)
void
_PyPreConfig_InitPythonConfig(_PyPreConfig *config)
PyPreConfig_InitPythonConfig(PyPreConfig *config)
{
_PyPreConfig_InitCompatConfig(config);
@ -312,7 +320,7 @@ _PyPreConfig_InitPythonConfig(_PyPreConfig *config)
void
_PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
{
_PyPreConfig_InitCompatConfig(config);
@ -329,37 +337,37 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
void
_PyPreConfig_InitFromPreConfig(_PyPreConfig *config,
const _PyPreConfig *config2)
_PyPreConfig_InitFromPreConfig(PyPreConfig *config,
const PyPreConfig *config2)
{
_PyPreConfig_InitCompatConfig(config);
_PyPreConfig_Copy(config, config2);
PyPreConfig_InitPythonConfig(config);
preconfig_copy(config, config2);
}
void
_PyPreConfig_InitFromCoreConfig(_PyPreConfig *config,
const _PyCoreConfig *coreconfig)
_PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config)
{
_PyConfigInitEnum config_init = (_PyConfigInitEnum)coreconfig->_config_init;
_PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init;
switch (config_init) {
case _PyConfig_INIT_PYTHON:
_PyPreConfig_InitPythonConfig(config);
PyPreConfig_InitPythonConfig(preconfig);
break;
case _PyConfig_INIT_ISOLATED:
_PyPreConfig_InitIsolatedConfig(config);
PyPreConfig_InitIsolatedConfig(preconfig);
break;
case _PyConfig_INIT_COMPAT:
default:
_PyPreConfig_InitCompatConfig(config);
_PyPreConfig_InitCompatConfig(preconfig);
}
_PyPreConfig_GetCoreConfig(config, coreconfig);
_PyPreConfig_GetConfig(preconfig, config);
}
void
_PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
static void
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
{
assert(config2->_config_version == _Py_CONFIG_VERSION);
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
COPY_ATTR(_config_init);
@ -381,7 +389,7 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
PyObject*
_PyPreConfig_AsDict(const _PyPreConfig *config)
_PyPreConfig_AsDict(const PyPreConfig *config)
{
PyObject *dict;
@ -427,12 +435,11 @@ fail:
void
_PyPreConfig_GetCoreConfig(_PyPreConfig *config,
const _PyCoreConfig *core_config)
_PyPreConfig_GetConfig(PyPreConfig *preconfig, const PyConfig *config)
{
#define COPY_ATTR(ATTR) \
if (core_config->ATTR != -1) { \
config->ATTR = core_config->ATTR; \
if (config->ATTR != -1) { \
preconfig->ATTR = config->ATTR; \
}
COPY_ATTR(parse_argv);
@ -445,7 +452,7 @@ _PyPreConfig_GetCoreConfig(_PyPreConfig *config,
static void
_PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
preconfig_get_global_vars(PyPreConfig *config)
{
if (config->_config_init != _PyConfig_INIT_COMPAT) {
/* Python and Isolated configuration ignore global variables */
@ -476,7 +483,7 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
static void
_PyPreConfig_SetGlobalConfig(const _PyPreConfig *config)
preconfig_set_global_vars(const PyPreConfig *config)
{
#define COPY_FLAG(ATTR, VAR) \
if (config->ATTR >= 0) { \
@ -555,7 +562,7 @@ _Py_get_env_flag(int use_environment, int *flag, const char *name)
const wchar_t*
_Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
_Py_get_xoption(const PyWideStringList *xoptions, const wchar_t *name)
{
for (Py_ssize_t i=0; i < xoptions->length; i++) {
const wchar_t *option = xoptions->items[i];
@ -575,8 +582,8 @@ _Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
}
static _PyInitError
preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
static PyStatus
preconfig_init_utf8_mode(PyPreConfig *config, const _PyPreCmdline *cmdline)
{
#ifdef MS_WINDOWS
if (config->legacy_windows_fs_encoding) {
@ -585,7 +592,7 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
#endif
if (config->utf8_mode >= 0) {
return _Py_INIT_OK();
return _PyStatus_OK();
}
const wchar_t *xopt;
@ -601,13 +608,13 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
config->utf8_mode = 0;
}
else {
return _Py_INIT_ERR("invalid -X utf8 option value");
return _PyStatus_ERR("invalid -X utf8 option value");
}
}
else {
config->utf8_mode = 1;
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
const char *opt = _Py_GetEnv(config->use_environment, "PYTHONUTF8");
@ -619,10 +626,10 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
config->utf8_mode = 0;
}
else {
return _Py_INIT_ERR("invalid PYTHONUTF8 environment "
return _PyStatus_ERR("invalid PYTHONUTF8 environment "
"variable value");
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -642,12 +649,12 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
if (config->utf8_mode < 0) {
config->utf8_mode = 0;
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static void
preconfig_init_coerce_c_locale(_PyPreConfig *config)
preconfig_init_coerce_c_locale(PyPreConfig *config)
{
if (!config->configure_locale) {
config->coerce_c_locale = 0;
@ -693,8 +700,8 @@ preconfig_init_coerce_c_locale(_PyPreConfig *config)
}
static _PyInitError
preconfig_init_allocator(_PyPreConfig *config)
static PyStatus
preconfig_init_allocator(PyPreConfig *config)
{
if (config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
/* bpo-34247. The PYTHONMALLOC environment variable has the priority
@ -705,7 +712,7 @@ preconfig_init_allocator(_PyPreConfig *config)
if (envvar) {
PyMemAllocatorName name;
if (_PyMem_GetAllocatorName(envvar, &name) < 0) {
return _Py_INIT_ERR("PYTHONMALLOC: unknown allocator");
return _PyStatus_ERR("PYTHONMALLOC: unknown allocator");
}
config->allocator = (int)name;
}
@ -714,21 +721,21 @@ preconfig_init_allocator(_PyPreConfig *config)
if (config->dev_mode && config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
config->allocator = PYMEM_ALLOCATOR_DEBUG;
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
static _PyInitError
preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
static PyStatus
preconfig_read(PyPreConfig *config, _PyPreCmdline *cmdline)
{
_PyInitError err;
PyStatus status;
err = _PyPreCmdline_Read(cmdline, config);
if (_Py_INIT_FAILED(err)) {
return err;
status = _PyPreCmdline_Read(cmdline, config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
_PyPreCmdline_SetPreConfig(cmdline, config);
precmdline_set_preconfig(cmdline, config);
/* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */
#ifdef MS_WINDOWS
@ -739,15 +746,15 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
preconfig_init_coerce_c_locale(config);
err = preconfig_init_utf8_mode(config, cmdline);
if (_Py_INIT_FAILED(err)) {
return err;
status = preconfig_init_utf8_mode(config, cmdline);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* allocator */
err = preconfig_init_allocator(config);
if (_Py_INIT_FAILED(err)) {
return err;
status = preconfig_init_allocator(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
assert(config->coerce_c_locale >= 0);
@ -760,7 +767,7 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
assert(config->use_environment >= 0);
assert(config->dev_mode >= 0);
return _Py_INIT_OK();
return _PyStatus_OK();
}
@ -770,30 +777,30 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
- environment variables
- Py_xxx global configuration variables
- the LC_CTYPE locale */
_PyInitError
_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
PyStatus
_PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
{
_PyInitError err;
PyStatus status;
err = _PyRuntime_Initialize();
if (_Py_INIT_FAILED(err)) {
return err;
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
_PyPreConfig_GetGlobalConfig(config);
preconfig_get_global_vars(config);
/* Copy LC_CTYPE locale, since it's modified later */
const char *loc = setlocale(LC_CTYPE, NULL);
if (loc == NULL) {
return _Py_INIT_ERR("failed to LC_CTYPE locale");
return _PyStatus_ERR("failed to LC_CTYPE locale");
}
char *init_ctype_locale = _PyMem_RawStrdup(loc);
if (init_ctype_locale == NULL) {
return _Py_INIT_NO_MEMORY();
return _PyStatus_NO_MEMORY();
}
/* Save the config to be able to restore it if encodings change */
_PyPreConfig save_config;
PyPreConfig save_config;
_PyPreConfig_InitFromPreConfig(&save_config, config);
/* Set LC_CTYPE to the user preferred locale */
@ -808,8 +815,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
#endif
if (args) {
err = _PyPreCmdline_SetArgv(&cmdline, args);
if (_Py_INIT_FAILED(err)) {
status = _PyPreCmdline_SetArgv(&cmdline, args);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
}
@ -823,7 +830,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
/* Watchdog to prevent an infinite loop */
loops++;
if (loops == 3) {
err = _Py_INIT_ERR("Encoding changed twice while "
status = _PyStatus_ERR("Encoding changed twice while "
"reading the configuration");
goto done;
}
@ -835,8 +842,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
#endif
err = preconfig_read(config, &cmdline);
if (_Py_INIT_FAILED(err)) {
status = preconfig_read(config, &cmdline);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
@ -877,14 +884,14 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
just keep UTF-8 Mode value. */
int new_utf8_mode = config->utf8_mode;
int new_coerce_c_locale = config->coerce_c_locale;
_PyPreConfig_Copy(config, &save_config);
preconfig_copy(config, &save_config);
config->utf8_mode = new_utf8_mode;
config->coerce_c_locale = new_coerce_c_locale;
/* The encoding changed: read again the configuration
with the new encoding */
}
err = _Py_INIT_OK();
status = _PyStatus_OK();
done:
if (init_ctype_locale != NULL) {
@ -896,7 +903,7 @@ done:
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
#endif
_PyPreCmdline_Clear(&cmdline);
return err;
return status;
}
@ -912,26 +919,26 @@ done:
Do nothing if called after Py_Initialize(): ignore the new
pre-configuration. */
_PyInitError
_PyPreConfig_Write(const _PyPreConfig *src_config)
PyStatus
_PyPreConfig_Write(const PyPreConfig *src_config)
{
_PyPreConfig config;
PyPreConfig config;
_PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyRuntime.core_initialized) {
/* bpo-34008: Calling this functions after Py_Initialize() ignores
the new configuration. */
return _Py_INIT_OK();
return _PyStatus_OK();
}
PyMemAllocatorName name = (PyMemAllocatorName)config.allocator;
if (name != PYMEM_ALLOCATOR_NOT_SET) {
if (_PyMem_SetupAllocators(name) < 0) {
return _Py_INIT_ERR("Unknown PYTHONMALLOC allocator");
return _PyStatus_ERR("Unknown PYTHONMALLOC allocator");
}
}
_PyPreConfig_SetGlobalConfig(&config);
preconfig_set_global_vars(&config);
if (config.configure_locale) {
if (config.coerce_c_locale) {
@ -946,7 +953,7 @@ _PyPreConfig_Write(const _PyPreConfig *src_config)
}
/* Write the new pre-configuration into _PyRuntime */
_PyPreConfig_Copy(&_PyRuntime.preconfig, &config);
preconfig_copy(&_PyRuntime.preconfig, &config);
return _Py_INIT_OK();
return _PyStatus_OK();
}

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
#include "Python.h"
#include "pycore_ceval.h"
#include "pycore_coreconfig.h"
#include "pycore_initconfig.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#include "pycore_pylifecycle.h"
@ -42,7 +42,7 @@ static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_st
static void _PyThreadState_Delete(_PyRuntimeState *runtime, PyThreadState *tstate);
static _PyInitError
static PyStatus
_PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
{
/* We preserve the hook across init, because there is
@ -60,7 +60,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
_PyPreConfig_InitPythonConfig(&runtime->preconfig);
PyPreConfig_InitPythonConfig(&runtime->preconfig);
runtime->gilstate.check_enabled = 1;
@ -71,22 +71,22 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
runtime->interpreters.mutex = PyThread_allocate_lock();
if (runtime->interpreters.mutex == NULL) {
return _Py_INIT_ERR("Can't initialize threads for interpreter");
return _PyStatus_ERR("Can't initialize threads for interpreter");
}
runtime->interpreters.next_id = -1;
runtime->xidregistry.mutex = PyThread_allocate_lock();
if (runtime->xidregistry.mutex == NULL) {
return _Py_INIT_ERR("Can't initialize threads for cross-interpreter data registry");
return _PyStatus_ERR("Can't initialize threads for cross-interpreter data registry");
}
// Set it to the ID of the main thread of the main interpreter.
runtime->main_thread = PyThread_get_thread_ident();
return _Py_INIT_OK();
return _PyStatus_OK();
}
_PyInitError
PyStatus
_PyRuntimeState_Init(_PyRuntimeState *runtime)
{
/* Force default allocator, since _PyRuntimeState_Fini() must
@ -94,10 +94,10 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
_PyInitError err = _PyRuntimeState_Init_impl(runtime);
PyStatus status = _PyRuntimeState_Init_impl(runtime);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return err;
return status;
}
void
@ -163,7 +163,7 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
static void _PyGILState_NoteThreadState(
struct _gilstate_runtime_state *gilstate, PyThreadState* tstate);
_PyInitError
PyStatus
_PyInterpreterState_Enable(_PyRuntimeState *runtime)
{
struct pyinterpreters *interpreters = &runtime->interpreters;
@ -182,11 +182,11 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
if (interpreters->mutex == NULL) {
return _Py_INIT_ERR("Can't initialize threads for interpreter");
return _PyStatus_ERR("Can't initialize threads for interpreter");
}
}
return _Py_INIT_OK();
return _PyStatus_OK();
}
PyInterpreterState *
@ -205,8 +205,11 @@ PyInterpreterState_New(void)
interp->id_refcount = -1;
interp->check_interval = 100;
_PyInitError err = _PyCoreConfig_InitPythonConfig(&interp->core_config);
if (_Py_INIT_FAILED(err)) {
PyStatus status = PyConfig_InitPythonConfig(&interp->config);
if (_PyStatus_EXCEPTION(status)) {
/* Don't report status to caller: PyConfig_InitPythonConfig()
can only fail with a memory allocation error. */
PyConfig_Clear(&interp->config);
PyMem_RawFree(interp);
return NULL;
}
@ -269,7 +272,7 @@ _PyInterpreterState_Clear(_PyRuntimeState *runtime, PyInterpreterState *interp)
Py_CLEAR(interp->audit_hooks);
_PyCoreConfig_Clear(&interp->core_config);
PyConfig_Clear(&interp->config);
Py_CLEAR(interp->codec_search_path);
Py_CLEAR(interp->codec_search_cache);
Py_CLEAR(interp->codec_error_registry);
@ -523,12 +526,6 @@ _PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
interp->requires_idref = required ? 1 : 0;
}
_PyCoreConfig *
_PyInterpreterState_GetCoreConfig(PyInterpreterState *interp)
{
return &interp->core_config;
}
PyObject *
_PyInterpreterState_GetMainModule(PyInterpreterState *interp)
{
@ -775,7 +772,7 @@ _PyState_ClearModules(void)
void
PyThreadState_Clear(PyThreadState *tstate)
{
int verbose = tstate->interp->core_config.verbose;
int verbose = tstate->interp->config.verbose;
if (verbose && tstate->frame != NULL)
fprintf(stderr,

View File

@ -94,7 +94,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
PyCompilerFlags local_flags;
int nomem_count = 0;
#ifdef Py_REF_DEBUG
int show_ref_count = _PyInterpreterState_Get()->core_config.show_ref_count;
int show_ref_count = _PyInterpreterState_Get()->config.show_ref_count;
#endif
filename = PyUnicode_DecodeFSDefault(filename_str);
@ -584,7 +584,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
int
_Py_HandleSystemExit(int *exitcode_p)
{
int inspect = _PyInterpreterState_GET_UNSAFE()->core_config.inspect;
int inspect = _PyInterpreterState_GET_UNSAFE()->config.inspect;
if (inspect) {
/* Don't exit if -i flag was given. This flag is set to 0
* when entering interactive mode for inspecting. */

View File

@ -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) {