From 522691c46e2ae51faaad5bbbce7d959dd61770df Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 23 Jun 2020 16:40:40 +0200 Subject: bpo-40521: Cleanup code of free lists (GH-21082) Add get_xxx_state() function to factorize duplicated code. --- Python/context.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Python/context.c') diff --git a/Python/context.c b/Python/context.c index dedbca9938..dc34071884 100644 --- a/Python/context.c +++ b/Python/context.c @@ -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); -- cgit v1.2.1