diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-11 07:08:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 07:08:51 (GMT) |
commit | 5c6e85480ad8365c1b05fdbd678c7867103f7d76 (patch) | |
tree | fd60db7e4faa317bff9af2ef0501566a18905b73 /Modules/_testcapimodule.c | |
parent | 3dd593e2f2527e199ff7401308131e6888f0cf6c (diff) | |
download | cpython-5c6e85480ad8365c1b05fdbd678c7867103f7d76.zip cpython-5c6e85480ad8365c1b05fdbd678c7867103f7d76.tar.gz cpython-5c6e85480ad8365c1b05fdbd678c7867103f7d76.tar.bz2 |
gh-84489: C API: Add tests for Py_BuildValue() (GH-110596)
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ce3d0b1..2b9b232 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -386,6 +386,41 @@ raise_error(void *unused) return NULL; } +static PyObject * +py_buildvalue(PyObject *self, PyObject *args) +{ + const char *fmt; + PyObject *objs[10] = {NULL}; + if (!PyArg_ParseTuple(args, "s|OOOOOOOOOO", &fmt, + &objs[0], &objs[1], &objs[2], &objs[3], &objs[4], + &objs[5], &objs[6], &objs[7], &objs[8], &objs[9])) + { + return NULL; + } + for(int i = 0; i < 10; i++) { + NULLABLE(objs[i]); + } + return Py_BuildValue(fmt, + objs[0], objs[1], objs[2], objs[3], objs[4], + objs[5], objs[6], objs[7], objs[8], objs[9]); +} + +static PyObject * +py_buildvalue_ints(PyObject *self, PyObject *args) +{ + const char *fmt; + unsigned int values[10] = {0}; + if (!PyArg_ParseTuple(args, "s|IIIIIIIIII", &fmt, + &values[0], &values[1], &values[2], &values[3], &values[4], + &values[5], &values[6], &values[7], &values[8], &values[9])) + { + return NULL; + } + return Py_BuildValue(fmt, + values[0], values[1], values[2], values[3], values[4], + values[5], values[6], values[7], values[8], values[9]); +} + static int test_buildvalue_N_error(const char *fmt) { @@ -3252,6 +3287,8 @@ static PyMethodDef TestMethods[] = { #endif {"getbuffer_with_null_view", getbuffer_with_null_view, METH_O}, {"PyBuffer_SizeFromFormat", test_PyBuffer_SizeFromFormat, METH_VARARGS}, + {"py_buildvalue", py_buildvalue, METH_VARARGS}, + {"py_buildvalue_ints", py_buildvalue_ints, METH_VARARGS}, {"test_buildvalue_N", test_buildvalue_N, METH_NOARGS}, {"test_get_statictype_slots", test_get_statictype_slots, METH_NOARGS}, {"test_get_type_name", test_get_type_name, METH_NOARGS}, |