diff options
author | Nadeshiko Manju <me@manjusaka.me> | 2025-05-21 06:02:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-20 18:02:50 -0400 |
commit | e1c0c451a2ff815fc817e71ec15c37bff9cb84d0 (patch) | |
tree | d3341c74525bfd9fe14f1625a0f65f59ac94519d /Python/optimizer_cases.c.h | |
parent | e4fbfb12889013fd52565cd2598a366754cb677b (diff) | |
download | cpython-e1c0c451a2ff815fc817e71ec15c37bff9cb84d0.tar.gz cpython-e1c0c451a2ff815fc817e71ec15c37bff9cb84d0.zip |
GH-131798: Narrow the return type of _GET_LEN to int (GH-133345)
Diffstat (limited to 'Python/optimizer_cases.c.h')
-rw-r--r-- | Python/optimizer_cases.c.h | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index a2c68457d8e..0a539b2829e 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -1463,8 +1463,29 @@ } case _GET_LEN: { + JitOptSymbol *obj; JitOptSymbol *len; - len = sym_new_not_null(ctx); + obj = stack_pointer[-1]; + int tuple_length = sym_tuple_length(obj); + if (tuple_length == -1) { + len = sym_new_type(ctx, &PyLong_Type); + } + else { + assert(tuple_length >= 0); + PyObject *temp = PyLong_FromLong(tuple_length); + if (temp == NULL) { + goto error; + } + if (_Py_IsImmortal(temp)) { + REPLACE_OP(this_instr, _LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp); + } + len = sym_new_const(ctx, temp); + stack_pointer[0] = len; + stack_pointer += 1; + assert(WITHIN_STACK_BOUNDS()); + Py_DECREF(temp); + stack_pointer += -1; + } stack_pointer[0] = len; stack_pointer += 1; assert(WITHIN_STACK_BOUNDS()); |