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

Add get_xxx_state() function to factorize duplicated code.
This commit is contained in:
Victor Stinner 2020-06-23 16:40:40 +02:00 committed by GitHub
parent bc43f6e212
commit 522691c46e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 69 deletions

View file

@ -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));