mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +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
|
@ -15,14 +15,21 @@ static void
|
|||
notify_code_watchers(PyCodeEvent event, PyCodeObject *co)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->active_code_watchers) {
|
||||
assert(interp->_initialized);
|
||||
for (int i = 0; i < CODE_MAX_WATCHERS; i++) {
|
||||
assert(interp->_initialized);
|
||||
uint8_t bits = interp->active_code_watchers;
|
||||
int i = 0;
|
||||
while (bits) {
|
||||
assert(i < CODE_MAX_WATCHERS);
|
||||
if (bits & 1) {
|
||||
PyCode_WatchCallback cb = interp->code_watchers[i];
|
||||
if ((cb != NULL) && (cb(event, co) < 0)) {
|
||||
// callback must be non-null if the watcher bit is set
|
||||
assert(cb != NULL);
|
||||
if (cb(event, co) < 0) {
|
||||
PyErr_WriteUnraisable((PyObject *) co);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
bits >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue