summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-03-29 22:53:30 (GMT)
committerGitHub <noreply@github.com>2023-03-29 22:53:30 (GMT)
commit121057aa3600c4d4d392539aeb79e1b09fd5659d (patch)
treeed1b99c697ad052eb38e38c2da2d07bfe2bf0838 /Python/specialize.c
parente647dbaded898e5399d01d06771c1b42b5631be8 (diff)
downloadcpython-121057aa3600c4d4d392539aeb79e1b09fd5659d.zip
cpython-121057aa3600c4d4d392539aeb79e1b09fd5659d.tar.gz
cpython-121057aa3600c4d4d392539aeb79e1b09fd5659d.tar.bz2
GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index dd5b22d..9187438 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1330,16 +1330,16 @@ _Py_Specialize_BinarySubscr(
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
goto fail;
}
- assert(cls->tp_version_tag != 0);
- write_u32(cache->type_version, cls->tp_version_tag);
- int version = _PyFunction_GetVersionForCurrentState(func);
- if (version == 0 || version != (uint16_t)version) {
- SPECIALIZATION_FAIL(BINARY_SUBSCR, version == 0 ?
- SPEC_FAIL_OUT_OF_VERSIONS : SPEC_FAIL_OUT_OF_RANGE);
+ uint32_t version = _PyFunction_GetVersionForCurrentState(func);
+ if (version == 0) {
+ SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_VERSIONS);
goto fail;
}
- cache->func_version = version;
- ((PyHeapTypeObject *)container_type)->_spec_cache.getitem = descriptor;
+ PyHeapTypeObject *ht = (PyHeapTypeObject *)container_type;
+ // This pointer is invalidated by PyType_Modified (see the comment on
+ // struct _specialization_cache):
+ ht->_spec_cache.getitem = descriptor;
+ ht->_spec_cache.getitem_version = version;
instr->op.code = BINARY_SUBSCR_GETITEM;
goto success;
}