summaryrefslogtreecommitdiff
path: root/Python/preconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/preconfig.c')
-rw-r--r--Python/preconfig.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c
index ac87a7a3c7..d336352d93 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -143,6 +143,23 @@ _PyPreCmdline_GetPreConfig(_PyPreCmdline *cmdline, const _PyPreConfig *config)
COPY_ATTR(use_environment);
COPY_ATTR(isolated);
+ COPY_ATTR(dev_mode);
+
+#undef COPY_ATTR
+}
+
+
+void
+_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
+{
+#define COPY_ATTR(ATTR) \
+ if (cmdline->ATTR != -1) { \
+ config->ATTR = cmdline->ATTR; \
+ }
+
+ COPY_ATTR(use_environment);
+ COPY_ATTR(isolated);
+ COPY_ATTR(dev_mode);
#undef COPY_ATTR
}
@@ -152,12 +169,13 @@ void
_PyPreCmdline_GetCoreConfig(_PyPreCmdline *cmdline, const _PyCoreConfig *config)
{
#define COPY_ATTR(ATTR) \
- if (config->preconfig.ATTR != -1) { \
- cmdline->ATTR = config->preconfig.ATTR; \
+ if (config->ATTR != -1) { \
+ cmdline->ATTR = config->ATTR; \
}
COPY_ATTR(use_environment);
COPY_ATTR(isolated);
+ COPY_ATTR(dev_mode);
#undef COPY_ATTR
}
@@ -167,12 +185,13 @@ void
_PyPreCmdline_SetCoreConfig(const _PyPreCmdline *cmdline, _PyCoreConfig *config)
{
#define COPY_ATTR(ATTR) \
- if (config->preconfig.ATTR == -1 && cmdline->ATTR != -1) { \
- config->preconfig.ATTR = cmdline->ATTR; \
+ if (config->ATTR == -1 && cmdline->ATTR != -1) { \
+ config->ATTR = cmdline->ATTR; \
}
COPY_ATTR(use_environment);
COPY_ATTR(isolated);
+ COPY_ATTR(dev_mode);
#undef COPY_ATTR
}
@@ -206,13 +225,13 @@ _PyPreConfig_Copy(_PyPreConfig *config, const _PyPreConfig *config2)
COPY_ATTR(isolated);
COPY_ATTR(use_environment);
+ COPY_ATTR(dev_mode);
COPY_ATTR(coerce_c_locale);
COPY_ATTR(coerce_c_locale_warn);
#ifdef MS_WINDOWS
COPY_ATTR(legacy_windows_fs_encoding);
#endif
COPY_ATTR(utf8_mode);
- COPY_ATTR(dev_mode);
COPY_STR_ATTR(allocator);
#undef COPY_ATTR
@@ -270,11 +289,11 @@ _PyPreConfig_SetGlobalConfig(const _PyPreConfig *config)
const char*
-_PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name)
+_Py_GetEnv(int use_environment, const char *name)
{
- assert(config->use_environment >= 0);
+ assert(use_environment >= 0);
- if (!config->use_environment) {
+ if (!use_environment) {
return NULL;
}
@@ -288,6 +307,13 @@ _PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name)
}
+static const char*
+_PyPreConfig_GetEnv(const _PyPreConfig *config, const char *name)
+{
+ return _Py_GetEnv(config->use_environment, name);
+}
+
+
int
_Py_str_to_int(const char *str, int *result)
{
@@ -307,9 +333,9 @@ _Py_str_to_int(const char *str, int *result)
void
-_Py_get_env_flag(_PyPreConfig *config, int *flag, const char *name)
+_Py_get_env_flag(int use_environment, int *flag, const char *name)
{
- const char *var = _PyPreConfig_GetEnv(config, name);
+ const char *var = _Py_GetEnv(use_environment, name);
if (!var) {
return;
}
@@ -434,8 +460,9 @@ preconfig_read(_PyPreConfig *config, _PyPreCmdline *cmdline)
/* legacy_windows_fs_encoding, utf8_mode, coerce_c_locale */
if (config->use_environment) {
#ifdef MS_WINDOWS
- _Py_get_env_flag(config, &config->legacy_windows_fs_encoding,
- "PYTHONLEGACYWINDOWSFSENCODING");
+ _Py_get_env_flag(config->use_environment,
+ &config->legacy_windows_fs_encoding,
+ "PYTHONLEGACYWINDOWSFSENCODING");
#endif
const char *env = _PyPreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
@@ -559,24 +586,16 @@ get_ctype_locale(char **locale_p)
}
-void
-_PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
+PyObject*
+_PyPreConfig_AsDict(const _PyPreConfig *config)
{
-#define COPY_ATTR(ATTR) \
- if (cmdline->ATTR != -1) { \
- config->ATTR = cmdline->ATTR; \
- }
-
- COPY_ATTR(use_environment);
- COPY_ATTR(isolated);
-
-#undef COPY_ATTR
-}
+ PyObject *dict;
+ dict = PyDict_New();
+ if (dict == NULL) {
+ return NULL;
+ }
-int
-_PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict)
-{
#define SET_ITEM(KEY, EXPR) \
do { \
PyObject *obj = (EXPR); \
@@ -608,10 +627,11 @@ _PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict)
#endif
SET_ITEM_INT(dev_mode);
SET_ITEM_STR(allocator);
- return 0;
+ return dict;
fail:
- return -1;
+ Py_DECREF(dict);
+ return NULL;
#undef FROM_STRING
#undef SET_ITEM
@@ -696,7 +716,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args,
if (coreconfig) {
_PyPreCmdline_GetCoreConfig(&cmdline, coreconfig);
if (config->dev_mode == -1) {
- config->dev_mode = coreconfig->preconfig.dev_mode;
+ config->dev_mode = coreconfig->dev_mode;
}
}