mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-36635: Add _testinternalcapi module (GH-12841)
Add a new _testinternalcapi module to test the internal C API. Move _Py_GetConfigsAsDict() function to the internal C API: _testembed now uses _testinternalcapi to access the function.
This commit is contained in:
parent
11efd79076
commit
23bace26ec
13 changed files with 172 additions and 49 deletions
|
|
@ -298,42 +298,13 @@ static int test_initialize_pymain(void)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
dump_config_impl(void)
|
||||
{
|
||||
PyObject *config = _Py_GetConfigsAsDict();
|
||||
if (config == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject *res;
|
||||
PyObject *json = PyImport_ImportModule("json");
|
||||
if (json) {
|
||||
res = PyObject_CallMethod(json, "dumps", "O", config);
|
||||
Py_DECREF(json);
|
||||
}
|
||||
else {
|
||||
res = NULL;
|
||||
}
|
||||
Py_CLEAR(config);
|
||||
if (res == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PySys_FormatStdout("%S\n", res);
|
||||
Py_DECREF(res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dump_config(void)
|
||||
{
|
||||
if (dump_config_impl() < 0) {
|
||||
fprintf(stderr, "failed to dump the configuration:\n");
|
||||
PyErr_Print();
|
||||
}
|
||||
(void) PyRun_SimpleStringFlags(
|
||||
"import _testinternalcapi, json; "
|
||||
"print(json.dumps(_testinternalcapi.get_configs()))",
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue