summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/coreconfig.c15
-rw-r--r--Python/preconfig.c34
-rw-r--r--Python/pylifecycle.c13
3 files changed, 17 insertions, 45 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index 3c17e35..fd45726 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1746,7 +1746,7 @@ config_usage(int error, const wchar_t* program)
/* Parse the command line arguments */
static _PyInitError
config_parse_cmdline(_PyCoreConfig *config, _PyWstrList *warnoptions,
- int *opt_index)
+ Py_ssize_t *opt_index)
{
_PyInitError err;
const _PyWstrList *argv = &config->argv;
@@ -2044,7 +2044,7 @@ config_init_warnoptions(_PyCoreConfig *config,
static _PyInitError
-config_update_argv(_PyCoreConfig *config, int opt_index)
+config_update_argv(_PyCoreConfig *config, Py_ssize_t opt_index)
{
const _PyWstrList *cmdline_argv = &config->argv;
_PyWstrList config_argv = _PyWstrList_INIT;
@@ -2105,10 +2105,7 @@ core_read_precmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
_PyPreConfig preconfig;
_PyPreConfig_Init(&preconfig);
- if (_PyPreConfig_Copy(&preconfig, &_PyRuntime.preconfig) < 0) {
- err = _Py_INIT_NO_MEMORY();
- return err;
- }
+ _PyPreConfig_Copy(&preconfig, &_PyRuntime.preconfig);
_PyPreConfig_GetCoreConfig(&preconfig, config);
@@ -2145,7 +2142,7 @@ config_read_cmdline(_PyCoreConfig *config)
}
if (config->parse_argv) {
- int opt_index;
+ Py_ssize_t opt_index;
err = config_parse_cmdline(config, &cmdline_warnoptions, &opt_index);
if (_Py_INIT_FAILED(err)) {
goto done;
@@ -2207,7 +2204,7 @@ _PyCoreConfig_SetPyArgv(_PyCoreConfig *config, const _PyArgv *args)
/* Set config.argv: decode argv using Py_DecodeLocale(). Pre-initialize Python
if needed to ensure that encodings are properly configured. */
_PyInitError
-_PyCoreConfig_SetArgv(_PyCoreConfig *config, int argc, char **argv)
+_PyCoreConfig_SetArgv(_PyCoreConfig *config, Py_ssize_t argc, char **argv)
{
_PyArgv args = {
.argc = argc,
@@ -2219,7 +2216,7 @@ _PyCoreConfig_SetArgv(_PyCoreConfig *config, int argc, char **argv)
_PyInitError
-_PyCoreConfig_SetWideArgv(_PyCoreConfig *config, int argc, wchar_t **argv)
+_PyCoreConfig_SetWideArgv(_PyCoreConfig *config, Py_ssize_t argc, wchar_t **argv)
{
_PyArgv args = {
.argc = argc,
diff --git a/Python/preconfig.c b/Python/preconfig.c
index 985af39..b7bcfeb 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -297,19 +297,10 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
}
-int
+void
_PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
{
#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
-#define COPY_STR_ATTR(ATTR) \
- do { \
- if (config2->ATTR != NULL) { \
- config->ATTR = _PyMem_RawStrdup(config2->ATTR); \
- if (config->ATTR == NULL) { \
- return -1; \
- } \
- } \
- } while (0)
COPY_ATTR(isolated);
COPY_ATTR(use_environment);
@@ -317,15 +308,13 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
COPY_ATTR(dev_mode);
COPY_ATTR(coerce_c_locale);
COPY_ATTR(coerce_c_locale_warn);
+ COPY_ATTR(utf8_mode);
+ COPY_ATTR(allocator);
#ifdef MS_WINDOWS
COPY_ATTR(legacy_windows_fs_encoding);
#endif
- COPY_ATTR(utf8_mode);
- COPY_ATTR(allocator);
#undef COPY_ATTR
-#undef COPY_STR_ATTR
- return 0;
}
@@ -750,9 +739,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
/* Save the config to be able to restore it if encodings change */
_PyPreConfig save_config;
_PyPreConfig_Init(&save_config);
- if (_PyPreConfig_Copy(&save_config, config) < 0) {
- return _Py_INIT_NO_MEMORY();
- }
+ _PyPreConfig_Copy(&save_config, config);
/* Set LC_CTYPE to the user preferred locale */
if (config->configure_locale) {
@@ -835,10 +822,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
just keep UTF-8 Mode value. */
int new_utf8_mode = config->utf8_mode;
int new_coerce_c_locale = config->coerce_c_locale;
- if (_PyPreConfig_Copy(config, &save_config) < 0) {
- err = _Py_INIT_NO_MEMORY();
- goto done;
- }
+ _PyPreConfig_Copy(config, &save_config);
config->utf8_mode = new_utf8_mode;
config->coerce_c_locale = new_coerce_c_locale;
@@ -900,13 +884,7 @@ _PyPreConfig_Write(const _PyPreConfig *config)
}
/* Write the new pre-configuration into _PyRuntime */
- PyMemAllocatorEx old_alloc;
- _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- int res = _PyPreConfig_Copy(&_PyRuntime.preconfig, config);
- PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- if (res < 0) {
- return _Py_INIT_NO_MEMORY();
- }
+ _PyPreConfig_Copy(&_PyRuntime.preconfig, config);
return _Py_INIT_OK();
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 231706d..d29b293 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -705,10 +705,7 @@ _Py_PreInitializeFromPyArgv(const _PyPreConfig *src_config, const _PyArgv *args)
_PyPreConfig_Init(&config);
if (src_config) {
- if (_PyPreConfig_Copy(&config, src_config) < 0) {
- err = _Py_INIT_NO_MEMORY();
- return err;
- }
+ _PyPreConfig_Copy(&config, src_config);
}
err = _PyPreConfig_Read(&config, args);
@@ -727,7 +724,7 @@ _Py_PreInitializeFromPyArgv(const _PyPreConfig *src_config, const _PyArgv *args)
_PyInitError
-_Py_PreInitializeFromArgs(const _PyPreConfig *src_config, int argc, char **argv)
+_Py_PreInitializeFromArgs(const _PyPreConfig *src_config, Py_ssize_t argc, char **argv)
{
_PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
return _Py_PreInitializeFromPyArgv(src_config, &args);
@@ -735,7 +732,7 @@ _Py_PreInitializeFromArgs(const _PyPreConfig *src_config, int argc, char **argv)
_PyInitError
-_Py_PreInitializeFromWideArgs(const _PyPreConfig *src_config, int argc, wchar_t **argv)
+_Py_PreInitializeFromWideArgs(const _PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
{
_PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
return _Py_PreInitializeFromPyArgv(src_config, &args);
@@ -1024,7 +1021,7 @@ init_python(const _PyCoreConfig *config, const _PyArgv *args)
_PyInitError
-_Py_InitializeFromArgs(const _PyCoreConfig *config, int argc, char **argv)
+_Py_InitializeFromArgs(const _PyCoreConfig *config, Py_ssize_t argc, char **argv)
{
_PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
return init_python(config, &args);
@@ -1032,7 +1029,7 @@ _Py_InitializeFromArgs(const _PyCoreConfig *config, int argc, char **argv)
_PyInitError
-_Py_InitializeFromWideArgs(const _PyCoreConfig *config, int argc, wchar_t **argv)
+_Py_InitializeFromWideArgs(const _PyCoreConfig *config, Py_ssize_t argc, wchar_t **argv)
{
_PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
return init_python(config, &args);