Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion 2 Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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)

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.

#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"
Expand Down
2 changes: 1 addition & 1 deletion 2 Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,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) {

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 :-)

assert(_Py_IsImmortal(newconst));
INSTR_SET_OP1(instr, LOAD_SMALL_INT, (int)val);
return 1;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.