diff options
author | Raymond Hettinger <python@rcn.com> | 2003-10-12 18:24:34 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-10-12 18:24:34 (GMT) |
commit | cb2da43db8943e9e7b1d900bce1d6416339d6f64 (patch) | |
tree | 91873c9ad0b19e9ab7e40f7d0a79db1bbc823df5 /Objects/tupleobject.c | |
parent | d662548c728e5e1da15d5594a8b6e751213002f8 (diff) | |
download | cpython-cb2da43db8943e9e7b1d900bce1d6416339d6f64.zip cpython-cb2da43db8943e9e7b1d900bce1d6416339d6f64.tar.gz cpython-cb2da43db8943e9e7b1d900bce1d6416339d6f64.tar.bz2 |
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().
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r-- | Objects/tupleobject.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 282da3e..ef5cb85 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -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 |