| 1 | #include "parts.h" |
| 2 | |
| 3 | |
| 4 | static PyObject * |
| 5 | _testcapi_config_get(PyObject *module, PyObject *name_obj) |
| 6 | { |
| 7 | const char *name; |
| 8 | if (PyArg_Parse(name_obj, "s", &name) < 0) { |
| 9 | return NULL; |
| 10 | } |
| 11 | |
| 12 | return PyConfig_Get(name); |
| 13 | } |
| 14 | |
| 15 | |
| 16 | static PyObject * |
| 17 | _testcapi_config_getint(PyObject *module, PyObject *name_obj) |
| 18 | { |
| 19 | const char *name; |
| 20 | if (PyArg_Parse(name_obj, "s", &name) < 0) { |
| 21 | return NULL; |
| 22 | } |
| 23 | |
| 24 | int value; |
| 25 | if (PyConfig_GetInt(name, &value) < 0) { |
| 26 | return NULL; |
| 27 | } |
| 28 | return PyLong_FromLong(value); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | static PyObject * |
| 33 | _testcapi_config_names(PyObject *module, PyObject* Py_UNUSED(args)) |
| 34 | { |
| 35 | return PyConfig_Names(); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static PyObject * |
| 40 | _testcapi_config_set(PyObject *module, PyObject *args) |
| 41 | { |
| 42 | const char *name; |
| 43 | PyObject *value; |
| 44 | if (PyArg_ParseTuple(args, "sO", &name, &value) < 0) { |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | int res = PyConfig_Set(name, value); |
| 49 | if (res < 0) { |
| 50 | return NULL; |
| 51 | } |
| 52 | Py_RETURN_NONE; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | static PyMethodDef test_methods[] = { |
| 57 | {"config_get", _testcapi_config_get, METH_O}, |
| 58 | {"config_getint", _testcapi_config_getint, METH_O}, |
| 59 | {"config_names", _testcapi_config_names, METH_NOARGS}, |
| 60 | {"config_set", _testcapi_config_set, METH_VARARGS}, |
| 61 | {NULL} |
| 62 | }; |
| 63 | |
| 64 | int |
| 65 | _PyTestCapi_Init_Config(PyObject *mod) |
| 66 | { |
| 67 | return PyModule_AddFunctions(mod, test_methods); |
| 68 | } |