8000 GH-100000: Cleanup and polish various watchers code by itamaro · Pull Request #99998 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-100000: Cleanup and polish various watchers code #99998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 14, 2022
Merged
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
Prev Previous commit
Next Next commit
Optimize func watchers notification
  • Loading branch information
itamaro committed Dec 5, 2022
commit 0eaed3ec2d0da98ef990cf4e4e4a67386d5dce61
16 changes: 12 additions & 4 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ static void
notify_func_watchers(PyInterpreterState *interp, PyFunction_WatchEvent event,
PyFunctionObject *func, PyObject *new_value)
{
for (int i = 0; i < FUNC_MAX_WATCHERS; i++) {
PyFunction_WatchCallback cb = interp->func_watchers[i];
if ((cb != NULL) && (cb(event, func, new_value) < 0)) {
PyErr_WriteUnraisable((PyObject *) func);
uint8_t bits = interp->active_func_watchers;
int i = 0;
while (bits) {
assert(i < FUNC_MAX_WATCHERS);
if (bits & 1) {
PyFunction_WatchCallback cb = interp->func_watchers[i];
if ((cb != NULL) && (cb(event, func, new_value) < 0)) {
PyErr_WriteUnraisable((PyObject *) func);
}
}
i++;
bits >>= 1;
}
}

Expand All @@ -25,6 +32,7 @@ handle_func_event(PyFunction_WatchEvent event, PyFunctionObject *func,
PyObject *new_value)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
assert(interp->_initialized);
if (interp->active_func_watchers) {
notify_func_watchers(interp, event, func, new_value);
}
Expand Down
0