gh-119333: get interp from tstate for PyContext watchers(#124444)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Jason Fried 2024-09-25 22:26:23 -07:00 committed by GitHub
parent de929f353c
commit 46f5cbca4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View File

@ -33,10 +33,9 @@ typedef enum {
} PyContextEvent; } PyContextEvent;
/* /*
* A Callback to clue in non-python contexts impls about a * Callback to be invoked when a context object is entered or exited.
* change in the active python context.
* *
* 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. * the context after its entered and before its exited.
* *
* if the callback returns with an exception set, it must return -1. Otherwise * if the callback returns with an exception set, it must return -1. Otherwise

View File

@ -112,10 +112,10 @@ context_event_name(PyContextEvent event) {
Py_UNREACHABLE(); 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); assert(Py_REFCNT(ctx) > 0);
PyInterpreterState *interp = _PyInterpreterState_GET(); PyInterpreterState *interp = ts->interp;
assert(interp->_initialized); assert(interp->_initialized);
uint8_t bits = interp->active_context_watchers; uint8_t bits = interp->active_context_watchers;
int i = 0; int i = 0;
@ -192,7 +192,7 @@ _PyContext_Enter(PyThreadState *ts, PyObject *octx)
ts->context = Py_NewRef(ctx); ts->context = Py_NewRef(ctx);
ts->context_ver++; ts->context_ver++;
notify_context_watchers(Py_CONTEXT_EVENT_ENTER, ctx); notify_context_watchers(Py_CONTEXT_EVENT_ENTER, ctx, ts);
return 0; return 0;
} }
@ -226,7 +226,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
return -1; 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); Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);
ts->context_ver++; ts->context_ver++;