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.
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
 dump_config_impl(void)
 {
-    PyObject *config = NULL;
-    PyObject *dict = NULL;
-
-    config = PyDict_New();
+    PyObject *config = _Py_GetConfigsAsDict();
     if (config == NULL) {
-        goto error;
+        return -1;
     }
 
-    /* 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;
-    }
-    Py_CLEAR(dict);
-
-    /* main config */
-    const _PyMainInterpreterConfig *main_config = _PyInterpreterState_GetMainConfig(interp);
-    dict = _PyMainInterpreterConfig_AsDict(main_config);
-    if (dict == NULL) {
-        goto error;
-    }
-    if (PyDict_SetItemString(config, "main_config", dict) < 0) {
-        goto error;
-    }
-    Py_CLEAR(dict);
-
+    PyObject *res;
     PyObject *json = PyImport_ImportModule("json");
-    PyObject *res = PyObject_CallMethod(json, "dumps", "O", config);
-    Py_DECREF(json);
+    if (json) {
+        res = PyObject_CallMethod(json, "dumps", "O", config);
+        Py_DECREF(json);
+    }
+    else {
+        res = NULL;
+    }
     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;
 }