summaryrefslogtreecommitdiffstats
path: root/Objects/frameobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-23 14:40:40 (GMT)
committerGitHub <noreply@github.com>2020-06-23 14:40:40 (GMT)
commit522691c46e2ae51faaad5bbbce7d959dd61770df (patch)
treeb6f833b6712837379d135d56125b9f3fe0dc4fa0 /Objects/frameobject.c
parentbc43f6e21244f31d25896875430174cd4ac7604c (diff)
downloadcpython-522691c46e2ae51faaad5bbbce7d959dd61770df.zip
cpython-522691c46e2ae51faaad5bbbce7d959dd61770df.tar.gz
cpython-522691c46e2ae51faaad5bbbce7d959dd61770df.tar.bz2
bpo-40521: Cleanup code of free lists (GH-21082)
Add get_xxx_state() function to factorize duplicated code.
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r--Objects/frameobject.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 6e1cbcf..7c2bce3 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -22,6 +22,15 @@ static PyMemberDef frame_memberlist[] = {
{NULL} /* Sentinel */
};
+
+static struct _Py_frame_state *
+get_frame_state(void)
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return &interp->frame;
+}
+
+
static PyObject *
frame_getlocals(PyFrameObject *f, void *closure)
{
@@ -593,8 +602,7 @@ frame_dealloc(PyFrameObject *f)
co->co_zombieframe = f;
}
else {
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_frame_state *state = &interp->frame;
+ struct _Py_frame_state *state = get_frame_state();
#ifdef Py_DEBUG
// frame_dealloc() must not be called after _PyFrame_Fini()
assert(state->numfree != -1);
@@ -784,8 +792,7 @@ frame_alloc(PyCodeObject *code)
Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars);
Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars);
Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees;
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_frame_state *state = &interp->frame;
+ struct _Py_frame_state *state = get_frame_state();
if (state->free_list == NULL)
{
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
@@ -1206,8 +1213,7 @@ _PyFrame_Fini(PyThreadState *tstate)
void
_PyFrame_DebugMallocStats(FILE *out)
{
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_frame_state *state = &interp->frame;
+ struct _Py_frame_state *state = get_frame_state();
_PyDebugAllocatorStats(out,
"free PyFrameObject",
state->numfree, sizeof(PyFrameObject));