summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-17 17:01:14 (GMT)
committerGitHub <noreply@github.com>2019-05-17 17:01:14 (GMT)
commitcab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3 (patch)
tree745b2e08f4a035ffb345e695216934b1a3b6ccda /Include
parentb16b4e45923f4e4dfd8e970ae4e6a934faf73b79 (diff)
downloadcpython-cab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3.zip
cpython-cab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3.tar.gz
cpython-cab5d0741ee6adf2ae9ff5aaafe06b75b4b5bca3.tar.bz2
bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)
Add new functions to get the Python interpreter behavior: * _PyPreConfig_InitPythonConfig() * _PyCoreConfig_InitPythonConfig() Add new functions to get an isolated configuration: * _PyPreConfig_InitIsolatedConfig() * _PyCoreConfig_InitIsolatedConfig() Replace _PyPreConfig_INIT and _PyCoreConfig_INIT with new functions _PyPreConfig_Init() and _PyCoreConfig_Init(). _PyCoreConfig: set configure_c_stdio and parse_argv to 0 by default to behave as Python 3.6 in the default configuration. _PyCoreConfig_Read() no longer sets coerce_c_locale_warn to 1 if it's equal to 0. coerce_c_locale_warn must now be set to -1 (ex: using _PyCoreConfig_InitPythonConfig()) to enable C locale coercion warning. Add unit tests for _PyCoreConfig_InitPythonConfig() and _PyCoreConfig_InitIsolatedConfig(). Changes: * Rename _PyCoreConfig_GetCoreConfig() to _PyPreConfig_GetCoreConfig() * Fix core_read_precmdline(): handle parse_argv=0 * Fix _Py_PreInitializeFromCoreConfig(): pass coreconfig.argv to _Py_PreInitializeFromPyArgv(), except if parse_argv=0
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/coreconfig.h32
-rw-r--r--Include/internal/pycore_coreconfig.h7
2 files changed, 31 insertions, 8 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h
index dca4134..7d561ce 100644
--- a/Include/cpython/coreconfig.h
+++ b/Include/cpython/coreconfig.h
@@ -86,12 +86,18 @@ typedef struct {
If it is equal to 1, LC_CTYPE locale is read to decide it it should be
coerced or not (ex: PYTHONCOERCECLOCALE=1). Internally, it is set to 2
- if the LC_CTYPE locale must be coerced. */
+ if the LC_CTYPE locale must be coerced.
+
+ Disable by default (set to 0). Set it to -1 to let Python decides if it
+ should be enabled or not. */
int coerce_c_locale;
/* Emit a warning if the LC_CTYPE locale is coerced?
- Disabled by default. Set to 1 by PYTHONCOERCECLOCALE=warn. */
+ Set to 1 by PYTHONCOERCECLOCALE=warn.
+
+ Disable by default (set to 0). Set it to -1 to let Python decides if it
+ should be enabled or not. */
int coerce_c_locale_warn;
#ifdef MS_WINDOWS
@@ -116,7 +122,10 @@ typedef struct {
Set to 0 by "-X utf8=0" and PYTHONUTF8=0.
If equals to -1, it is set to 1 if the LC_CTYPE locale is "C" or
- "POSIX", otherwise inherit Py_UTF8Mode value. */
+ "POSIX", otherwise it is set to 0.
+
+ If equals to -2, inherit Py_UTF8Mode value value (which is equal to 0
+ by default). */
int utf8_mode;
int dev_mode; /* Development mode. PYTHONDEVMODE, -X dev */
@@ -138,9 +147,14 @@ typedef struct {
._config_version = _Py_CONFIG_VERSION, \
.isolated = -1, \
.use_environment = -1, \
+ .utf8_mode = -2, \
.dev_mode = -1, \
.allocator = PYMEM_ALLOCATOR_NOT_SET}
+PyAPI_FUNC(void) _PyPreConfig_Init(_PyPreConfig *config);
+PyAPI_FUNC(void) _PyPreConfig_InitPythonConfig(_PyPreConfig *config);
+PyAPI_FUNC(void) _PyPreConfig_InitIsolateConfig(_PyPreConfig *config);
+
/* --- _PyCoreConfig ---------------------------------------------- */
@@ -213,8 +227,8 @@ typedef struct {
/* Command line arguments (sys.argv).
- By default, Python command line arguments are parsed and then stripped
- from argv. Set parse_argv to 0 to avoid that.
+ Set parse_argv to 1 to parse argv as Python command line arguments
+ and then strip Python arguments from argv.
If argv is empty, an empty string is added to ensure that sys.argv
always exists and is never empty. */
@@ -442,7 +456,7 @@ typedef struct {
.faulthandler = -1, \
.tracemalloc = -1, \
.use_module_search_paths = 0, \
- .parse_argv = 1, \
+ .parse_argv = 0, \
.site_import = -1, \
.bytes_warning = -1, \
.inspect = -1, \
@@ -453,7 +467,7 @@ typedef struct {
.verbose = -1, \
.quiet = -1, \
.user_site_directory = -1, \
- .configure_c_stdio = 1, \
+ .configure_c_stdio = 0, \
.buffered_stdio = -1, \
._install_importlib = 1, \
.check_hash_pycs_mode = NULL, \
@@ -461,6 +475,10 @@ typedef struct {
._init_main = 1}
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
+PyAPI_FUNC(void) _PyCoreConfig_Init(_PyCoreConfig *config);
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config);
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitIsolateConfig(_PyCoreConfig *config);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/internal/pycore_coreconfig.h b/Include/internal/pycore_coreconfig.h
index ccb7948..e9c6d9f 100644
--- a/Include/internal/pycore_coreconfig.h
+++ b/Include/internal/pycore_coreconfig.h
@@ -88,10 +88,13 @@ PyAPI_FUNC(_PyInitError) _PyPreCmdline_Read(_PyPreCmdline *cmdline,
/* --- _PyPreConfig ----------------------------------------------- */
+PyAPI_FUNC(void) _PyPreConfig_Init(_PyPreConfig *config);
+PyAPI_FUNC(void) _PyPreConfig_InitPythonConfig(_PyPreConfig *config);
+PyAPI_FUNC(void) _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config);
PyAPI_FUNC(int) _PyPreConfig_Copy(_PyPreConfig *config,
const _PyPreConfig *config2);
PyAPI_FUNC(PyObject*) _PyPreConfig_AsDict(const _PyPreConfig *config);
-PyAPI_FUNC(void) _PyCoreConfig_GetCoreConfig(_PyPreConfig *config,
+PyAPI_FUNC(void) _PyPreConfig_GetCoreConfig(_PyPreConfig *config,
const _PyCoreConfig *core_config);
PyAPI_FUNC(_PyInitError) _PyPreConfig_Read(_PyPreConfig *config,
const _PyArgv *args);
@@ -101,6 +104,8 @@ PyAPI_FUNC(_PyInitError) _PyPreConfig_Write(const _PyPreConfig *config);
/* --- _PyCoreConfig ---------------------------------------------- */
PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *);
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPythonConfig(_PyCoreConfig *config);
+PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitIsolatedConfig(_PyCoreConfig *config);
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Copy(
_PyCoreConfig *config,
const _PyCoreConfig *config2);