bpo-40521: Cleanup code of free lists (GH-21082)

Add get_xxx_state() function to factorize duplicated code.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index f3b1157..b1f11b3 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -249,6 +249,15 @@
 
 #include "clinic/dictobject.c.h"
 
+
+static struct _Py_dict_state *
+get_dict_state(void)
+{
+    PyInterpreterState *interp = _PyInterpreterState_GET();
+    return &interp->dict_state;
+}
+
+
 void
 _PyDict_ClearFreeList(PyThreadState *tstate)
 {
@@ -269,8 +278,7 @@
 {
     _PyDict_ClearFreeList(tstate);
 #ifdef Py_DEBUG
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
     state->numfree = -1;
     state->keys_numfree = -1;
 #endif
@@ -281,8 +289,7 @@
 void
 _PyDict_DebugMallocStats(FILE *out)
 {
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
     _PyDebugAllocatorStats(out, "free PyDictObject",
                            state->numfree, sizeof(PyDictObject));
 }
@@ -557,8 +564,7 @@
         es = sizeof(Py_ssize_t);
     }
 
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
 #ifdef Py_DEBUG
     // new_keys_object() must not be called after _PyDict_Fini()
     assert(state->keys_numfree != -1);
@@ -598,8 +604,7 @@
         Py_XDECREF(entries[i].me_key);
         Py_XDECREF(entries[i].me_value);
     }
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
 #ifdef Py_DEBUG
     // free_keys_object() must not be called after _PyDict_Fini()
     assert(state->keys_numfree != -1);
@@ -620,8 +625,7 @@
 {
     PyDictObject *mp;
     assert(keys != NULL);
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
 #ifdef Py_DEBUG
     // new_dict() must not be called after _PyDict_Fini()
     assert(state->numfree != -1);
@@ -1281,8 +1285,7 @@
 #ifdef Py_REF_DEBUG
         _Py_RefTotal--;
 #endif
-        PyInterpreterState *interp = _PyInterpreterState_GET();
-        struct _Py_dict_state *state = &interp->dict_state;
+        struct _Py_dict_state *state = get_dict_state();
 #ifdef Py_DEBUG
         // dictresize() must not be called after _PyDict_Fini()
         assert(state->keys_numfree != -1);
@@ -2032,8 +2035,7 @@
         assert(keys->dk_refcnt == 1);
         dictkeys_decref(keys);
     }
-    PyInterpreterState *interp = _PyInterpreterState_GET();
-    struct _Py_dict_state *state = &interp->dict_state;
+    struct _Py_dict_state *state = get_dict_state();
 #ifdef Py_DEBUG
     // new_dict() must not be called after _PyDict_Fini()
     assert(state->numfree != -1);