mirror of https://github.com/python/cpython
Add _PyStack_AsTupleSlice() helper
This commit is contained in:
parent
7fc252adfb
commit
69de71b255
|
@ -160,6 +160,12 @@ PyAPI_FUNC(PyObject*) _PyStack_AsTuple(
|
||||||
PyObject **stack,
|
PyObject **stack,
|
||||||
Py_ssize_t nargs);
|
Py_ssize_t nargs);
|
||||||
|
|
||||||
|
PyAPI_FUNC(PyObject*) _PyStack_AsTupleSlice(
|
||||||
|
PyObject **stack,
|
||||||
|
Py_ssize_t nargs,
|
||||||
|
Py_ssize_t start,
|
||||||
|
Py_ssize_t end);
|
||||||
|
|
||||||
/* Convert keyword arguments from the (stack, kwnames) format to a Python
|
/* Convert keyword arguments from the (stack, kwnames) format to a Python
|
||||||
dictionary.
|
dictionary.
|
||||||
|
|
||||||
|
|
|
@ -2274,7 +2274,30 @@ _PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs)
|
||||||
Py_INCREF(item);
|
Py_INCREF(item);
|
||||||
PyTuple_SET_ITEM(args, i, 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;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue