bpo-40521: Cleanup code of free lists (GH-21082) · python/cpython@522691c
@@ -249,6 +249,15 @@ static uint64_t pydict_global_version = 0;
249249250250#include "clinic/dictobject.c.h"
251251252+253+static struct _Py_dict_state *
254+get_dict_state(void)
255+{
256+PyInterpreterState *interp = _PyInterpreterState_GET();
257+return &interp->dict_state;
258+}
259+260+252261void
253262_PyDict_ClearFreeList(PyThreadState *tstate)
254263{
@@ -269,8 +278,7 @@ _PyDict_Fini(PyThreadState *tstate)
269278{
270279_PyDict_ClearFreeList(tstate);
271280#ifdef Py_DEBUG
272-PyInterpreterState *interp = _PyInterpreterState_GET();
273-struct _Py_dict_state *state = &interp->dict_state;
281+struct _Py_dict_state *state = get_dict_state();
274282state->numfree = -1;
275283state->keys_numfree = -1;
276284#endif
@@ -281,8 +289,7 @@ _PyDict_Fini(PyThreadState *tstate)
281289void
282290_PyDict_DebugMallocStats(FILE *out)
283291{
284-PyInterpreterState *interp = _PyInterpreterState_GET();
285-struct _Py_dict_state *state = &interp->dict_state;
292+struct _Py_dict_state *state = get_dict_state();
286293_PyDebugAllocatorStats(out, "free PyDictObject",
287294state->numfree, sizeof(PyDictObject));
288295}
@@ -557,8 +564,7 @@ new_keys_object(Py_ssize_t size)
557564es = sizeof(Py_ssize_t);
558565 }
559566560-PyInterpreterState *interp = _PyInterpreterState_GET();
561-struct _Py_dict_state *state = &interp->dict_state;
567+struct _Py_dict_state *state = get_dict_state();
562568#ifdef Py_DEBUG
563569// new_keys_object() must not be called after _PyDict_Fini()
564570assert(state->keys_numfree != -1);
@@ -598,8 +604,7 @@ free_keys_object(PyDictKeysObject *keys)
598604Py_XDECREF(entries[i].me_key);
599605Py_XDECREF(entries[i].me_value);
600606 }
601-PyInterpreterState *interp = _PyInterpreterState_GET();
602-struct _Py_dict_state *state = &interp->dict_state;
607+struct _Py_dict_state *state = get_dict_state();
603608#ifdef Py_DEBUG
604609// free_keys_object() must not be called after _PyDict_Fini()
605610assert(state->keys_numfree != -1);
@@ -620,8 +625,7 @@ new_dict(PyDictKeysObject *keys, PyObject **values)
620625{
621626PyDictObject *mp;
622627assert(keys != NULL);
623-PyInterpreterState *interp = _PyInterpreterState_GET();
624-struct _Py_dict_state *state = &interp->dict_state;
628+struct _Py_dict_state *state = get_dict_state();
625629#ifdef Py_DEBUG
626630// new_dict() must not be called after _PyDict_Fini()
627631assert(state->numfree != -1);
@@ -1281,8 +1285,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize)
12811285#ifdef Py_REF_DEBUG
12821286_Py_RefTotal--;
12831287#endif
1284-PyInterpreterState *interp = _PyInterpreterState_GET();
1285-struct _Py_dict_state *state = &interp->dict_state;
1288+struct _Py_dict_state *state = get_dict_state();
12861289#ifdef Py_DEBUG
12871290// dictresize() must not be called after _PyDict_Fini()
12881291assert(state->keys_numfree != -1);
@@ -2032,8 +2035,7 @@ dict_dealloc(PyDictObject *mp)
20322035assert(keys->dk_refcnt == 1);
20332036dictkeys_decref(keys);
20342037 }
2035-PyInterpreterState *interp = _PyInterpreterState_GET();
2036-struct _Py_dict_state *state = &interp->dict_state;
2038+struct _Py_dict_state *state = get_dict_state();
20372039#ifdef Py_DEBUG
20382040// new_dict() must not be called after _PyDict_Fini()
20392041assert(state->numfree != -1);