https://github.com/python/cpython/commit/e387bac1a4a36c1b5c7899d1e79d6d424fae7b85
commit: e387bac1a4a36c1b5c7899d1e79d6d424fae7b85
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-31T13:27:11Z
summary:

[3.14] gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631) (#147187)

gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631)
(cherry picked from commit adf2c47911b35134cf108c24a3cc7794b7755aac)

Co-authored-by: Victor Stinner <[email protected]>

files:
M Include/internal/pycore_long.h
M Objects/longobject.c
M Python/flowgraph.c

diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index 3196d1b82084b9..ec84dc167a868c 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -64,7 +64,8 @@ PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self);
 #  error "_PY_NSMALLPOSINTS must be greater than or equal to 257"
 #endif
 
-#define _PY_IS_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < 
_PY_NSMALLPOSINTS)
+#define _PY_IS_SMALL_INT(val) \
+    (-_PY_NSMALLNEGINTS <= (val) && (val) < _PY_NSMALLPOSINTS)
 
 // Return a reference to the immortal zero singleton.
 // The function cannot return NULL.
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 803da9f590be65..3d936cb92565c0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -24,7 +24,7 @@ class int "PyObject *" "&PyLong_Type"
 
 #define medium_value(x) ((stwodigits)_PyLong_CompactValue(x))
 
-#define IS_SMALL_INT(ival) (-_PY_NSMALLNEGINTS <= (ival) && (ival) < 
_PY_NSMALLPOSINTS)
+#define IS_SMALL_INT(ival) _PY_IS_SMALL_INT(ival)
 #define IS_SMALL_UINT(ival) ((ival) < _PY_NSMALLPOSINTS)
 
 #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"
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 04cd7a003da963..87e90ddeef91d5 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1397,7 +1397,7 @@ maybe_instr_make_load_smallint(cfg_instr *instr, PyObject 
*newconst,
         if (val == -1 && PyErr_Occurred()) {
             return -1;
         }
-        if (!overflow && _PY_IS_SMALL_INT(val)) {
+        if (!overflow && _PY_IS_SMALL_INT(val) && 0 <= val && val <= 255) {
             assert(_Py_IsImmortal(newconst));
             INSTR_SET_OP1(instr, LOAD_SMALL_INT, (int)val);
             return 1;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to