summaryrefslogtreecommitdiff
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorItamar Ostricher <itamarost@gmail.com>2022-12-14 11:14:16 -0800
committerGitHub <noreply@github.com>2022-12-14 19:14:16 +0000
commitae83c782155ffe86830c3255e338f366e331ad30 (patch)
tree353db1dc5287520c07b951467461deb8a10a84c4 /Objects/typeobject.c
parentaa8591e9ca9a3e55e96a03c17fa9d3902f0674dc (diff)
downloadcpython-git-ae83c782155ffe86830c3255e338f366e331ad30.tar.gz
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
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ae80f5a8fd..2c3b39521a 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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 */
}