diff options
| author | Victor Stinner <vstinner@redhat.com> | 2019-03-25 22:19:57 (GMT) | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-25 22:19:57 (GMT) | 
| commit | 1075d1684ab84dc7c28d93cfb46e95e70d3b6d3b (patch) | |
| tree | 7a0543a13a28f88318d16f8900111ea10198a4a3 /Programs/_testembed.c | |
| parent | 91759d98015e1d6d5e1367cff60592ab548e7806 (diff) | |
| download | cpython-1075d1684ab84dc7c28d93cfb46e95e70d3b6d3b.zip cpython-1075d1684ab84dc7c28d93cfb46e95e70d3b6d3b.tar.gz cpython-1075d1684ab84dc7c28d93cfb46e95e70d3b6d3b.tar.bz2  | |
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.
Diffstat (limited to 'Programs/_testembed.c')
| -rw-r--r-- | Programs/_testembed.c | 55 | 
1 files changed, 10 insertions, 45 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 7c143f1..ab5802d 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -301,64 +301,29 @@ static int test_initialize_pymain(void)  static int  dump_config_impl(void)  { -    PyObject *config = NULL; -    PyObject *dict = NULL; - -    config = PyDict_New(); +    PyObject *config = _Py_GetConfigsAsDict();      if (config == NULL) { -        goto error; -    } - -    /* global config */ -    dict = _Py_GetGlobalVariablesAsDict(); -    if (dict == NULL) { -        goto error; -    } -    if (PyDict_SetItemString(config, "global_config", dict) < 0) { -        goto error; -    } -    Py_CLEAR(dict); - -    /* core config */ -    PyInterpreterState *interp = _PyInterpreterState_Get(); -    const _PyCoreConfig *core_config = _PyInterpreterState_GetCoreConfig(interp); -    dict = _PyCoreConfig_AsDict(core_config); -    if (dict == NULL) { -        goto error; -    } -    if (PyDict_SetItemString(config, "core_config", dict) < 0) { -        goto error; +        return -1;      } -    Py_CLEAR(dict); -    /* main config */ -    const _PyMainInterpreterConfig *main_config = _PyInterpreterState_GetMainConfig(interp); -    dict = _PyMainInterpreterConfig_AsDict(main_config); -    if (dict == NULL) { -        goto error; +    PyObject *res; +    PyObject *json = PyImport_ImportModule("json"); +    if (json) { +        res = PyObject_CallMethod(json, "dumps", "O", config); +        Py_DECREF(json);      } -    if (PyDict_SetItemString(config, "main_config", dict) < 0) { -        goto error; +    else { +        res = NULL;      } -    Py_CLEAR(dict); - -    PyObject *json = PyImport_ImportModule("json"); -    PyObject *res = PyObject_CallMethod(json, "dumps", "O", config); -    Py_DECREF(json);      Py_CLEAR(config);      if (res == NULL) { -        goto error; +        return -1;      }      PySys_FormatStdout("%S\n", res);      Py_DECREF(res);      return 0; - -error: -    Py_XDECREF(config); -    Py_XDECREF(dict); -    return -1;  }  | 
