summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-27 11:24:23 (GMT)
committerGitHub <noreply@github.com>2022-06-27 11:24:23 (GMT)
commitc0453a40faaadb43d2e69767af6c9680f8689063 (patch)
treed8ab19e5244e552e5d1b371651593be9be5142e4 /Objects
parent33fc3b5e42f241ab81cc6d115711545b4f9e271e (diff)
downloadcpython-c0453a40faaadb43d2e69767af6c9680f8689063.zip
cpython-c0453a40faaadb43d2e69767af6c9680f8689063.tar.gz
cpython-c0453a40faaadb43d2e69767af6c9680f8689063.tar.bz2
GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/sliceobject.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 713829d..e37623f 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -110,18 +110,10 @@ void _PySlice_Fini(PyInterpreterState *interp)
index is present.
*/
-PyObject *
-PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
+static PySliceObject *
+_PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
{
- if (step == NULL) {
- step = Py_None;
- }
- if (start == NULL) {
- start = Py_None;
- }
- if (stop == NULL) {
- stop = Py_None;
- }
+ assert(start != NULL && stop != NULL && step != NULL);
PyInterpreterState *interp = _PyInterpreterState_GET();
PySliceObject *obj;
@@ -133,19 +125,44 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
else {
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
if (obj == NULL) {
- return NULL;
+ goto error;
}
}
- Py_INCREF(step);
- obj->step = step;
- Py_INCREF(start);
obj->start = start;
- Py_INCREF(stop);
obj->stop = stop;
+ obj->step = Py_NewRef(step);
_PyObject_GC_TRACK(obj);
- return (PyObject *) obj;
+ return obj;
+error:
+ Py_DECREF(start);
+ Py_DECREF(stop);
+ return NULL;
+}
+
+PyObject *
+PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
+{
+ if (step == NULL) {
+ step = Py_None;
+ }
+ if (start == NULL) {
+ start = Py_None;
+ }
+ if (stop == NULL) {
+ stop = Py_None;
+ }
+ Py_INCREF(start);
+ Py_INCREF(stop);
+ return (PyObject *) _PyBuildSlice_Consume2(start, stop, step);
+}
+
+PyObject *
+_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop)
+{
+ assert(start != NULL && stop != NULL);
+ return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None);
}
PyObject *