[Python-checkins] cpython: Add _PyStack_AsTupleSlice() helper
victor.stinner
python-checkins at python.org
Mon Jan 16 17:57:59 EST 2017
https://hg.python.org/cpython/rev/4cb3bb326149
changeset: 106169:4cb3bb326149
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Jan 16 23:50:53 2017 +0100
summary:
Add _PyStack_AsTupleSlice() helper
files:
Include/abstract.h | 6 ++++++
Objects/abstract.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/Include/abstract.h b/Include/abstract.h
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -160,6 +160,12 @@
PyObject **stack,
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
dictionary.
diff --git a/Objects/abstract.c b/Objects/abstract.c
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2274,7 +2274,30 @@
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;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list