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

@ -66,6 +66,14 @@ static int
contextvar_del(PyContextVar *var);
static struct _Py_context_state *
get_context_state(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
return &interp->context;
}
PyObject *
_PyContext_NewHamtForTests(void)
{
@ -332,8 +340,7 @@ class _contextvars.Context "PyContext *" "&PyContext_Type"
static inline PyContext *
_context_alloc(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _Py_context_state *state = &interp->context;
struct _Py_context_state *state = get_context_state();
PyContext *ctx;
#ifdef Py_DEBUG
// _context_alloc() must not be called after _PyContext_Fini()
@ -462,8 +469,7 @@ context_tp_dealloc(PyContext *self)
}
(void)context_tp_clear(self);
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _Py_context_state *state = &interp->context;
struct _Py_context_state *state = get_context_state();
#ifdef Py_DEBUG
// _context_alloc() must not be called after _PyContext_Fini()
assert(state->numfree != -1);