aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-23 16:40:40 +0200
committerGitHub <noreply@github.com>2020-06-23 16:40:40 +0200
commit522691c46e2ae51faaad5bbbce7d959dd61770df (patch)
treeb6f833b6712837379d135d56125b9f3fe0dc4fa0 /Objects/sliceobject.c
parentbpo-41065: Use zip-strict in zoneinfo (GH-21031) (diff)
downloadcpython-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.c24
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);