@@ -15,7 +15,7 @@ this type and there is exactly one in existence.
1515
1616#include "Python.h"
1717#include "pycore_abstract.h" // _PyIndex_Check()
18- #include "pycore_object.h"
18+ #include "pycore_object.h" // _PyObject_GC_TRACK()
1919#include "structmember.h" // PyMemberDef
2020
2121static PyObject *
@@ -95,16 +95,13 @@ PyObject _Py_EllipsisObject = {
9595
9696/* Slice object implementation */
9797
98- /* Using a cache is very effective since typically only a single slice is
99- * created and then deleted again
100- */
101- static PySliceObject * slice_cache = NULL ;
10298
103- void _PySlice_Fini (void )
99+ void _PySlice_Fini (PyThreadState * tstate )
104100{
105- PySliceObject * obj = slice_cache ;
101+ PyInterpreterState * interp = tstate -> interp ;
102+ PySliceObject * obj = interp -> slice_cache ;
106103 if (obj != NULL ) {
107- slice_cache = NULL ;
104+ interp -> slice_cache = NULL ;
108105 PyObject_GC_Del (obj );
109106 }
110107}
@@ -116,10 +113,11 @@ void _PySlice_Fini(void)
116113PyObject *
117114PySlice_New (PyObject * start , PyObject * stop , PyObject * step )
118115{
116+ PyInterpreterState * interp = _PyInterpreterState_GET ();
119117 PySliceObject * obj ;
120- if (slice_cache != NULL ) {
121- obj = slice_cache ;
122- slice_cache = NULL ;
118+ if (interp -> slice_cache != NULL ) {
119+ obj = interp -> slice_cache ;
120+ interp -> slice_cache = NULL ;
123121 _Py_NewReference ((PyObject * )obj );
124122 } else {
125123 obj = PyObject_GC_New (PySliceObject , & PySlice_Type );
@@ -324,14 +322,17 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
324322static void
325323slice_dealloc (PySliceObject * r )
326324{
325+ PyInterpreterState * interp = _PyInterpreterState_GET ();
327326 _PyObject_GC_UNTRACK (r );
328327 Py_DECREF (r -> step );
329328 Py_DECREF (r -> start );
330329 Py_DECREF (r -> stop );
331- if (slice_cache == NULL )
332- slice_cache = r ;
333- else
330+ if (interp -> slice_cache == NULL ) {
331+ interp -> slice_cache = r ;
332+ }
333+ else {
334334 PyObject_GC_Del (r );
335+ }
335336}
336337
337338static PyObject *
0 commit comments