bpo-36301: Add _Py_GetConfigsAsDict() function (GH-12540)

* Add _Py_GetConfigsAsDict() function to get all configurations as a
  dict.
* dump_config() of _testembed.c now dumps preconfig as a separated
  key: call _Py_GetConfigsAsDict().
* Make _PyMainInterpreterConfig_AsDict() private.
This commit is contained in:
Victor Stinner 2019-03-25 23:19:57 +01:00 committed by GitHub
parent 91759d9801
commit 1075d1684a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 179 additions and 134 deletions

View file

@ -574,9 +574,16 @@ _PyPreCmdline_SetPreConfig(const _PyPreCmdline *cmdline, _PyPreConfig *config)
}
int
_PyPreConfig_AsDict(const _PyPreConfig *config, PyObject *dict)
PyObject*
_PyPreConfig_AsDict(const _PyPreConfig *config)
{
PyObject *dict;
dict = PyDict_New();
if (dict == NULL) {
return NULL;
}
#define SET_ITEM(KEY, EXPR) \
do { \
PyObject *obj = (EXPR); \
@ -608,10 +615,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