diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-23 16:40:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 16:40:40 +0200 |
commit | 522691c46e2ae51faaad5bbbce7d959dd61770df (patch) | |
tree | b6f833b6712837379d135d56125b9f3fe0dc4fa0 /Objects/sliceobject.c | |
parent | bpo-41065: Use zip-strict in zoneinfo (GH-21031) (diff) | |
download | cpython-522691c46e2ae51faaad5bbbce7d959dd61770df.tar.gz cpython-522691c46e2ae51faaad5bbbce7d959dd61770df.tar.bz2 cpython-522691c46e2ae51faaad5bbbce7d959dd61770df.zip |
bpo-40521: Cleanup code of free lists (GH-21082)
Add get_xxx_state() function to factorize duplicated code.
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r-- | Objects/sliceobject.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index f97a570a787..e8af623142b 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -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); |