summaryrefslogtreecommitdiffstats
path: root/Python
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 /Python
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 'Python')
-rw-r--r--Python/context.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/context.c b/Python/context.c
index dedbca9..dc34071 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);