mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.12] gh-84489: C API: Add tests for Py_BuildValue() (GH-110596) (GH-110680)
(cherry picked from commit 5c6e85480a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
9ffef4d797
commit
ca971d12ed
2 changed files with 117 additions and 0 deletions
|
|
@ -423,6 +423,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)
|
||||
{
|
||||
|
|
@ -3267,6 +3302,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_buildvalue_issue38913", test_buildvalue_issue38913, METH_NOARGS},
|
||||
{"test_get_statictype_slots", test_get_statictype_slots, METH_NOARGS},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue