Skip to content

Commit 850832e

Browse files
committed
gh-126835: Fix _PY_IS_SMALL_INT() macro
1 parent 382c043 commit 850832e

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Include/internal/pycore_long.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self);
6464
# error "_PY_NSMALLPOSINTS must be greater than or equal to 257"
6565
#endif
6666

67-
#define _PY_IS_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS)
67+
#define _PY_IS_SMALL_INT(val) \
68+
(-_PY_NSMALLNEGINTS <= (val) && (val) < _PY_NSMALLPOSINTS)
6869

6970
// Return a reference to the immortal zero singleton.
7071
// The function cannot return NULL.

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class int "PyObject *" "&PyLong_Type"
2626

2727
#define medium_value(x) ((stwodigits)_PyLong_CompactValue(x))
2828

29-
#define IS_SMALL_INT(ival) (-_PY_NSMALLNEGINTS <= (ival) && (ival) < _PY_NSMALLPOSINTS)
29+
#define IS_SMALL_INT(ival) _PY_IS_SMALL_INT(ival)
3030
#define IS_SMALL_UINT(ival) ((ival) < _PY_NSMALLPOSINTS)
3131

3232
#define _MAX_STR_DIGITS_ERROR_FMT_TO_INT "Exceeds the limit (%d digits) for integer string conversion: value has %zd digits; use sys.set_int_max_str_digits() to increase the limit"

Python/flowgraph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ maybe_instr_make_load_smallint(cfg_instr *instr, PyObject *newconst,
14111411
if (val == -1 && PyErr_Occurred()) {
14121412
return -1;
14131413
}
1414-
if (!overflow && _PY_IS_SMALL_INT(val)) {
1414+
if (!overflow && _PY_IS_SMALL_INT(val) && 0 <= val && val <= 255) {
14151415
assert(_Py_IsImmortal(newconst));
14161416
INSTR_SET_OP1(instr, LOAD_SMALL_INT, (int)val);
14171417
return 1;

0 commit comments

Comments
 (0)