mirror of
https://github.com/python/cpython.git
synced 2025-08-16 23:01:34 +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
|
@ -485,23 +485,24 @@ PyType_Modified(PyTypeObject *type)
|
|||
}
|
||||
}
|
||||
|
||||
// Notify registered type watchers, if any
|
||||
if (type->tp_watched) {
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
int bits = type->tp_watched;
|
||||
int i = 0;
|
||||
while(bits && i < TYPE_MAX_WATCHERS) {
|
||||
while (bits) {
|
||||
assert(i < TYPE_MAX_WATCHERS);
|
||||
if (bits & 1) {
|
||||
PyType_WatchCallback cb = interp->type_watchers[i];
|
||||
if (cb && (cb(type) < 0)) {
|
||||
PyErr_WriteUnraisable((PyObject *)type);
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
i++;
|
||||
bits >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
|
||||
type->tp_version_tag = 0; /* 0 is not a valid version tag */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue