summaryrefslogtreecommitdiffstats
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-01-15 15:38:57 (GMT)
committerGitHub <noreply@github.com>2024-01-15 15:38:57 (GMT)
commit3eae76554b0687c6b9c5c019cc53bb76430488c9 (patch)
treef57ef0919140b9603434f854b40054150c18f54f /Objects/sliceobject.c
parent44e47dfba55a825ce7c340b1460cb493165353c9 (diff)
downloadcpython-3eae76554b0687c6b9c5c019cc53bb76430488c9.zip
cpython-3eae76554b0687c6b9c5c019cc53bb76430488c9.tar.gz
cpython-3eae76554b0687c6b9c5c019cc53bb76430488c9.tar.bz2
gh-111968: Use per-thread slice_cache in free-threading (gh-113972)
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index a3ed0c0..9ec8ea8 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -103,16 +103,20 @@ PyObject _Py_EllipsisObject = _PyObject_HEAD_INIT(&PyEllipsis_Type);
/* Slice object implementation */
-
-void _PySlice_Fini(PyInterpreterState *interp)
+void _PySlice_ClearCache(_PyFreeListState *state)
{
- PySliceObject *obj = interp->slice_cache;
+ PySliceObject *obj = state->slice_state.slice_cache;
if (obj != NULL) {
- interp->slice_cache = NULL;
+ state->slice_state.slice_cache = NULL;
PyObject_GC_Del(obj);
}
}
+void _PySlice_Fini(_PyFreeListState *state)
+{
+ _PySlice_ClearCache(state);
+}
+
/* start, stop, and step are python objects with None indicating no
index is present.
*/
@@ -122,11 +126,11 @@ _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
{
assert(start != NULL && stop != NULL && step != NULL);
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ _PyFreeListState *state = _PyFreeListState_GET();
PySliceObject *obj;
- if (interp->slice_cache != NULL) {
- obj = interp->slice_cache;
- interp->slice_cache = NULL;
+ if (state->slice_state.slice_cache != NULL) {
+ obj = state->slice_state.slice_cache;
+ state->slice_state.slice_cache = NULL;
_Py_NewReference((PyObject *)obj);
}
else {
@@ -354,13 +358,13 @@ 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();
+ _PyFreeListState *state = _PyFreeListState_GET();
_PyObject_GC_UNTRACK(r);
Py_DECREF(r->step);
Py_DECREF(r->start);
Py_DECREF(r->stop);
- if (interp->slice_cache == NULL) {
- interp->slice_cache = r;
+ if (state->slice_state.slice_cache == NULL) {
+ state->slice_state.slice_cache = r;
}
else {
PyObject_GC_Del(r);