summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/sliceobject.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-04-18 12:39:32 +0300
committershadchin <[email protected]>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Objects/sliceobject.c
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Objects/sliceobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/sliceobject.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/contrib/tools/python3/src/Objects/sliceobject.c b/contrib/tools/python3/src/Objects/sliceobject.c
index 391711f711a..22fb7c61c35 100644
--- a/contrib/tools/python3/src/Objects/sliceobject.c
+++ b/contrib/tools/python3/src/Objects/sliceobject.c
@@ -15,7 +15,8 @@ this type and there is exactly one in existence.
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
-#include "pycore_object.h"
+#include "pycore_long.h" // _PyLong_GetZero()
+#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "structmember.h" // PyMemberDef
static PyObject *
@@ -95,16 +96,12 @@ PyObject _Py_EllipsisObject = {
/* Slice object implementation */
-/* Using a cache is very effective since typically only a single slice is
- * created and then deleted again
- */
-static PySliceObject *slice_cache = NULL;
-void _PySlice_Fini(void)
+void _PySlice_Fini(PyInterpreterState *interp)
{
- PySliceObject *obj = slice_cache;
+ PySliceObject *obj = interp->slice_cache;
if (obj != NULL) {
- slice_cache = NULL;
+ interp->slice_cache = NULL;
PyObject_GC_Del(obj);
}
}
@@ -116,26 +113,35 @@ void _PySlice_Fini(void)
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 (slice_cache != NULL) {
- obj = slice_cache;
- slice_cache = NULL;
+ 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);
@@ -324,14 +330,17 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
static void
slice_dealloc(PySliceObject *r)
{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
_PyObject_GC_UNTRACK(r);
Py_DECREF(r->step);
Py_DECREF(r->start);
Py_DECREF(r->stop);
- if (slice_cache == NULL)
- slice_cache = r;
- else
+ if (interp->slice_cache == NULL) {
+ interp->slice_cache = r;
+ }
+ else {
PyObject_GC_Del(r);
+ }
}
static PyObject *
@@ -379,7 +388,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
/* Convert step to an integer; raise for zero step. */
if (self->step == Py_None) {
- step = _PyLong_One;
+ step = _PyLong_GetOne();
Py_INCREF(step);
step_is_negative = 0;
}
@@ -408,7 +417,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
goto error;
}
else {
- lower = _PyLong_Zero;
+ lower = _PyLong_GetZero();
Py_INCREF(lower);
upper = length;
Py_INCREF(upper);