Visitar URL original
GH-100000: Cleanup and polish various watchers code by itamaro · Pull Request #99998 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cleanup nits in watchers-related code
- Remove `dict_watchers` array on the interpreter state (was never used, likely added in [the function watchers
PR](https://github.com/python/cpython/pull/98175/files#diff-cb06b7ba43789a1d6ae5bef46baa8a255b72dbcd2b44bfec7f146ea4e94dbfa0) when resolving a merge conflict)
- Cast `METH_NOARGS` function to `(PyCFunction)` in watchers test methods
- Initialize `type_watchers` array to `NULL`s
  • Loading branch information
itamaro committed Dec 4, 2022
commit 468ef723a49f3b375af273aee7a362885ac70d99
1 change: 0 additions & 1 deletion Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ struct _is {
// Initialized to _PyEval_EvalFrameDefault().
_PyFrameEvalFunction eval_frame;

PyDict_WatchCallback dict_watchers[DICT_MAX_WATCHERS];
PyFunction_WatchCallback func_watchers[FUNC_MAX_WATCHERS];
// One bit is set for each non-NULL entry in func_watchers
uint8_t active_func_watchers;
Expand Down
6 changes: 4 additions & 2 deletions Modules/_testcapi/watchers.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,16 @@ static PyMethodDef test_methods[] = {
{"clear_dict_watcher", clear_dict_watcher, METH_O, NULL},
{"watch_dict", watch_dict, METH_VARARGS, NULL},
{"unwatch_dict", unwatch_dict, METH_VARARGS, NULL},
{"get_dict_watcher_events", get_dict_watcher_events, METH_NOARGS, NULL},
{"get_dict_watcher_events",
(PyCFunction) get_dict_watcher_events, METH_NOARGS, NULL},

// Type watchers.
{"add_type_watcher", add_type_watcher, METH_O, NULL},
{"clear_type_watcher", clear_type_watcher, METH_O, NULL},
{"watch_type", watch_type, METH_VARARGS, NULL},
{"unwatch_type", unwatch_type, METH_VARARGS, NULL},
{"get_type_modified_events", get_type_modified_events, METH_NOARGS, NULL},
{"get_type_modified_events",
(PyCFunction) get_type_modified_events, METH_NOARGS, NULL},

// Code object watchers.
{"add_code_watcher", add_code_watcher, METH_O, NULL},
Expand Down
4 changes: 4 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
interp->dict_state.watchers[i] = NULL;
}

for (int i=0; i < TYPE_MAX_WATCHERS; i++) {
interp->type_watchers[i] = NULL;
}

for (int i=0; i < FUNC_MAX_WATCHERS; i++) {
interp->func_watchers[i] = NULL;
}
Expand Down