diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-01-16 22:50:53 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-01-16 22:50:53 (GMT) |
commit | 69de71b2557509d6b3f914a36596fee833d0594b (patch) | |
tree | 355fde9daf05d08a8d55c09a1c8021501c80d032 /Objects/abstract.c | |
parent | 7fc252adfbedece75f2330bcfdadbf84dee7836f (diff) | |
download | cpython-69de71b2557509d6b3f914a36596fee833d0594b.zip cpython-69de71b2557509d6b3f914a36596fee833d0594b.tar.gz cpython-69de71b2557509d6b3f914a36596fee833d0594b.tar.bz2 |
Add _PyStack_AsTupleSlice() helper
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 5726160..bba946e 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2274,7 +2274,30 @@ _PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs) Py_INCREF(item); PyTuple_SET_ITEM(args, i, item); } + return args; +} + +PyObject* +_PyStack_AsTupleSlice(PyObject **stack, Py_ssize_t nargs, + Py_ssize_t start, Py_ssize_t end) +{ + PyObject *args; + Py_ssize_t i; + + assert(0 <= start); + assert(end <= nargs); + assert(start <= end); + args = PyTuple_New(end - start); + if (args == NULL) { + return NULL; + } + + for (i=start; i < end; i++) { + PyObject *item = stack[i]; + Py_INCREF(item); + PyTuple_SET_ITEM(args, i - start, item); + } return args; } |