bpo-42260: Add _PyConfig_FromDict() (GH-23167)

* Rename config_as_dict() to _PyConfig_AsDict().
* Add 'module_search_paths_set' to _PyConfig_AsDict().
* Add _PyConfig_FromDict().
* Add get_config() and set_config() to _testinternalcapi.
* Add config_check_consistency().
This commit is contained in:
Victor Stinner 2020-11-05 18:12:33 +01:00 committed by GitHub
parent 4662fa9bfe
commit f3cb814315
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 653 additions and 60 deletions

View file

@ -13,9 +13,10 @@
#include "Python.h"
#include "pycore_bitutils.h" // _Py_bswap32()
#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
#include "pycore_hashtable.h" // _Py_hashtable_new()
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_new()
#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
static PyObject *
@ -231,6 +232,38 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args))
}
static PyObject *
test_get_config(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
{
PyConfig config;
PyConfig_InitIsolatedConfig(&config);
if (_PyInterpreterState_GetConfigCopy(&config) < 0) {
PyConfig_Clear(&config);
return NULL;
}
PyObject *dict = _PyConfig_AsDict(&config);
PyConfig_Clear(&config);
return dict;
}
static PyObject *
test_set_config(PyObject *Py_UNUSED(self), PyObject *dict)
{
PyConfig config;
PyConfig_InitIsolatedConfig(&config);
if (_PyConfig_FromDict(&config, dict) < 0) {
PyConfig_Clear(&config);
return NULL;
}
if (_PyInterpreterState_SetConfig(&config) < 0) {
return NULL;
}
PyConfig_Clear(&config);
Py_RETURN_NONE;
}
static PyMethodDef TestMethods[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@ -238,6 +271,8 @@ static PyMethodDef TestMethods[] = {
{"test_popcount", test_popcount, METH_NOARGS},
{"test_bit_length", test_bit_length, METH_NOARGS},
{"test_hashtable", test_hashtable, METH_NOARGS},
{"get_config", test_get_config, METH_NOARGS},
{"set_config", test_set_config, METH_O},
{NULL, NULL} /* sentinel */
};