diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/main.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/Modules/main.c b/Modules/main.c index 3e51ef8..8e66ddd 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -1442,11 +1442,11 @@ _PyMainInterpreterConfig_Copy(_PyMainInterpreterConfig *config, _PyMainInterpreterConfig_Clear(config); #define COPY_ATTR(ATTR) config->ATTR = config2->ATTR -#define COPY_OBJ_ATTR(OBJ_ATTR) \ +#define COPY_OBJ_ATTR(ATTR) \ do { \ - if (config2->OBJ_ATTR != NULL) { \ - config->OBJ_ATTR = config_copy_attr(config2->OBJ_ATTR); \ - if (config->OBJ_ATTR == NULL) { \ + if (config2->ATTR != NULL) { \ + config->ATTR = config_copy_attr(config2->ATTR); \ + if (config->ATTR == NULL) { \ return -1; \ } \ } \ @@ -1480,38 +1480,42 @@ _PyMainInterpreterConfig_AsDict(const _PyMainInterpreterConfig *config) return NULL; } -#define SET_ITEM(KEY, ATTR) \ - do { \ - obj = config->ATTR; \ - if (obj == NULL) { \ - obj = Py_None; \ - } \ - res = PyDict_SetItemString(dict, (KEY), obj); \ - if (res < 0) { \ - goto fail; \ - } \ - } while (0) +#define SET_ITEM_INT(ATTR) \ + do { \ + obj = PyLong_FromLong(config->ATTR); \ + if (obj == NULL) { \ + goto fail; \ + } \ + res = PyDict_SetItemString(dict, #ATTR, obj); \ + Py_DECREF(obj); \ + if (res < 0) { \ + goto fail; \ + } \ + } while (0) - obj = PyLong_FromLong(config->install_signal_handlers); - if (obj == NULL) { - goto fail; - } - res = PyDict_SetItemString(dict, "install_signal_handlers", obj); - Py_DECREF(obj); - if (res < 0) { - goto fail; - } +#define SET_ITEM_OBJ(ATTR) \ + do { \ + obj = config->ATTR; \ + if (obj == NULL) { \ + obj = Py_None; \ + } \ + res = PyDict_SetItemString(dict, #ATTR, obj); \ + if (res < 0) { \ + goto fail; \ + } \ + } while (0) - SET_ITEM("argv", argv); - SET_ITEM("executable", executable); - SET_ITEM("prefix", prefix); - SET_ITEM("base_prefix", base_prefix); - SET_ITEM("exec_prefix", exec_prefix); - SET_ITEM("base_exec_prefix", base_exec_prefix); - SET_ITEM("warnoptions", warnoptions); - SET_ITEM("xoptions", xoptions); - SET_ITEM("module_search_path", module_search_path); - SET_ITEM("pycache_prefix", pycache_prefix); + SET_ITEM_INT(install_signal_handlers); + SET_ITEM_OBJ(argv); + SET_ITEM_OBJ(executable); + SET_ITEM_OBJ(prefix); + SET_ITEM_OBJ(base_prefix); + SET_ITEM_OBJ(exec_prefix); + SET_ITEM_OBJ(base_exec_prefix); + SET_ITEM_OBJ(warnoptions); + SET_ITEM_OBJ(xoptions); + SET_ITEM_OBJ(module_search_path); + SET_ITEM_OBJ(pycache_prefix); return dict; @@ -1519,7 +1523,7 @@ fail: Py_DECREF(dict); return NULL; -#undef SET_ITEM +#undef SET_ITEM_OBJ } |