8000 revert slice · python/cpython@4f4107a · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f4107a

Browse files
revert slice
1 parent 2d69426 commit 4f4107a

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

Include/internal/pycore_sliceobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
/* runtime lifecycle */
1313

1414
PyAPI_FUNC(PyObject *)
15-
_PyBuildSlice_ConsumeStackRefs(_PyStackRef start, _PyStackRef stop);
15+
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop);
1616

1717
#ifdef __cplusplus
1818
}

Objects/sliceobject.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void _PySlice_ClearFreeList(struct _Py_object_freelists *freelists, int is_final
127127
*/
128128

129129
static PySliceObject *
130-
_PyBuildSlice_Steal3(PyObject *start, PyObject *stop, PyObject *step)
130+
_PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
131131
{
132132
assert(start != NULL && stop != NULL && step != NULL);
133133
PySliceObject *obj;
@@ -149,14 +149,13 @@ _PyBuildSlice_Steal3(PyObject *start, PyObject *stop, PyObject *step)
149149

150150
obj->start = start;
151151
obj->stop = stop;
152-
obj->step = step;
152+
obj->step = Py_NewRef(step);
153153

154154
_PyObject_GC_TRACK(obj);
155155
return obj;
156156
error:
157157
Py_DECREF(start);
158158
Py_DECREF(stop);
159-
Py_DECREF(step);
160159
return NULL;
161160
}
162161

@@ -172,18 +171,15 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
172171
if (stop == NULL) {
173172
stop = Py_None;
174173
}
175-
return (PyObject *)_PyBuildSlice_Steal3(Py_NewRef(start),
176-
Py_NewRef(stop), Py_NewRef(step));
174+
return (PyObject *)_PyBuildSlice_Consume2(Py_NewRef(start),
175+
Py_NewRef(stop), step);
177176
}
178177

179178
PyObject *
180-
_PyBuildSlice_ConsumeStackRefs(_PyStackRef start, _PyStackRef stop)
179+
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop)
181180
{
182-
assert(PyStackRef_AsPyObjectBorrow(start) != NULL && PyStackRef_AsPyObjectBorrow(stop) != NULL);
183-
PyObject *res = (PyObject *)_PyBuildSlice_Steal3(PyStackRef_AsPyObjectNew(start),
184-
PyStackRef_AsPyObjectNew(stop),
185-
Py_None);
186-
return res;
181+
assert(start != NULL && stop != NULL);
182+
return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None);
187183
}
188184

189185
PyObject *

Python/bytecodes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ dummy_func(
648648
macro(BINARY_SUBSCR) = _SPECIALIZE_BINARY_SUBSCR + _BINARY_SUBSCR;
649649

650650
inst(BINARY_SLICE, (container, start, stop -- res)) {
651-
PyObject *slice = _PyBuildSlice_ConsumeStackRefs(start, stop);
651+
PyObject *slice = _PyBuildSlice_ConsumeRefs(PyStackRef_AsPyObjectNew(start),
652+
PyStackRef_AsPyObjectNew(stop));
652653
PyObject *res_o;
653654
// Can't use ERROR_IF() here, because we haven't
654655
// DECREF'ed container yet, and we still own slice.
@@ -665,7 +666,8 @@ dummy_func(
665666
}
666667

667668
inst(STORE_SLICE, (v, container, start, stop -- )) {
668-
PyObject *slice = _PyBuildSlice_ConsumeStackRefs(start, stop);
669+
PyObject *slice = _PyBuildSlice_ConsumeRefs(PyStackRef_AsPyObjectNew(start),
670+
PyStackRef_AsPyObjectNew(stop));
669671
int err;
670672
if (slice == NULL) {
671673
err = 1;

Python/executor_cases.c.h

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0