Skip to content

gh-126835: Fix _PY_IS_SMALL_INT() macro - #146631

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:is_small_int
Mar 30, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:is_small_int

Conversation

@vstinner

@vstinner vstinner commented Mar 30, 2026 •

Copy link
Copy Markdown
Member
@vstinner
vstinner enabled auto-merge (squash) March 30, 2026 12:41
@vstinner
vstinner merged commit adf2c47 into python:main Mar 30, 2026
49 checks passed
@vstinner
vstinner deleted the is_small_int branch March 30, 2026 12:48
Comment thread Objects/longobject.c
#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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now looks redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, IS_SMALL_INT() is shorter and is used in multiple functions. IMO IS_SMALL_INT() is more readable than _PY_IS_SMALL_INT(), and it avoids changing the code.

Comment thread Python/flowgraph.c
return -1;
}
if (!overflow && _PY_IS_SMALL_INT(val)) {
if (!overflow && _PY_IS_SMALL_INT(val) && 0 <= val && val <= 255) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!overflow && _PY_IS_SMALL_INT(val) && 0 <= val && val <= 255) {
if (!overflow && _PY_IS_SMALL_INT(val) && 0 <= val && val < 256) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's the same, and I prefer <= 255 :-)

maurycy added a commit to maurycy/cpython that referenced this pull request Mar 30, 2026
…ktor

* upstream/main: (119 commits)
  pythongh-144270: Make SubElement parent and tag positional-only (pythonGH-144845)
  pythongh-146558: JIT optimize dict access for objects with known hash (python#146559)
  pythongh-139922: always run MSVC 64-bit tail-calling CI (pythonGH-146570)
  pythongh-126835: Fix _PY_IS_SMALL_INT() macro (python#146631)
  pythongh-146587: fix type slot assignment incase of multiple slots for same name (python#146593)
  pythongh-138122: Add differential flame graph (python#145785)
  pythongh-146416: Emscripten: Improve standard stream handling in node_entry.mjs (python#146417)
  pythongh-146444: Don't package as part of iOS 'build hosts' target (python#146628)
  pythongh-138850: Add --disable-epoll to configure (pythonGH-145768)
  pythongh-146444: Make Platforms/Apple/ compatible with Python 3.9 (python#146624)
  pythongh-138577: Fix keyboard shortcuts in getpass with echo_char (python#141597)
  pythongh-146556: Fix infinite loop in annotationlib.get_annotations() on circular __wrapped__ (python#146557)
  pythongh-146579: _zstd: Fix decompression options dict error message (python#146577)
  pythongh-146083: Upgrade bundled Expat to 2.7.5 (python#146085)
  pythongh-146080: fix a crash in SNI callbacks when the SSL object is gone (python#146573)
  pythongh-146090: fix memory management of internal `sqlite3` callback contexts (python#146569)
  pythongh-145876: Do not mask KeyErrors raised during dictionary unpacking in call (pythonGH-146472)
  pythongh-146004: fix test_args_from_interpreter_flags on windows (python#146580)
  pythongh-139003: Use frozenset for module level attributes in _pyrepl.utils (python#139004)
  pythonGH-146527: Add more data to GC statistics and add it to PyDebugOffsets (python#146532)
  ...
@vstinner vstinner added the needs backport to 3.14 bugs and security fixes label Mar 31, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Mar 31, 2026

Copy link
Copy Markdown

GH-147187 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Mar 31, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 31, 2026
(cherry picked from commit adf2c47)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Mar 31, 2026
gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631)
(cherry picked from commit adf2c47)

Co-authored-by: Victor Stinner <vstinner@python.org>
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Apr 16, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants