mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Extended tuple's C API to include a new function, PyTuple_Pack() that is
useful for rapidly building argument tuples without having to invoke the more sophisticated machinery of Py_BuildValue().
This commit is contained in:
parent
d662548c72
commit
cb2da43db8
4 changed files with 37 additions and 1 deletions
|
|
@ -130,6 +130,28 @@ PyTuple_SetItem(register PyObject *op, register int i, PyObject *newitem)
|
|||
return 0;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PyTuple_Pack(int n, ...)
|
||||
{
|
||||
int i;
|
||||
PyObject *o;
|
||||
PyObject *result;
|
||||
va_list vargs;
|
||||
|
||||
va_start(vargs, n);
|
||||
result = PyTuple_New(n);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
for (i = 0; i < n; i++) {
|
||||
o = va_arg(vargs, PyObject *);
|
||||
Py_INCREF(o);
|
||||
PyTuple_SET_ITEM(result, i, o);
|
||||
}
|
||||
va_end(vargs);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Methods */
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue