mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
GH-100000: Cleanup and polish various watchers code (GH-99998)
* Initialize `type_watchers` array to `NULL`s * Optimize code watchers notification * Optimize func watchers notification
This commit is contained in:
parent
aa8591e9ca
commit
ae83c78215
6 changed files with 37 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue