Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Rename to _PyLong_IsSmallInt()
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
  • Loading branch information
vstinner and skirpichev authored Mar 31, 2026
commit 45b3b040da09b93a42a32e71f08de5670f8d79d6
4 changes: 2 additions & 2 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ _PyLong_IsPositive(const PyLongObject *op)

/* Return true if the argument is a small int */
static inline bool
Comment thread
skirpichev marked this conversation as resolved.
_PyLong_HasImmortalTag(const PyLongObject *op)
_PyLong_IsSmallInt(const PyLongObject *op)
{
assert(PyLong_Check(op));
bool is_small_int = (op->long_value.lv_tag & IMMORTALITY_BIT_MASK) != 0;
Expand Down Expand Up @@ -309,7 +309,7 @@ _PyLong_SetDigitCount(PyLongObject *op, Py_ssize_t size)
static inline void
_PyLong_FlipSign(PyLongObject *op)
{
assert(!_PyLong_HasImmortalTag(op));
assert(!_PyLong_IsSmallInt(op));
unsigned int flipped_sign = 2 - (op->long_value.lv_tag & SIGN_MASK);
op->long_value.lv_tag &= NON_SIZE_MASK;
op->long_value.lv_tag |= flipped_sign;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapi/immortal.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ test_immortal_small_ints(PyObject *self, PyObject *Py_UNUSED(ignored))
for (int i = -5; i <= 1024; i++) {
PyObject *obj = PyLong_FromLong(i);
assert(verify_immortality(obj));
int has_int_immortal_bit = _PyLong_HasImmortalTag((PyLongObject *)obj);
int has_int_immortal_bit = _PyLong_IsSmallInt((PyLongObject *)obj);
assert(has_int_immortal_bit);
}
for (int i = 1025; i <= 1030; i++) {
PyObject *obj = PyLong_FromLong(i);
assert(obj);
int has_int_immortal_bit = _PyLong_HasImmortalTag((PyLongObject *)obj);
int has_int_immortal_bit = _PyLong_IsSmallInt((PyLongObject *)obj);
assert(!has_int_immortal_bit);
Py_DECREF(obj);
}
Expand Down
4 changes: 2 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,7 @@ void
_PyLong_ExactDealloc(PyObject *self)
{
assert(PyLong_CheckExact(self));
if (_PyLong_HasImmortalTag((PyLongObject *)self)) {
if (_PyLong_IsSmallInt((PyLongObject *)self)) {
// See PEP 683, section Accidental De-Immortalizing for details
_Py_SetImmortal(self);
return;
Expand All @@ -3642,7 +3642,7 @@ _PyLong_ExactDealloc(PyObject *self)
static void
long_dealloc(PyObject *self)
{
if (_PyLong_HasImmortalTag((PyLongObject *)self)) {
if (_PyLong_IsSmallInt((PyLongObject *)self)) {
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
Expand Down
Loading