summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 9df0652..d5cf5b9 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -12,11 +12,20 @@ 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];
+ // callback must be non-null if the watcher bit is set
+ assert(cb != NULL);
+ if (cb(event, func, new_value) < 0) {
+ PyErr_WriteUnraisable((PyObject *) func);
+ }
}
+ i++;
+ bits >>= 1;
}
}
@@ -25,6 +34,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);
}