mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-124872: Change PyContext_WatchCallback to take PyObject (#124737)
The PyContext struct is not intended to be public, and users of the API don't need anything more specific than PyObject. Also see gh-78943.
This commit is contained in:
parent
fa52b82c91
commit
330c527299
4 changed files with 10 additions and 10 deletions
|
@ -136,7 +136,7 @@ Context object management functions:
|
||||||
|
|
||||||
.. versionadded:: 3.14
|
.. versionadded:: 3.14
|
||||||
|
|
||||||
.. c:type:: int (*PyContext_WatchCallback)(PyContextEvent event, PyContext* ctx)
|
.. c:type:: int (*PyContext_WatchCallback)(PyContextEvent event, PyObject *obj)
|
||||||
|
|
||||||
Context object watcher callback function. The object passed to the callback
|
Context object watcher callback function. The object passed to the callback
|
||||||
is event-specific; see :c:type:`PyContextEvent` for details.
|
is event-specific; see :c:type:`PyContextEvent` for details.
|
||||||
|
|
|
@ -52,7 +52,7 @@ typedef enum {
|
||||||
* 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
|
||||||
* it should return 0
|
* it should return 0
|
||||||
*/
|
*/
|
||||||
typedef int (*PyContext_WatchCallback)(PyContextEvent, PyContext *);
|
typedef int (*PyContext_WatchCallback)(PyContextEvent, PyObject *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register a per-interpreter callback that will be invoked for context object
|
* Register a per-interpreter callback that will be invoked for context object
|
||||||
|
|
|
@ -630,7 +630,7 @@ static int num_context_object_enter_events[NUM_CONTEXT_WATCHERS] = {0, 0};
|
||||||
static int num_context_object_exit_events[NUM_CONTEXT_WATCHERS] = {0, 0};
|
static int num_context_object_exit_events[NUM_CONTEXT_WATCHERS] = {0, 0};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_context_watcher_event(int which_watcher, PyContextEvent event, PyContext *ctx) {
|
handle_context_watcher_event(int which_watcher, PyContextEvent event, PyObject *ctx) {
|
||||||
if (event == Py_CONTEXT_EVENT_ENTER) {
|
if (event == Py_CONTEXT_EVENT_ENTER) {
|
||||||
num_context_object_enter_events[which_watcher]++;
|
num_context_object_enter_events[which_watcher]++;
|
||||||
}
|
}
|
||||||
|
@ -644,22 +644,22 @@ handle_context_watcher_event(int which_watcher, PyContextEvent event, PyContext
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
first_context_watcher_callback(PyContextEvent event, PyContext *ctx) {
|
first_context_watcher_callback(PyContextEvent event, PyObject *ctx) {
|
||||||
return handle_context_watcher_event(0, event, ctx);
|
return handle_context_watcher_event(0, event, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
second_context_watcher_callback(PyContextEvent event, PyContext *ctx) {
|
second_context_watcher_callback(PyContextEvent event, PyObject *ctx) {
|
||||||
return handle_context_watcher_event(1, event, ctx);
|
return handle_context_watcher_event(1, event, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
noop_context_event_handler(PyContextEvent event, PyContext *ctx) {
|
noop_context_event_handler(PyContextEvent event, PyObject *ctx) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
error_context_event_handler(PyContextEvent event, PyContext *ctx) {
|
error_context_event_handler(PyContextEvent event, PyObject *ctx) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "boom!");
|
PyErr_SetString(PyExc_RuntimeError, "boom!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ context_event_name(PyContextEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_context_watchers(PyThreadState *ts, PyContextEvent event, PyContext *ctx)
|
notify_context_watchers(PyThreadState *ts, PyContextEvent event, PyObject *ctx)
|
||||||
{
|
{
|
||||||
assert(Py_REFCNT(ctx) > 0);
|
assert(Py_REFCNT(ctx) > 0);
|
||||||
PyInterpreterState *interp = ts->interp;
|
PyInterpreterState *interp = ts->interp;
|
||||||
|
@ -193,7 +193,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(ts, Py_CONTEXT_EVENT_ENTER, ctx);
|
notify_context_watchers(ts, Py_CONTEXT_EVENT_ENTER, octx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_context_watchers(ts, Py_CONTEXT_EVENT_EXIT, ctx);
|
notify_context_watchers(ts, Py_CONTEXT_EVENT_EXIT, octx);
|
||||||
Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);
|
Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);
|
||||||
ts->context_ver++;
|
ts->context_ver++;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue