]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119333: get interp from tstate for PyContext watchers(#124444)
authorJason Fried <me@jasonfried.info>
Thu, 26 Sep 2024 05:26:23 +0000 (22:26 -0700)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2024 05:26:23 +0000 (05:26 +0000)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Include/cpython/context.h
Python/context.c

index a509f4eaba3d77fddaab482c40d7ef0fe3323cb2..ec72966e82c6f9b779a9b10b141b1dfe58a1efcb 100644 (file)
@@ -33,10 +33,9 @@ typedef enum {
 } PyContextEvent;
 
 /*
- * A Callback to clue in non-python contexts impls about a
- * change in the active python context.
+ * Callback to be invoked when a context object is entered or exited.
  *
- * The callback is invoked with the event and a reference to =
+ * The callback is invoked with the event and a reference to
  * the context after its entered and before its exited.
  *
  * if the callback returns with an exception set, it must return -1. Otherwise
index e52efbb6516d5c7d2ae1ff6a42c9c9d51ca6a3ac..ddb03555f9e4025d616df613ed01095c49966eeb 100644 (file)
@@ -112,10 +112,10 @@ context_event_name(PyContextEvent event) {
     Py_UNREACHABLE();
 }
 
-static void notify_context_watchers(PyContextEvent event, PyContext *ctx)
+static void notify_context_watchers(PyContextEvent event, PyContext *ctx, PyThreadState *ts)
 {
     assert(Py_REFCNT(ctx) > 0);
-    PyInterpreterState *interp = _PyInterpreterState_GET();
+    PyInterpreterState *interp = ts->interp;
     assert(interp->_initialized);
     uint8_t bits = interp->active_context_watchers;
     int i = 0;
@@ -192,7 +192,7 @@ _PyContext_Enter(PyThreadState *ts, PyObject *octx)
     ts->context = Py_NewRef(ctx);
     ts->context_ver++;
 
-    notify_context_watchers(Py_CONTEXT_EVENT_ENTER, ctx);
+    notify_context_watchers(Py_CONTEXT_EVENT_ENTER, ctx, ts);
     return 0;
 }
 
@@ -226,7 +226,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
         return -1;
     }
 
-    notify_context_watchers(Py_CONTEXT_EVENT_EXIT, ctx);
+    notify_context_watchers(Py_CONTEXT_EVENT_EXIT, ctx, ts);
     Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);
     ts->context_ver++;