Skip to content

Commit a81e9e3

Browse files
committed
Invalidate type cache before calling watchers.
This avoids the watcher callback potentially using invalid cache entries.
1 parent 1cff448 commit a81e9e3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Objects/typeobject.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,14 @@ type_modified_unlocked(PyTypeObject *type)
11271127
}
11281128
}
11291129

1130+
set_version_unlocked(type, 0); /* 0 is not a valid version tag */
1131+
if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
1132+
// This field *must* be invalidated if the type is modified (see the
1133+
// comment on struct _specialization_cache):
1134+
FT_ATOMIC_STORE_PTR_RELAXED(
1135+
((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
1136+
}
1137+
11301138
// Notify registered type watchers, if any
11311139
if (type->tp_watched) {
11321140
// Note that PyErr_FormatUnraisable is re-entrant and the watcher
@@ -1148,14 +1156,6 @@ type_modified_unlocked(PyTypeObject *type)
11481156
bits >>= 1;
11491157
}
11501158
}
1151-
1152-
set_version_unlocked(type, 0); /* 0 is not a valid version tag */
1153-
if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
1154-
// This field *must* be invalidated if the type is modified (see the
1155-
// comment on struct _specialization_cache):
1156-
FT_ATOMIC_STORE_PTR_RELAXED(
1157-
((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
1158-
}
11591159
}
11601160

11611161
void

0 commit comments

Comments
 (0)