aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 713829da574..e37623f38ba 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 *