diff options
author | Mark Shannon <mark@hotpy.org> | 2024-08-21 14:52:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-21 14:52:04 (GMT) |
commit | a4fd7aa4a6420cef1c22ec64eab54d8aea41cc57 (patch) | |
tree | 026af8576d2d3e05b56c475574606f13f69cf040 /Python/specialize.c | |
parent | 4b7c4880a0b264373e65235701bb78cbf19266b5 (diff) | |
download | cpython-a4fd7aa4a6420cef1c22ec64eab54d8aea41cc57.zip cpython-a4fd7aa4a6420cef1c22ec64eab54d8aea41cc57.tar.gz cpython-a4fd7aa4a6420cef1c22ec64eab54d8aea41cc57.tar.bz2 |
GH-115776: Allow any fixed sized object to have inline values (GH-123192)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index b3a2e07..db794be 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -849,15 +849,19 @@ specialize_dict_access( assert(PyUnicode_CheckExact(name)); Py_ssize_t index = _PyDictKeys_StringLookup(keys, name); assert (index != DKIX_ERROR); - if (index != (uint16_t)index) { - SPECIALIZATION_FAIL(base_op, - index == DKIX_EMPTY ? - SPEC_FAIL_ATTR_NOT_IN_KEYS : - SPEC_FAIL_OUT_OF_RANGE); + if (index == DKIX_EMPTY) { + SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_NOT_IN_KEYS); + return 0; + } + assert(index >= 0); + char *value_addr = (char *)&_PyObject_InlineValues(owner)->values[index]; + Py_ssize_t offset = value_addr - (char *)owner; + if (offset != (uint16_t)offset) { + SPECIALIZATION_FAIL(base_op, SPEC_FAIL_OUT_OF_RANGE); return 0; } write_u32(cache->version, type->tp_version_tag); - cache->index = (uint16_t)index; + cache->index = (uint16_t)offset; instr->op.code = values_op; } else { |