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 abstract.rst
concrete.rst concrete.rst
init.rst init.rst
init_config.rst
memory.rst memory.rst
objimpl.rst objimpl.rst
apiabiversion.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. ``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) .. c:function:: int PyRun_AnyFile(FILE *fp, const char *filename)
This is a simplified interface to :c:func:`PyRun_AnyFileExFlags` below, leaving 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`.) (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 Other Language Changes
====================== ======================

View file

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

View file

@ -5,56 +5,49 @@
extern "C" { extern "C" {
#endif #endif
/* --- _PyInitError ----------------------------------------------- */ /* --- PyStatus ----------------------------------------------- */
typedef struct { typedef struct {
enum { enum {
_Py_INIT_ERR_TYPE_OK=0, _PyStatus_TYPE_OK=0,
_Py_INIT_ERR_TYPE_ERROR=1, _PyStatus_TYPE_ERROR=1,
_Py_INIT_ERR_TYPE_EXIT=2 _PyStatus_TYPE_EXIT=2
} _type; } _type;
const char *_func; const char *func;
const char *err_msg; const char *err_msg;
int exitcode; int exitcode;
} _PyInitError; } PyStatus;
PyAPI_FUNC(_PyInitError) _PyInitError_Ok(void); PyAPI_FUNC(PyStatus) PyStatus_Ok(void);
PyAPI_FUNC(_PyInitError) _PyInitError_Error(const char *err_msg); PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg);
PyAPI_FUNC(_PyInitError) _PyInitError_NoMemory(void); PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void);
PyAPI_FUNC(_PyInitError) _PyInitError_Exit(int exitcode); PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
PyAPI_FUNC(int) _PyInitError_IsError(_PyInitError err); PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
PyAPI_FUNC(int) _PyInitError_IsExit(_PyInitError err); PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
PyAPI_FUNC(int) _PyInitError_Failed(_PyInitError err); PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
/* --- _PyWstrList ------------------------------------------------ */ /* --- PyWideStringList ------------------------------------------------ */
typedef struct { typedef struct {
/* If length is greater than zero, items must be non-NULL /* If length is greater than zero, items must be non-NULL
and all items strings must be non-NULL */ and all items strings must be non-NULL */
Py_ssize_t length; Py_ssize_t length;
wchar_t **items; wchar_t **items;
} _PyWstrList; } PyWideStringList;
PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list,
const wchar_t *item);
/* --- _PyPreConfig ----------------------------------------------- */ /* --- 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;
typedef struct { typedef struct {
int _config_version; /* Internal configuration version, int _config_version; /* Internal configuration version,
used for ABI compatibility */ used for ABI compatibility */
int _config_init; /* _PyConfigInitEnum value */ int _config_init; /* _PyConfigInitEnum value */
/* Parse _Py_PreInitializeFromArgs() arguments? /* Parse Py_PreInitializeFromBytesArgs() arguments?
See _PyCoreConfig.parse_argv */ See PyConfig.parse_argv */
int parse_argv; int parse_argv;
/* If greater than 0, enable isolated mode: sys.path contains /* If greater than 0, enable isolated mode: sys.path contains
@ -124,22 +117,22 @@ typedef struct {
/* Memory allocator: PYTHONMALLOC env var. /* Memory allocator: PYTHONMALLOC env var.
See PyMemAllocatorName for valid values. */ See PyMemAllocatorName for valid values. */
int allocator; int allocator;
} _PyPreConfig; } PyPreConfig;
PyAPI_FUNC(void) _PyPreConfig_InitPythonConfig(_PyPreConfig *config); PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
PyAPI_FUNC(void) _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config); PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
/* --- _PyCoreConfig ---------------------------------------------- */ /* --- PyConfig ---------------------------------------------- */
typedef struct { typedef struct {
int _config_version; /* Internal configuration version, int _config_version; /* Internal configuration version,
used for ABI compatibility */ used for ABI compatibility */
int _config_init; /* _PyConfigInitEnum value */ int _config_init; /* _PyConfigInitEnum value */
int isolated; /* Isolated mode? see _PyPreConfig.isolated */ int isolated; /* Isolated mode? see PyPreConfig.isolated */
int use_environment; /* Use environment variables? see _PyPreConfig.use_environment */ int use_environment; /* Use environment variables? see PyPreConfig.use_environment */
int dev_mode; /* Development mode? See _PyPreConfig.dev_mode */ int dev_mode; /* Development mode? See PyPreConfig.dev_mode */
/* Install signal handlers? Yes by default. */ /* Install signal handlers? Yes by default. */
int install_signal_handlers; int install_signal_handlers;
@ -207,7 +200,7 @@ typedef struct {
If argv is empty, an empty string is added to ensure that sys.argv If argv is empty, an empty string is added to ensure that sys.argv
always exists and is never empty. */ always exists and is never empty. */
_PyWstrList argv; PyWideStringList argv;
/* Program name: /* Program name:
@ -219,8 +212,8 @@ typedef struct {
- Use "python" on Windows, or "python3 on other platforms. */ - Use "python" on Windows, or "python3 on other platforms. */
wchar_t *program_name; wchar_t *program_name;
_PyWstrList xoptions; /* Command line -X options */ PyWideStringList xoptions; /* Command line -X options */
_PyWstrList warnoptions; /* Warnings options */ PyWideStringList warnoptions; /* Warnings options */
/* If equal to zero, disable the import of the module site and the /* If equal to zero, disable the import of the module site and the
site-dependent manipulations of sys.path that it entails. Also disable site-dependent manipulations of sys.path that it entails. Also disable
@ -347,17 +340,37 @@ typedef struct {
int legacy_windows_stdio; int legacy_windows_stdio;
#endif #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 ------------ */ /* --- 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, wchar_t *home; /* PYTHONHOME environment variable,
see also Py_SetPythonHome(). */ see also Py_SetPythonHome(). */
/* --- Path configuration outputs ----------- */ /* --- Path configuration outputs ----------- */
int use_module_search_paths; /* If non-zero, use module_search_paths */ int module_search_paths_set; /* If non-zero, use module_search_paths */
_PyWstrList module_search_paths; /* sys.path paths. Computed if PyWideStringList module_search_paths; /* sys.path paths. Computed if
use_module_search_paths is equal module_search_paths_set is equal
to zero. */ to zero. */
wchar_t *executable; /* sys.executable */ wchar_t *executable; /* sys.executable */
@ -384,48 +397,28 @@ typedef struct {
Needed by freeze_importlib. */ Needed by freeze_importlib. */
int _install_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 */ /* If equal to 0, stop Python initialization before the "main" phase */
int _init_main; int _init_main;
} _PyCoreConfig; } PyConfig;
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config); PyAPI_FUNC(PyStatus) PyConfig_InitPythonConfig(PyConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config); PyAPI_FUNC(PyStatus) PyConfig_InitIsolatedConfig(PyConfig *config);
PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *); PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetString( PyAPI_FUNC(PyStatus) PyConfig_SetString(
_PyCoreConfig *config, PyConfig *config,
wchar_t **config_str, wchar_t **config_str,
const wchar_t *str); const wchar_t *str);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_DecodeLocale( PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
_PyCoreConfig *config, PyConfig *config,
wchar_t **config_str, wchar_t **config_str,
const char *str); const char *str);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config); PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetArgv( PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
_PyCoreConfig *config, PyConfig *config,
Py_ssize_t argc, Py_ssize_t argc,
char * const *argv); char * const *argv);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetWideArgv(_PyCoreConfig *config, PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
Py_ssize_t argc, Py_ssize_t argc,
wchar_t * const *argv); 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!) */ /* PEP 432 Multi-phase initialization API (Private while provisional!) */
PyAPI_FUNC(_PyInitError) _Py_PreInitialize( PyAPI_FUNC(PyStatus) Py_PreInitialize(
const _PyPreConfig *src_config); const PyPreConfig *src_config);
PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromArgs( PyAPI_FUNC(PyStatus) Py_PreInitializeFromBytesArgs(
const _PyPreConfig *src_config, const PyPreConfig *src_config,
Py_ssize_t argc, Py_ssize_t argc,
char **argv); char **argv);
PyAPI_FUNC(_PyInitError) _Py_PreInitializeFromWideArgs( PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs(
const _PyPreConfig *src_config, const PyPreConfig *src_config,
Py_ssize_t argc, Py_ssize_t argc,
wchar_t **argv); wchar_t **argv);
@ -30,22 +30,22 @@ PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
/* Initialization and finalization */ /* Initialization and finalization */
PyAPI_FUNC(_PyInitError) _Py_InitializeFromConfig( PyAPI_FUNC(PyStatus) Py_InitializeFromConfig(
const _PyCoreConfig *config); const PyConfig *config);
PyAPI_FUNC(_PyInitError) _Py_InitializeFromArgs( PyAPI_FUNC(PyStatus) _Py_InitializeFromArgs(
const _PyCoreConfig *config, const PyConfig *config,
Py_ssize_t argc, Py_ssize_t argc,
char * const *argv); char * const *argv);
PyAPI_FUNC(_PyInitError) _Py_InitializeFromWideArgs( PyAPI_FUNC(PyStatus) _Py_InitializeFromWideArgs(
const _PyCoreConfig *config, const PyConfig *config,
Py_ssize_t argc, Py_ssize_t argc,
wchar_t * const *argv); 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 /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
* exit functions. * exit functions.

View file

@ -6,13 +6,11 @@
extern "C" { extern "C" {
#endif #endif
#include "cpython/coreconfig.h" #include "cpython/initconfig.h"
PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int); PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);
PyAPI_FUNC(_PyCoreConfig *) _PyInterpreterState_GetCoreConfig(PyInterpreterState *);
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetMainModule(PyInterpreterState *); PyAPI_FUNC(PyObject *) _PyInterpreterState_GetMainModule(PyInterpreterState *);
/* State unique per thread */ /* 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_DATA(_PyPathConfig) _Py_path_config;
PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void); extern void _PyPathConfig_ClearGlobal(void);
PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal( extern PyStatus _PyPathConfig_SetGlobal(
const struct _PyPathConfig *config); const struct _PyPathConfig *pathconfig);
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl( extern PyStatus _PyPathConfig_Calculate(
_PyPathConfig *config, _PyPathConfig *pathconfig,
const _PyCoreConfig *core_config); const PyConfig *config);
PyAPI_FUNC(int) _PyPathConfig_ComputeSysPath0( extern int _PyPathConfig_ComputeSysPath0(
const _PyWstrList *argv, const PyWideStringList *argv,
PyObject **path0); PyObject **path0);
PyAPI_FUNC(int) _Py_FindEnvConfigValue( extern int _Py_FindEnvConfigValue(
FILE *env_file, FILE *env_file,
const wchar_t *key, const wchar_t *key,
wchar_t *value, wchar_t *value,

View file

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

View file

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

View file

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

View file

@ -322,7 +322,7 @@ PYTHON_OBJS= \
Python/ceval.o \ Python/ceval.o \
Python/codecs.o \ Python/codecs.o \
Python/compile.o \ Python/compile.o \
Python/coreconfig.o \ Python/context.o \
Python/dynamic_annotations.o \ Python/dynamic_annotations.o \
Python/errors.o \ Python/errors.o \
Python/frozenmain.o \ Python/frozenmain.o \
@ -333,8 +333,10 @@ PYTHON_OBJS= \
Python/getplatform.o \ Python/getplatform.o \
Python/getversion.o \ Python/getversion.o \
Python/graminit.o \ Python/graminit.o \
Python/hamt.o \
Python/import.o \ Python/import.o \
Python/importdl.o \ Python/importdl.o \
Python/initconfig.o \
Python/marshal.o \ Python/marshal.o \
Python/modsupport.o \ Python/modsupport.o \
Python/mysnprintf.o \ Python/mysnprintf.o \
@ -349,8 +351,6 @@ PYTHON_OBJS= \
Python/pylifecycle.o \ Python/pylifecycle.o \
Python/pymath.o \ Python/pymath.o \
Python/pystate.o \ Python/pystate.o \
Python/context.o \
Python/hamt.o \
Python/pythonrun.o \ Python/pythonrun.o \
Python/pytime.o \ Python/pytime.o \
Python/bootstrap_hash.o \ Python/bootstrap_hash.o \
@ -1052,9 +1052,9 @@ PYTHON_HEADERS= \
$(srcdir)/Include/Python-ast.h \ $(srcdir)/Include/Python-ast.h \
\ \
$(srcdir)/Include/cpython/abstract.h \ $(srcdir)/Include/cpython/abstract.h \
$(srcdir)/Include/cpython/coreconfig.h \
$(srcdir)/Include/cpython/dictobject.h \ $(srcdir)/Include/cpython/dictobject.h \
$(srcdir)/Include/cpython/fileobject.h \ $(srcdir)/Include/cpython/fileobject.h \
$(srcdir)/Include/cpython/initconfig.h \
$(srcdir)/Include/cpython/interpreteridobject.h \ $(srcdir)/Include/cpython/interpreteridobject.h \
$(srcdir)/Include/cpython/object.h \ $(srcdir)/Include/cpython/object.h \
$(srcdir)/Include/cpython/objimpl.h \ $(srcdir)/Include/cpython/objimpl.h \
@ -1072,11 +1072,11 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_ceval.h \ $(srcdir)/Include/internal/pycore_ceval.h \
$(srcdir)/Include/internal/pycore_condvar.h \ $(srcdir)/Include/internal/pycore_condvar.h \
$(srcdir)/Include/internal/pycore_context.h \ $(srcdir)/Include/internal/pycore_context.h \
$(srcdir)/Include/internal/pycore_coreconfig.h \
$(srcdir)/Include/internal/pycore_fileutils.h \ $(srcdir)/Include/internal/pycore_fileutils.h \
$(srcdir)/Include/internal/pycore_getopt.h \ $(srcdir)/Include/internal/pycore_getopt.h \
$(srcdir)/Include/internal/pycore_gil.h \ $(srcdir)/Include/internal/pycore_gil.h \
$(srcdir)/Include/internal/pycore_hamt.h \ $(srcdir)/Include/internal/pycore_hamt.h \
$(srcdir)/Include/internal/pycore_initconfig.h \
$(srcdir)/Include/internal/pycore_object.h \ $(srcdir)/Include/internal/pycore_object.h \
$(srcdir)/Include/internal/pycore_pathconfig.h \ $(srcdir)/Include/internal/pycore_pathconfig.h \
$(srcdir)/Include/internal/pycore_pyerrors.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; PyObject *RawIO_class = (PyObject *)&PyFileIO_Type;
#ifdef MS_WINDOWS #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') { if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type; RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type;
encoding = "utf-8"; encoding = "utf-8";

View file

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

View file

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

View file

@ -1,5 +1,5 @@
#include "Python.h" #include "Python.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#include "pycore_traceback.h" #include "pycore_traceback.h"
#include "pythread.h" #include "pythread.h"
#include <signal.h> #include <signal.h>
@ -1315,7 +1315,7 @@ faulthandler_init_enable(void)
return 0; return 0;
} }
_PyInitError PyStatus
_PyFaulthandler_Init(int enable) _PyFaulthandler_Init(int enable)
{ {
#ifdef HAVE_SIGALTSTACK #ifdef HAVE_SIGALTSTACK
@ -1340,17 +1340,17 @@ _PyFaulthandler_Init(int enable)
thread.cancel_event = PyThread_allocate_lock(); thread.cancel_event = PyThread_allocate_lock();
thread.running = PyThread_allocate_lock(); thread.running = PyThread_allocate_lock();
if (!thread.cancel_event || !thread.running) { 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); PyThread_acquire_lock(thread.cancel_event, 1);
#endif #endif
if (enable) { if (enable) {
if (faulthandler_init_enable() < 0) { 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) void _PyFaulthandler_Fini(void)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2824,7 +2824,7 @@ _PyBuiltin_Init(void)
{ {
PyObject *mod, *dict, *debug; 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 || if (PyType_Ready(&PyFilter_Type) < 0 ||
PyType_Ready(&PyMap_Type) < 0 || PyType_Ready(&PyMap_Type) < 0 ||

View file

@ -1,5 +1,5 @@
#include "Python.h" #include "Python.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
# include <windows.h> # include <windows.h>
/* All sample MSDN wincrypt programs include the header below. It is at least /* 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 PyStatus
_Py_HashRandomization_Init(const _PyCoreConfig *config) _Py_HashRandomization_Init(const PyConfig *config)
{ {
void *secret = &_Py_HashSecret; void *secret = &_Py_HashSecret;
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t); Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
if (_Py_HashSecret_Initialized) { if (_Py_HashSecret_Initialized) {
return _Py_INIT_OK(); return _PyStatus_OK();
} }
_Py_HashSecret_Initialized = 1; _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. */ pyurandom() is non-blocking mode (blocking=0): see the PEP 524. */
res = pyurandom(secret, secret_size, 0, 0); res = pyurandom(secret, secret_size, 0, 0);
if (res < 0) { if (res < 0) {
return _Py_INIT_ERR("failed to get random numbers " return _PyStatus_ERR("failed to get random numbers "
"to initialize Python"); "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; PyCodeObject *co = NULL;
PyCompilerFlags local_flags; PyCompilerFlags local_flags;
int merged; int merged;
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config; PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
if (!__doc__) { if (!__doc__) {
__doc__ = PyUnicode_InternFromString("__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"); 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){ c->u->u_scope_type != COMPILER_SCOPE_COMPREHENSION){
return compiler_error(c, "'await' outside async function"); 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) const char *pathname, FILE *fp)
{ {
int flags = BIND_FIRST | BIND_DEFERRED; int flags = BIND_FIRST | BIND_DEFERRED;
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose; int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
if (verbose) { if (verbose) {
flags = BIND_FIRST | BIND_IMMEDIATE | flags = BIND_FIRST | BIND_IMMEDIATE |
BIND_NONFATAL | BIND_VERBOSE; BIND_NONFATAL | BIND_VERBOSE;

View file

@ -2,7 +2,7 @@
/* Error handling */ /* Error handling */
#include "Python.h" #include "Python.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#include "pycore_pyerrors.h" #include "pycore_pyerrors.h"
#include "pycore_pystate.h" #include "pycore_pystate.h"
#include "pycore_traceback.h" #include "pycore_traceback.h"
@ -1090,16 +1090,16 @@ static PyStructSequence_Desc UnraisableHookArgs_desc = {
}; };
_PyInitError PyStatus
_PyErr_Init(void) _PyErr_Init(void)
{ {
if (UnraisableHookArgsType.tp_name == NULL) { if (UnraisableHookArgsType.tp_name == NULL) {
if (PyStructSequence_InitType2(&UnraisableHookArgsType, if (PyStructSequence_InitType2(&UnraisableHookArgsType,
&UnraisableHookArgs_desc) < 0) { &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 int
Py_FrozenMain(int argc, char **argv) Py_FrozenMain(int argc, char **argv)
{ {
_PyInitError err = _PyRuntime_Initialize(); PyStatus status = _PyRuntime_Initialize();
if (_PyInitError_Failed(err)) { if (PyStatus_Exception(status)) {
_Py_ExitInitError(err); Py_ExitStatusException(status);
} }
const char *p; const char *p;
@ -39,11 +39,11 @@ Py_FrozenMain(int argc, char **argv)
} }
} }
_PyCoreConfig config; PyConfig config;
err = _PyCoreConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (_PyInitError_Failed(err)) { if (PyStatus_Exception(status)) {
_PyCoreConfig_Clear(&config); PyConfig_Clear(&config);
_Py_ExitInitError(err); Py_ExitStatusException(status);
} }
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */ config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
@ -85,10 +85,10 @@ Py_FrozenMain(int argc, char **argv)
if (argc >= 1) if (argc >= 1)
Py_SetProgramName(argv_copy[0]); Py_SetProgramName(argv_copy[0]);
err = _Py_InitializeFromConfig(&config); status = Py_InitializeFromConfig(&config);
_PyCoreConfig_Clear(&config); PyConfig_Clear(&config);
if (_PyInitError_Failed(err)) { if (PyStatus_Exception(status)) {
_Py_ExitInitError(err); Py_ExitStatusException(status);
} }
#ifdef MS_WINDOWS #ifdef MS_WINDOWS

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,5 +1,5 @@
#include "Python.h" #include "Python.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#include "pycore_getopt.h" #include "pycore_getopt.h"
#include "pycore_pystate.h" /* _PyRuntime_Initialize() */ #include "pycore_pystate.h" /* _PyRuntime_Initialize() */
#include <locale.h> /* setlocale() */ #include <locale.h> /* setlocale() */
@ -7,8 +7,13 @@
#define DECODE_LOCALE_ERR(NAME, LEN) \ #define DECODE_LOCALE_ERR(NAME, LEN) \
(((LEN) == -2) \ (((LEN) == -2) \
? _Py_INIT_ERR("cannot decode " NAME) \ ? _PyStatus_ERR("cannot decode " NAME) \
: _Py_INIT_NO_MEMORY()) : _PyStatus_NO_MEMORY())
/* Forward declarations */
static void
preconfig_copy(PyPreConfig *config, const PyPreConfig *config2);
/* --- File system encoding/errors -------------------------------- */ /* --- File system encoding/errors -------------------------------- */
@ -67,22 +72,22 @@ _Py_SetFileSystemEncoding(const char *encoding, const char *errors)
/* --- _PyArgv ---------------------------------------------------- */ /* --- _PyArgv ---------------------------------------------------- */
/* Decode bytes_argv using Py_DecodeLocale() */ /* Decode bytes_argv using Py_DecodeLocale() */
_PyInitError PyStatus
_PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list) _PyArgv_AsWstrList(const _PyArgv *args, PyWideStringList *list)
{ {
_PyWstrList wargv = _PyWstrList_INIT; PyWideStringList wargv = PyWideStringList_INIT;
if (args->use_bytes_argv) { if (args->use_bytes_argv) {
size_t size = sizeof(wchar_t*) * args->argc; size_t size = sizeof(wchar_t*) * args->argc;
wargv.items = (wchar_t **)PyMem_RawMalloc(size); wargv.items = (wchar_t **)PyMem_RawMalloc(size);
if (wargv.items == NULL) { if (wargv.items == NULL) {
return _Py_INIT_NO_MEMORY(); return _PyStatus_NO_MEMORY();
} }
for (Py_ssize_t i = 0; i < args->argc; i++) { for (Py_ssize_t i = 0; i < args->argc; i++) {
size_t len; size_t len;
wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len); wchar_t *arg = Py_DecodeLocale(args->bytes_argv[i], &len);
if (arg == NULL) { if (arg == NULL) {
_PyWstrList_Clear(&wargv); _PyWideStringList_Clear(&wargv);
return DECODE_LOCALE_ERR("command line arguments", return DECODE_LOCALE_ERR("command line arguments",
(Py_ssize_t)len); (Py_ssize_t)len);
} }
@ -90,17 +95,17 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
wargv.length++; wargv.length++;
} }
_PyWstrList_Clear(list); _PyWideStringList_Clear(list);
*list = wargv; *list = wargv;
} }
else { else {
wargv.length = args->argc; wargv.length = args->argc;
wargv.items = (wchar_t **)args->wchar_argv; wargv.items = (wchar_t **)args->wchar_argv;
if (_PyWstrList_Copy(list, &wargv) < 0) { if (_PyWideStringList_Copy(list, &wargv) < 0) {
return _Py_INIT_NO_MEMORY(); return _PyStatus_NO_MEMORY();
} }
} }
return _Py_INIT_OK(); return _PyStatus_OK();
} }
@ -109,12 +114,12 @@ _PyArgv_AsWstrList(const _PyArgv *args, _PyWstrList *list)
void void
_PyPreCmdline_Clear(_PyPreCmdline *cmdline) _PyPreCmdline_Clear(_PyPreCmdline *cmdline)
{ {
_PyWstrList_Clear(&cmdline->argv); _PyWideStringList_Clear(&cmdline->argv);
_PyWstrList_Clear(&cmdline->xoptions); _PyWideStringList_Clear(&cmdline->xoptions);
} }
_PyInitError PyStatus
_PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args) _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
{ {
return _PyArgv_AsWstrList(args, &cmdline->argv); return _PyArgv_AsWstrList(args, &cmdline->argv);
@ -122,7 +127,7 @@ _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline, const _PyArgv *args)
static void static void
_PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config) precmdline_get_preconfig(_PyPreCmdline *cmdline, const PyPreConfig *config)
{ {
#define COPY_ATTR(ATTR) \ #define COPY_ATTR(ATTR) \
if (config->ATTR != -1) { \ if (config->ATTR != -1) { \
@ -138,7 +143,7 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
static void static void
_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config) precmdline_set_preconfig(const _PyPreCmdline *cmdline, PyPreConfig *config)
{ {
#define COPY_ATTR(ATTR) \ #define COPY_ATTR(ATTR) \
config->ATTR = cmdline->ATTR config->ATTR = cmdline->ATTR
@ -151,33 +156,34 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
} }
int PyStatus
_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config) _PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config)
{ {
#define COPY_ATTR(ATTR) \ #define COPY_ATTR(ATTR) \
config->ATTR = cmdline->ATTR config->ATTR = cmdline->ATTR
if (_PyWstrList_Extend(&config->xoptions, &cmdline->xoptions) < 0) { PyStatus status = _PyWideStringList_Extend(&config->xoptions, &cmdline->xoptions);
return -1; if (_PyStatus_EXCEPTION(status)) {
return status;
} }
COPY_ATTR(isolated); COPY_ATTR(isolated);
COPY_ATTR(use_environment); COPY_ATTR(use_environment);
COPY_ATTR(dev_mode); COPY_ATTR(dev_mode);
return 0; return _PyStatus_OK();
#undef COPY_ATTR #undef COPY_ATTR
} }
/* Parse the command line arguments */ /* Parse the command line arguments */
static _PyInitError static PyStatus
precmdline_parse_cmdline(_PyPreCmdline *cmdline) precmdline_parse_cmdline(_PyPreCmdline *cmdline)
{ {
const _PyWstrList *argv = &cmdline->argv; const PyWideStringList *argv = &cmdline->argv;
_PyOS_ResetGetOpt(); _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 */ is responsible for that */
_PyOS_opterr = 0; _PyOS_opterr = 0;
do { do {
@ -199,32 +205,34 @@ precmdline_parse_cmdline(_PyPreCmdline *cmdline)
case 'X': case 'X':
{ {
if (_PyWstrList_Append(&cmdline->xoptions, _PyOS_optarg) < 0) { PyStatus status = PyWideStringList_Append(&cmdline->xoptions,
return _Py_INIT_NO_MEMORY(); _PyOS_optarg);
if (_PyStatus_EXCEPTION(status)) {
return status;
} }
break; break;
} }
default: default:
/* ignore other argument: /* ignore other argument:
handled by _PyCoreConfig_Read() */ handled by PyConfig_Read() */
break; break;
} }
} while (1); } while (1);
return _Py_INIT_OK(); return _PyStatus_OK();
} }
_PyInitError PyStatus
_PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig) _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
{ {
_PyPreCmdline_GetPreConfig(cmdline, preconfig); precmdline_get_preconfig(cmdline, preconfig);
if (preconfig->parse_argv) { if (preconfig->parse_argv) {
_PyInitError err = precmdline_parse_cmdline(cmdline); PyStatus status = precmdline_parse_cmdline(cmdline);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
} }
@ -254,15 +262,15 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const _PyPreConfig *preconfig)
assert(cmdline->isolated >= 0); assert(cmdline->isolated >= 0);
assert(cmdline->dev_mode >= 0); assert(cmdline->dev_mode >= 0);
return _Py_INIT_OK(); return _PyStatus_OK();
} }
/* --- _PyPreConfig ----------------------------------------------- */ /* --- PyPreConfig ----------------------------------------------- */
void void
_PyPreConfig_InitCompatConfig(_PyPreConfig *config) _PyPreConfig_InitCompatConfig(PyPreConfig *config)
{ {
memset(config, 0, sizeof(*config)); memset(config, 0, sizeof(*config));
@ -291,7 +299,7 @@ _PyPreConfig_InitCompatConfig(_PyPreConfig *config)
void void
_PyPreConfig_InitPythonConfig(_PyPreConfig *config) PyPreConfig_InitPythonConfig(PyPreConfig *config)
{ {
_PyPreConfig_InitCompatConfig(config); _PyPreConfig_InitCompatConfig(config);
@ -312,7 +320,7 @@ _PyPreConfig_InitPythonConfig(_PyPreConfig *config)
void void
_PyPreConfig_InitIsolatedConfig(_PyPreConfig *config) PyPreConfig_InitIsolatedConfig(PyPreConfig *config)
{ {
_PyPreConfig_InitCompatConfig(config); _PyPreConfig_InitCompatConfig(config);
@ -329,37 +337,37 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
void void
_PyPreConfig_InitFromPreConfig(_PyPreConfig *config, _PyPreConfig_InitFromPreConfig(PyPreConfig *config,
const _PyPreConfig *config2) const PyPreConfig *config2)
{ {
_PyPreConfig_InitCompatConfig(config); PyPreConfig_InitPythonConfig(config);
_PyPreConfig_Copy(config, config2); preconfig_copy(config, config2);
} }
void void
_PyPreConfig_InitFromCoreConfig(_PyPreConfig *config, _PyPreConfig_InitFromConfig(PyPreConfig *preconfig, const PyConfig *config)
const _PyCoreConfig *coreconfig)
{ {
_PyConfigInitEnum config_init = (_PyConfigInitEnum)coreconfig->_config_init; _PyConfigInitEnum config_init = (_PyConfigInitEnum)config->_config_init;
switch (config_init) { switch (config_init) {
case _PyConfig_INIT_PYTHON: case _PyConfig_INIT_PYTHON:
_PyPreConfig_InitPythonConfig(config); PyPreConfig_InitPythonConfig(preconfig);
break; break;
case _PyConfig_INIT_ISOLATED: case _PyConfig_INIT_ISOLATED:
_PyPreConfig_InitIsolatedConfig(config); PyPreConfig_InitIsolatedConfig(preconfig);
break; break;
case _PyConfig_INIT_COMPAT: case _PyConfig_INIT_COMPAT:
default: default:
_PyPreConfig_InitCompatConfig(config); _PyPreConfig_InitCompatConfig(preconfig);
} }
_PyPreConfig_GetCoreConfig(config, coreconfig); _PyPreConfig_GetConfig(preconfig, config);
} }
void static void
_PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2) preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
{ {
assert(config2->_config_version == _Py_CONFIG_VERSION);
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
COPY_ATTR(_config_init); COPY_ATTR(_config_init);
@ -381,7 +389,7 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
PyObject* PyObject*
_PyPreConfig_AsDict(const _PyPreConfig *config) _PyPreConfig_AsDict(const PyPreConfig *config)
{ {
PyObject *dict; PyObject *dict;
@ -427,12 +435,11 @@ _PyPreConfig_AsDict(const _PyPreConfig *config)
void void
_PyPreConfig_GetCoreConfig(_PyPreConfig *config, _PyPreConfig_GetConfig(PyPreConfig *preconfig, const PyConfig *config)
const _PyCoreConfig *core_config)
{ {
#define COPY_ATTR(ATTR) \ #define COPY_ATTR(ATTR) \
if (core_config->ATTR != -1) { \ if (config->ATTR != -1) { \
config->ATTR = core_config->ATTR; \ preconfig->ATTR = config->ATTR; \
} }
COPY_ATTR(parse_argv); COPY_ATTR(parse_argv);
@ -445,7 +452,7 @@ _PyPreConfig_GetCoreConfig(_PyPreConfig *config,
static void static void
_PyPreConfig_GetGlobalConfig(_PyPreConfig *config) preconfig_get_global_vars(PyPreConfig *config)
{ {
if (config->_config_init != _PyConfig_INIT_COMPAT) { if (config->_config_init != _PyConfig_INIT_COMPAT) {
/* Python and Isolated configuration ignore global variables */ /* Python and Isolated configuration ignore global variables */
@ -476,7 +483,7 @@ _PyPreConfig_GetGlobalConfig(_PyPreConfig *config)
static void static void
_PyPreConfig_SetGlobalConfig(const _PyPreConfig *config) preconfig_set_global_vars(const PyPreConfig *config)
{ {
#define COPY_FLAG(ATTR, VAR) \ #define COPY_FLAG(ATTR, VAR) \
if (config->ATTR >= 0) { \ if (config->ATTR >= 0) { \
@ -555,7 +562,7 @@ _Py_get_env_flag(int use_environment, int *flag, const char *name)
const wchar_t* 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++) { for (Py_ssize_t i=0; i < xoptions->length; i++) {
const wchar_t *option = xoptions->items[i]; const wchar_t *option = xoptions->items[i];
@ -575,8 +582,8 @@ _Py_get_xoption(const _PyWstrList *xoptions, const wchar_t *name)
} }
static _PyInitError static PyStatus
preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline) preconfig_init_utf8_mode(PyPreConfig *config, const _PyPreCmdline *cmdline)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
if (config->legacy_windows_fs_encoding) { if (config->legacy_windows_fs_encoding) {
@ -585,7 +592,7 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
#endif #endif
if (config->utf8_mode >= 0) { if (config->utf8_mode >= 0) {
return _Py_INIT_OK(); return _PyStatus_OK();
} }
const wchar_t *xopt; const wchar_t *xopt;
@ -601,13 +608,13 @@ preconfig_init_utf8_mode(_PyPreConfig *config, const _PyPreCmdline *cmdline)
config->utf8_mode = 0; config->utf8_mode = 0;
} }
else { else {
return _Py_INIT_ERR("invalid -X utf8 option value"); return _PyStatus_ERR("invalid -X utf8 option value");
} }
} }
else { else {
config->utf8_mode = 1; config->utf8_mode = 1;
} }
return _Py_INIT_OK(); return _PyStatus_OK();
} }
const char *opt = _Py_GetEnv(config->use_environment, "PYTHONUTF8"); 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; config->utf8_mode = 0;
} }
else { else {
return _Py_INIT_ERR("invalid PYTHONUTF8 environment " return _PyStatus_ERR("invalid PYTHONUTF8 environment "
"variable value"); "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) { if (config->utf8_mode < 0) {
config->utf8_mode = 0; config->utf8_mode = 0;
} }
return _Py_INIT_OK(); return _PyStatus_OK();
} }
static void static void
preconfig_init_coerce_c_locale(_PyPreConfig *config) preconfig_init_coerce_c_locale(PyPreConfig *config)
{ {
if (!config->configure_locale) { if (!config->configure_locale) {
config->coerce_c_locale = 0; config->coerce_c_locale = 0;
@ -693,8 +700,8 @@ preconfig_init_coerce_c_locale(_PyPreConfig *config)
} }
static _PyInitError static PyStatus
preconfig_init_allocator(_PyPreConfig *config) preconfig_init_allocator(PyPreConfig *config)
{ {
if (config->allocator == PYMEM_ALLOCATOR_NOT_SET) { if (config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
/* bpo-34247. The PYTHONMALLOC environment variable has the priority /* bpo-34247. The PYTHONMALLOC environment variable has the priority
@ -705,7 +712,7 @@ preconfig_init_allocator(_PyPreConfig *config)
if (envvar) { if (envvar) {
PyMemAllocatorName name; PyMemAllocatorName name;
if (_PyMem_GetAllocatorName(envvar, &name) < 0) { if (_PyMem_GetAllocatorName(envvar, &name) < 0) {
return _Py_INIT_ERR("PYTHONMALLOC: unknown allocator"); return _PyStatus_ERR("PYTHONMALLOC: unknown allocator");
} }
config->allocator = (int)name; config->allocator = (int)name;
} }
@ -714,21 +721,21 @@ preconfig_init_allocator(_PyPreConfig *config)
if (config->dev_mode && config->allocator == PYMEM_ALLOCATOR_NOT_SET) { if (config->dev_mode && config->allocator == PYMEM_ALLOCATOR_NOT_SET) {
config->allocator = PYMEM_ALLOCATOR_DEBUG; config->allocator = PYMEM_ALLOCATOR_DEBUG;
} }
return _Py_INIT_OK(); return _PyStatus_OK();
} }
static _PyInitError static PyStatus
preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline) preconfig_read(PyPreConfig *config, _PyPreCmdline *cmdline)
{ {
_PyInitError err; PyStatus status;
err = _PyPreCmdline_Read(cmdline, config); status = _PyPreCmdline_Read(cmdline, config);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
_PyPreCmdline_SetPreConfig(cmdline, config); precmdline_set_preconfig(cmdline, config);
/* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */ /* legacy_windows_fs_encoding, coerce_c_locale, utf8_mode */
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
@ -739,15 +746,15 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
preconfig_init_coerce_c_locale(config); preconfig_init_coerce_c_locale(config);
err = preconfig_init_utf8_mode(config, cmdline); status = preconfig_init_utf8_mode(config, cmdline);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
/* allocator */ /* allocator */
err = preconfig_init_allocator(config); status = preconfig_init_allocator(config);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
assert(config->coerce_c_locale >= 0); assert(config->coerce_c_locale >= 0);
@ -760,7 +767,7 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
assert(config->use_environment >= 0); assert(config->use_environment >= 0);
assert(config->dev_mode >= 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 - environment variables
- Py_xxx global configuration variables - Py_xxx global configuration variables
- the LC_CTYPE locale */ - the LC_CTYPE locale */
_PyInitError PyStatus
_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args) _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
{ {
_PyInitError err; PyStatus status;
err = _PyRuntime_Initialize(); status = _PyRuntime_Initialize();
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
_PyPreConfig_GetGlobalConfig(config); preconfig_get_global_vars(config);
/* Copy LC_CTYPE locale, since it's modified later */ /* Copy LC_CTYPE locale, since it's modified later */
const char *loc = setlocale(LC_CTYPE, NULL); const char *loc = setlocale(LC_CTYPE, NULL);
if (loc == 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); char *init_ctype_locale = _PyMem_RawStrdup(loc);
if (init_ctype_locale == NULL) { 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 */ /* Save the config to be able to restore it if encodings change */
_PyPreConfig save_config; PyPreConfig save_config;
_PyPreConfig_InitFromPreConfig(&save_config, config); _PyPreConfig_InitFromPreConfig(&save_config, config);
/* Set LC_CTYPE to the user preferred locale */ /* Set LC_CTYPE to the user preferred locale */
@ -808,8 +815,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
#endif #endif
if (args) { if (args) {
err = _PyPreCmdline_SetArgv(&cmdline, args); status = _PyPreCmdline_SetArgv(&cmdline, args);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
goto done; goto done;
} }
} }
@ -823,7 +830,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
/* Watchdog to prevent an infinite loop */ /* Watchdog to prevent an infinite loop */
loops++; loops++;
if (loops == 3) { if (loops == 3) {
err = _Py_INIT_ERR("Encoding changed twice while " status = _PyStatus_ERR("Encoding changed twice while "
"reading the configuration"); "reading the configuration");
goto done; goto done;
} }
@ -835,8 +842,8 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
#endif #endif
err = preconfig_read(config, &cmdline); status = preconfig_read(config, &cmdline);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
goto done; goto done;
} }
@ -877,14 +884,14 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
just keep UTF-8 Mode value. */ just keep UTF-8 Mode value. */
int new_utf8_mode = config->utf8_mode; int new_utf8_mode = config->utf8_mode;
int new_coerce_c_locale = config->coerce_c_locale; 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->utf8_mode = new_utf8_mode;
config->coerce_c_locale = new_coerce_c_locale; config->coerce_c_locale = new_coerce_c_locale;
/* The encoding changed: read again the configuration /* The encoding changed: read again the configuration
with the new encoding */ with the new encoding */
} }
err = _Py_INIT_OK(); status = _PyStatus_OK();
done: done:
if (init_ctype_locale != NULL) { if (init_ctype_locale != NULL) {
@ -896,7 +903,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding; Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
#endif #endif
_PyPreCmdline_Clear(&cmdline); _PyPreCmdline_Clear(&cmdline);
return err; return status;
} }
@ -912,26 +919,26 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
Do nothing if called after Py_Initialize(): ignore the new Do nothing if called after Py_Initialize(): ignore the new
pre-configuration. */ pre-configuration. */
_PyInitError PyStatus
_PyPreConfig_Write(const _PyPreConfig *src_config) _PyPreConfig_Write(const PyPreConfig *src_config)
{ {
_PyPreConfig config; PyPreConfig config;
_PyPreConfig_InitFromPreConfig(&config, src_config); _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyRuntime.core_initialized) { if (_PyRuntime.core_initialized) {
/* bpo-34008: Calling this functions after Py_Initialize() ignores /* bpo-34008: Calling this functions after Py_Initialize() ignores
the new configuration. */ the new configuration. */
return _Py_INIT_OK(); return _PyStatus_OK();
} }
PyMemAllocatorName name = (PyMemAllocatorName)config.allocator; PyMemAllocatorName name = (PyMemAllocatorName)config.allocator;
if (name != PYMEM_ALLOCATOR_NOT_SET) { if (name != PYMEM_ALLOCATOR_NOT_SET) {
if (_PyMem_SetupAllocators(name) < 0) { 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.configure_locale) {
if (config.coerce_c_locale) { if (config.coerce_c_locale) {
@ -946,7 +953,7 @@ _PyPreConfig_Write(const _PyPreConfig *src_config)
} }
/* Write the new pre-configuration into _PyRuntime */ /* 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 "Python.h"
#include "pycore_ceval.h" #include "pycore_ceval.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#include "pycore_pymem.h" #include "pycore_pymem.h"
#include "pycore_pystate.h" #include "pycore_pystate.h"
#include "pycore_pylifecycle.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 void _PyThreadState_Delete(_PyRuntimeState *runtime, PyThreadState *tstate);
static _PyInitError static PyStatus
_PyRuntimeState_Init_impl(_PyRuntimeState *runtime) _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
{ {
/* We preserve the hook across init, because there is /* We preserve the hook across init, because there is
@ -60,7 +60,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
_PyGC_Initialize(&runtime->gc); _PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval); _PyEval_Initialize(&runtime->ceval);
_PyPreConfig_InitPythonConfig(&runtime->preconfig); PyPreConfig_InitPythonConfig(&runtime->preconfig);
runtime->gilstate.check_enabled = 1; runtime->gilstate.check_enabled = 1;
@ -71,22 +71,22 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
runtime->interpreters.mutex = PyThread_allocate_lock(); runtime->interpreters.mutex = PyThread_allocate_lock();
if (runtime->interpreters.mutex == NULL) { 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->interpreters.next_id = -1;
runtime->xidregistry.mutex = PyThread_allocate_lock(); runtime->xidregistry.mutex = PyThread_allocate_lock();
if (runtime->xidregistry.mutex == NULL) { 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. // Set it to the ID of the main thread of the main interpreter.
runtime->main_thread = PyThread_get_thread_ident(); runtime->main_thread = PyThread_get_thread_ident();
return _Py_INIT_OK(); return _PyStatus_OK();
} }
_PyInitError PyStatus
_PyRuntimeState_Init(_PyRuntimeState *runtime) _PyRuntimeState_Init(_PyRuntimeState *runtime)
{ {
/* Force default allocator, since _PyRuntimeState_Fini() must /* Force default allocator, since _PyRuntimeState_Fini() must
@ -94,10 +94,10 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
PyMemAllocatorEx old_alloc; PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &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); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return err; return status;
} }
void void
@ -163,7 +163,7 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
static void _PyGILState_NoteThreadState( static void _PyGILState_NoteThreadState(
struct _gilstate_runtime_state *gilstate, PyThreadState* tstate); struct _gilstate_runtime_state *gilstate, PyThreadState* tstate);
_PyInitError PyStatus
_PyInterpreterState_Enable(_PyRuntimeState *runtime) _PyInterpreterState_Enable(_PyRuntimeState *runtime)
{ {
struct pyinterpreters *interpreters = &runtime->interpreters; struct pyinterpreters *interpreters = &runtime->interpreters;
@ -182,11 +182,11 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
if (interpreters->mutex == NULL) { 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 * PyInterpreterState *
@ -205,8 +205,11 @@ PyInterpreterState_New(void)
interp->id_refcount = -1; interp->id_refcount = -1;
interp->check_interval = 100; interp->check_interval = 100;
_PyInitError err = _PyCoreConfig_InitPythonConfig(&interp->core_config); PyStatus status = PyConfig_InitPythonConfig(&interp->config);
if (_Py_INIT_FAILED(err)) { 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); PyMem_RawFree(interp);
return NULL; return NULL;
} }
@ -269,7 +272,7 @@ _PyInterpreterState_Clear(_PyRuntimeState *runtime, PyInterpreterState *interp)
Py_CLEAR(interp->audit_hooks); 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_path);
Py_CLEAR(interp->codec_search_cache); Py_CLEAR(interp->codec_search_cache);
Py_CLEAR(interp->codec_error_registry); Py_CLEAR(interp->codec_error_registry);
@ -523,12 +526,6 @@ _PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
interp->requires_idref = required ? 1 : 0; interp->requires_idref = required ? 1 : 0;
} }
_PyCoreConfig *
_PyInterpreterState_GetCoreConfig(PyInterpreterState *interp)
{
return &interp->core_config;
}
PyObject * PyObject *
_PyInterpreterState_GetMainModule(PyInterpreterState *interp) _PyInterpreterState_GetMainModule(PyInterpreterState *interp)
{ {
@ -775,7 +772,7 @@ _PyState_ClearModules(void)
void void
PyThreadState_Clear(PyThreadState *tstate) PyThreadState_Clear(PyThreadState *tstate)
{ {
int verbose = tstate->interp->core_config.verbose; int verbose = tstate->interp->config.verbose;
if (verbose && tstate->frame != NULL) if (verbose && tstate->frame != NULL)
fprintf(stderr, fprintf(stderr,

View file

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

View file

@ -17,7 +17,7 @@ Data members:
#include "Python.h" #include "Python.h"
#include "code.h" #include "code.h"
#include "frameobject.h" #include "frameobject.h"
#include "pycore_coreconfig.h" #include "pycore_initconfig.h"
#include "pycore_pylifecycle.h" #include "pycore_pylifecycle.h"
#include "pycore_pymem.h" #include "pycore_pymem.h"
#include "pycore_pathconfig.h" #include "pycore_pathconfig.h"
@ -752,7 +752,7 @@ sys_getfilesystemencoding_impl(PyObject *module)
/*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/ /*[clinic end generated code: output=1dc4bdbe9be44aa7 input=8475f8649b8c7d8c]*/
{ {
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE(); PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
const _PyCoreConfig *config = &interp->core_config; const PyConfig *config = &interp->config;
return PyUnicode_FromWideChar(config->filesystem_encoding, -1); return PyUnicode_FromWideChar(config->filesystem_encoding, -1);
} }
@ -767,7 +767,7 @@ sys_getfilesystemencodeerrors_impl(PyObject *module)
/*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/ /*[clinic end generated code: output=ba77b36bbf7c96f5 input=22a1e8365566f1e5]*/
{ {
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE(); PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
const _PyCoreConfig *config = &interp->core_config; const PyConfig *config = &interp->config;
return PyUnicode_FromWideChar(config->filesystem_errors, -1); return PyUnicode_FromWideChar(config->filesystem_errors, -1);
} }
@ -2475,8 +2475,8 @@ make_flags(_PyRuntimeState *runtime, PyInterpreterState *interp)
{ {
int pos = 0; int pos = 0;
PyObject *seq; PyObject *seq;
const _PyPreConfig *preconfig = &runtime->preconfig; const PyPreConfig *preconfig = &runtime->preconfig;
const _PyCoreConfig *config = &interp->core_config; const PyConfig *config = &interp->config;
seq = PyStructSequence_New(&FlagsType); seq = PyStructSequence_New(&FlagsType);
if (seq == NULL) if (seq == NULL)
@ -2690,7 +2690,7 @@ static struct PyModuleDef sysmodule = {
} \ } \
} while (0) } while (0)
static _PyInitError static PyStatus
_PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp, _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject *sysdict) PyObject *sysdict)
{ {
@ -2827,13 +2827,13 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
goto err_occurred; goto err_occurred;
} }
return _Py_INIT_OK(); return _PyStatus_OK();
type_init_failed: type_init_failed:
return _Py_INIT_ERR("failed to initialize a type"); return _PyStatus_ERR("failed to initialize a type");
err_occurred: err_occurred:
return _Py_INIT_ERR("can't initialize sys module"); return _PyStatus_ERR("can't initialize sys module");
} }
#undef SET_SYS_FROM_STRING #undef SET_SYS_FROM_STRING
@ -2885,7 +2885,7 @@ sys_add_xoption(PyObject *opts, const wchar_t *s)
static PyObject* static PyObject*
sys_create_xoptions_dict(const _PyCoreConfig *config) sys_create_xoptions_dict(const PyConfig *config)
{ {
Py_ssize_t nxoption = config->xoptions.length; Py_ssize_t nxoption = config->xoptions.length;
wchar_t * const * xoptions = config->xoptions.items; wchar_t * const * xoptions = config->xoptions.items;
@ -2910,12 +2910,12 @@ int
_PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp) _PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
{ {
PyObject *sysdict = interp->sysdict; PyObject *sysdict = interp->sysdict;
const _PyCoreConfig *config = &interp->core_config; const PyConfig *config = &interp->config;
int res; int res;
#define COPY_LIST(KEY, VALUE) \ #define COPY_LIST(KEY, VALUE) \
do { \ do { \
PyObject *list = _PyWstrList_AsList(&(VALUE)); \ PyObject *list = _PyWideStringList_AsList(&(VALUE)); \
if (list == NULL) { \ if (list == NULL) { \
return -1; \ return -1; \
} \ } \
@ -3003,7 +3003,7 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyInterpreterState *interp)
infrastructure for the io module in place. infrastructure for the io module in place.
Use UTF-8/surrogateescape and ignore EAGAIN errors. */ Use UTF-8/surrogateescape and ignore EAGAIN errors. */
_PyInitError PyStatus
_PySys_SetPreliminaryStderr(PyObject *sysdict) _PySys_SetPreliminaryStderr(PyObject *sysdict)
{ {
PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr)); PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr));
@ -3017,56 +3017,56 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict)
goto error; goto error;
} }
Py_DECREF(pstderr); Py_DECREF(pstderr);
return _Py_INIT_OK(); return _PyStatus_OK();
error: error:
Py_XDECREF(pstderr); 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 /* Create sys module without all attributes: _PySys_InitMain() should be called
later to add remaining attributes. */ later to add remaining attributes. */
_PyInitError PyStatus
_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp, _PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
PyObject **sysmod_p) PyObject **sysmod_p)
{ {
PyObject *modules = PyDict_New(); PyObject *modules = PyDict_New();
if (modules == NULL) { if (modules == NULL) {
return _Py_INIT_ERR("can't make modules dictionary"); return _PyStatus_ERR("can't make modules dictionary");
} }
interp->modules = modules; interp->modules = modules;
PyObject *sysmod = _PyModule_CreateInitialized(&sysmodule, PYTHON_API_VERSION); PyObject *sysmod = _PyModule_CreateInitialized(&sysmodule, PYTHON_API_VERSION);
if (sysmod == NULL) { 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); PyObject *sysdict = PyModule_GetDict(sysmod);
if (sysdict == NULL) { if (sysdict == NULL) {
return _Py_INIT_ERR("can't initialize sys dict"); return _PyStatus_ERR("can't initialize sys dict");
} }
Py_INCREF(sysdict); Py_INCREF(sysdict);
interp->sysdict = sysdict; interp->sysdict = sysdict;
if (PyDict_SetItemString(sysdict, "modules", interp->modules) < 0) { 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); PyStatus status = _PySys_SetPreliminaryStderr(sysdict);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
err = _PySys_InitCore(runtime, interp, sysdict); status = _PySys_InitCore(runtime, interp, sysdict);
if (_Py_INIT_FAILED(err)) { if (_PyStatus_EXCEPTION(status)) {
return err; return status;
} }
_PyImport_FixupBuiltin(sysmod, "sys", interp->modules); _PyImport_FixupBuiltin(sysmod, "sys", interp->modules);
*sysmod_p = sysmod; *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 (updatepath) {
/* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path.
If argv[0] is a symlink, use the real 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; PyObject *path0 = NULL;
if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) { if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) {
if (path0 == NULL) { if (path0 == NULL) {