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
Closed
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
19 changes: 16 additions & 3 deletions 19 Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ PyObject *_PyLong_One = NULL;
*/
static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS];

/* If use inline functions here, may lose performance due to
unnecessary type casting. */
#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Address STINNER Victor's advice:

Morever, if using a static inline function is causing issues, it would be nice to add a comment to explain why, so the issue will be avoided in the future.
https://bugs.python.org/issue37812#msg352670

#define IS_SMALL_UINT(ival) ((ival) < NSMALLPOSINTS)

Expand Down Expand Up @@ -77,11 +79,22 @@ maybe_small_long(PyLongObject *v)
}
return v;
}
#else
#else /* Preallocated small integers disabled */
#define IS_SMALL_INT(ival) 0
#define IS_SMALL_UINT(ival) 0
#define get_small_int(ival) (Py_UNREACHABLE(), NULL)
#define maybe_small_long(val) (val)

static PyObject *
get_small_int(sdigit ival)
{
Py_UNREACHABLE();
return NULL;
}

static inline PyLongObject *
maybe_small_long(PyLongObject *v)
{
return v;
}
#endif

/* If a freshly-allocated int is already shared, it must
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.