summaryrefslogtreecommitdiff
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-03-10 17:01:16 -0800
committerGitHub <noreply@github.com>2023-03-10 17:01:16 -0800
commit08b67fb34f4519be1b0bb4673643a2c761c7ae92 (patch)
treee7ab280d96ddc896b3f44845d1d322d317a7d0a0 /Python/specialize.c
parent767d3a8f6f2f94daa15ad3759d0ecdf4c009b7ab (diff)
downloadcpython-git-08b67fb34f4519be1b0bb4673643a2c761c7ae92.tar.gz
GH-90997: Shrink the LOAD_GLOBAL caches (#102569)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 0a7af8991e..719bd5bda3 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1148,8 +1148,12 @@ _Py_Specialize_LoadGlobal(
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_VERSIONS);
goto fail;
}
+ if (keys_version != (uint16_t)keys_version) {
+ SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
+ goto fail;
+ }
cache->index = (uint16_t)index;
- write_u32(cache->module_keys_version, keys_version);
+ cache->module_keys_version = (uint16_t)keys_version;
instr->op.code = LOAD_GLOBAL_MODULE;
goto success;
}
@@ -1177,6 +1181,10 @@ _Py_Specialize_LoadGlobal(
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_VERSIONS);
goto fail;
}
+ if (globals_version != (uint16_t)globals_version) {
+ SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE);
+ goto fail;
+ }
uint32_t builtins_version = _PyDictKeys_GetVersionForCurrentState(
interp, builtin_keys);
if (builtins_version == 0) {
@@ -1188,7 +1196,7 @@ _Py_Specialize_LoadGlobal(
goto fail;
}
cache->index = (uint16_t)index;
- write_u32(cache->module_keys_version, globals_version);
+ cache->module_keys_version = (uint16_t)globals_version;
cache->builtin_keys_version = (uint16_t)builtins_version;
instr->op.code = LOAD_GLOBAL_BUILTIN;
goto success;