gh-124872: Change PyContext_WatchCallback to take PyObject (#124737) · python/cpython@330c527 · GitHub
Skip to content

Commit 330c527

Browse files
authored
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.
1 parent fa52b82 commit 330c527

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

Doc/c-api/contextvars.rst

Lines changed: 1 addition & 1 deletion

Include/cpython/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef enum {
5252
* if the callback returns with an exception set, it must return -1. Otherwise
5353
* it should return 0
5454
*/
55-
typedef int (*PyContext_WatchCallback)(PyContextEvent, PyContext *);
55+
typedef int (*PyContext_WatchCallback)(PyContextEvent, PyObject *);
5656

5757
/*
5858
* Register a per-interpreter callback that will be invoked for context object

Modules/_testcapi/watchers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static int num_context_object_enter_events[NUM_CONTEXT_WATCHERS] = {0, 0};
630630
static int num_context_object_exit_events[NUM_CONTEXT_WATCHERS] = {0, 0};
631631

632632
static int
633-
handle_context_watcher_event(int which_watcher, PyContextEvent event, PyContext *ctx) {
633+
handle_context_watcher_event(int which_watcher, PyContextEvent event, PyObject *ctx) {
634634
if (event == Py_CONTEXT_EVENT_ENTER) {
635635
num_context_object_enter_events[which_watcher]++;
636636
}
@@ -644,22 +644,22 @@ handle_context_watcher_event(int which_watcher, PyContextEvent event, PyContext
644644
}
645645

646646
static int
647-
first_context_watcher_callback(PyContextEvent event, PyContext *ctx) {
647+
first_context_watcher_callback(PyContextEvent event, PyObject *ctx) {
648648
return handle_context_watcher_event(0, event, ctx);
649649
}
650650

651651
static int
652-
second_context_watcher_callback(PyContextEvent event, PyContext *ctx) {
652+
second_context_watcher_callback(PyContextEvent event, PyObject *ctx) {
653653
return handle_context_watcher_event(1, event, ctx);
654654
}
655655

656656
static int
657-
noop_context_event_handler(PyContextEvent event, PyContext *ctx) {
657+
noop_context_event_handler(PyContextEvent event, PyObject *ctx) {
658658
return 0;
659659
}
660660

661661
static int
662-
error_context_event_handler(PyContextEvent event, PyContext *ctx) {
662+
error_context_event_handler(PyContextEvent event, PyObject *ctx) {
663663
PyErr_SetString(PyExc_RuntimeError, "boom!");
664664
return -1;
665665
}

Python/context.c

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)