summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorjunyixie <xie.junyi@outlook.com>2021-03-13 13:38:36 (GMT)
committerGitHub <noreply@github.com>2021-03-13 13:38:36 (GMT)
commit75048c8a38005845f10f8cb1dd33a31e0052cae0 (patch)
treedaffa671aa912512a376ffcfbbcbb8a4489d32ec /Objects
parent5bd1059184b154d339f1bd53d23c98b5bcf14c8c (diff)
downloadcpython-75048c8a38005845f10f8cb1dd33a31e0052cae0.zip
cpython-75048c8a38005845f10f8cb1dd33a31e0052cae0.tar.gz
cpython-75048c8a38005845f10f8cb1dd33a31e0052cae0.tar.bz2
bpo-43441: Fix _PyType_ClearCache() for subinterpreters (GH-24822)
_PyType_ClearCache() now only resets next_version_tag in the main interpreter. Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 9e71214..650e414 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -39,6 +39,7 @@ class object "PyObject *" "&PyBaseObject_Type"
PyUnicode_IS_READY(name) && \
(PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
+// bpo-42745: next_version_tag remains shared by all interpreters because of static types
// Used to set PyTypeObject.tp_version_tag
static unsigned int next_version_tag = 0;
@@ -252,8 +253,9 @@ _PyType_InitCache(PyInterpreterState *interp)
static unsigned int
-_PyType_ClearCache(struct type_cache *cache)
+_PyType_ClearCache(PyInterpreterState *interp)
{
+ struct type_cache *cache = &interp->type_cache;
#if MCACHE_STATS
size_t total = cache->hits + cache->collisions + cache->misses;
fprintf(stderr, "-- Method cache hits = %zd (%d%%)\n",
@@ -267,7 +269,10 @@ _PyType_ClearCache(struct type_cache *cache)
#endif
unsigned int cur_version_tag = next_version_tag - 1;
- next_version_tag = 0;
+ if (_Py_IsMainInterpreter(interp)) {
+ next_version_tag = 0;
+ }
+
type_cache_clear(cache, 0);
return cur_version_tag;
@@ -277,15 +282,15 @@ _PyType_ClearCache(struct type_cache *cache)
unsigned int
PyType_ClearCache(void)
{
- struct type_cache *cache = get_type_cache();
- return _PyType_ClearCache(cache);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return _PyType_ClearCache(interp);
}
void
_PyType_Fini(PyInterpreterState *interp)
{
- _PyType_ClearCache(&interp->type_cache);
+ _PyType_ClearCache(interp);
if (_Py_IsMainInterpreter(interp)) {
clear_slotdefs();
}