GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)

This commit is contained in:
Mark Shannon 2022-06-27 12:24:23 +01:00 committed by GitHub
parent 33fc3b5e42
commit c0453a40fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 339 additions and 161 deletions

View file

@ -110,6 +110,37 @@ void _PySlice_Fini(PyInterpreterState *interp)
index is present.
*/
static PySliceObject *
_PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
{
assert(start != NULL && stop != NULL && step != NULL);
PyInterpreterState *interp = _PyInterpreterState_GET();
PySliceObject *obj;
if (interp->slice_cache != NULL) {
obj = interp->slice_cache;
interp->slice_cache = NULL;
_Py_NewReference((PyObject *)obj);
}
else {
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
if (obj == NULL) {
goto error;
}
}
obj->start = start;
obj->stop = stop;
obj->step = Py_NewRef(step);
_PyObject_GC_TRACK(obj);
return obj;
error:
Py_DECREF(start);
Py_DECREF(stop);
return NULL;
}
PyObject *
PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
{
@ -122,30 +153,16 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
if (stop == NULL) {
stop = Py_None;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PySliceObject *obj;
if (interp->slice_cache != NULL) {
obj = interp->slice_cache;
interp->slice_cache = NULL;
_Py_NewReference((PyObject *)obj);
}
else {
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
if (obj == NULL) {
return NULL;
}
}
Py_INCREF(step);
obj->step = step;
Py_INCREF(start);
obj->start = start;
Py_INCREF(stop);
obj->stop = stop;
return (PyObject *) _PyBuildSlice_Consume2(start, stop, step);
}
_PyObject_GC_TRACK(obj);
return (PyObject *) obj;
PyObject *
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop)
{
assert(start != NULL && stop != NULL);
return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None);
}
PyObject *