bpo-40521: Cleanup code of free lists (GH-21082)

Add get_xxx_state() function to factorize duplicated code.
This commit is contained in:
Victor Stinner 2020-06-23 16:40:40 +02:00 committed by GitHub
parent bc43f6e212
commit 522691c46e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 69 deletions

View file

@ -113,27 +113,35 @@ void _PySlice_Fini(PyThreadState *tstate)
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;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PySliceObject *obj;
if (interp->slice_cache != NULL) {
obj = interp->slice_cache;
interp->slice_cache = NULL;
_Py_NewReference((PyObject *)obj);
} else {
}
else {
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
if (obj == NULL)
if (obj == NULL) {
return NULL;
}
}
if (step == NULL) step = Py_None;
Py_INCREF(step);
if (start == NULL) start = Py_None;
Py_INCREF(start);
if (stop == NULL) stop = Py_None;
Py_INCREF(stop);
obj->step = step;
Py_INCREF(start);
obj->start = start;
Py_INCREF(stop);
obj->stop = stop;
_PyObject_GC_TRACK(obj);