@@ -39,6 +39,7 @@ class object "PyObject *" "&PyBaseObject_Type"
3939 PyUnicode_IS_READY(name) && \
4040 (PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
4141
42+ // bpo-42745: next_version_tag remains shared by all interpreters because of static types
4243// Used to set PyTypeObject.tp_version_tag
4344static unsigned int next_version_tag = 0 ;
4445
@@ -252,8 +253,9 @@ _PyType_InitCache(PyInterpreterState *interp)
252253
253254
254255static unsigned int
255- _PyType_ClearCache (struct type_cache * cache )
256+ _PyType_ClearCache (PyInterpreterState * interp )
256257{
258+ struct type_cache * cache = & interp -> type_cache ;
257259#if MCACHE_STATS
258260 size_t total = cache -> hits + cache -> collisions + cache -> misses ;
259261 fprintf (stderr , "-- Method cache hits = %zd (%d%%)\n" ,
@@ -267,7 +269,10 @@ _PyType_ClearCache(struct type_cache *cache)
267269#endif
268270
269271 unsigned int cur_version_tag = next_version_tag - 1 ;
270- next_version_tag = 0 ;
272+ if (_Py_IsMainInterpreter (interp )) {
273+ next_version_tag = 0 ;
274+ }
275+
271276 type_cache_clear (cache , 0 );
272277
273278 return cur_version_tag ;
@@ -277,15 +282,15 @@ _PyType_ClearCache(struct type_cache *cache)
277282unsigned int
278283PyType_ClearCache (void )
279284{
280- struct type_cache * cache = get_type_cache ();
281- return _PyType_ClearCache (cache );
285+ PyInterpreterState * interp = _PyInterpreterState_GET ();
286+ return _PyType_ClearCache (interp );
282287}
283288
284289
285290void
286291_PyType_Fini (PyInterpreterState * interp )
287292{
288- _PyType_ClearCache (& interp -> type_cache );
293+ _PyType_ClearCache (interp );
289294 if (_Py_IsMainInterpreter (interp )) {
290295 clear_slotdefs ();
291296 }
0 commit comments