diff options
author | Kirill Podoprigora <kirill.bast9@mail.ru> | 2024-10-15 14:42:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-15 14:42:16 (GMT) |
commit | d3c82b9ccedd77fc302f5ab8ab0220b3372f574c (patch) | |
tree | ee15c5f380dadeac8ee875abbc73b20f8067a12e /Python | |
parent | 55c4f4c30b49734ce35dc88139b8b4fdc94c66fd (diff) | |
download | cpython-d3c82b9ccedd77fc302f5ab8ab0220b3372f574c.zip cpython-d3c82b9ccedd77fc302f5ab8ab0220b3372f574c.tar.gz cpython-d3c82b9ccedd77fc302f5ab8ab0220b3372f574c.tar.bz2 |
gh-125512: Revert "gh-124872: Replace enter/exit events with "switched" (#124776)" (#125513)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/context.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/Python/context.c b/Python/context.c index 95aa822..8bc487a 100644 --- a/Python/context.c +++ b/Python/context.c @@ -102,8 +102,10 @@ PyContext_CopyCurrent(void) static const char * context_event_name(PyContextEvent event) { switch (event) { - case Py_CONTEXT_SWITCHED: - return "Py_CONTEXT_SWITCHED"; + case Py_CONTEXT_EVENT_ENTER: + return "Py_CONTEXT_EVENT_ENTER"; + case Py_CONTEXT_EVENT_EXIT: + return "Py_CONTEXT_EVENT_EXIT"; default: return "?"; } @@ -113,13 +115,6 @@ context_event_name(PyContextEvent event) { static void notify_context_watchers(PyThreadState *ts, PyContextEvent event, PyObject *ctx) { - if (ctx == NULL) { - // This will happen after exiting the last context in the stack, which - // can occur if context_get was never called before entering a context - // (e.g., called `contextvars.Context().run()` on a fresh thread, as - // PyContext_Enter doesn't call context_get). - ctx = Py_None; - } assert(Py_REFCNT(ctx) > 0); PyInterpreterState *interp = ts->interp; assert(interp->_initialized); @@ -180,16 +175,6 @@ PyContext_ClearWatcher(int watcher_id) } -static inline void -context_switched(PyThreadState *ts) -{ - ts->context_ver++; - // ts->context is used instead of context_get() because context_get() might - // throw if ts->context is NULL. - notify_context_watchers(ts, Py_CONTEXT_SWITCHED, ts->context); -} - - static int _PyContext_Enter(PyThreadState *ts, PyObject *octx) { @@ -206,7 +191,9 @@ _PyContext_Enter(PyThreadState *ts, PyObject *octx) ctx->ctx_entered = 1; ts->context = Py_NewRef(ctx); - context_switched(ts); + ts->context_ver++; + + notify_context_watchers(ts, Py_CONTEXT_EVENT_ENTER, octx); return 0; } @@ -240,11 +227,13 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx) return -1; } + notify_context_watchers(ts, Py_CONTEXT_EVENT_EXIT, octx); Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev); + ts->context_ver++; ctx->ctx_prev = NULL; ctx->ctx_entered = 0; - context_switched(ts); + return 0; } |