Skip to content

Commit

Permalink
Merge branch 'compact-ints2' into specialize-on-compact-int
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Jan 28, 2025
2 parents 114feb3 + e25f138 commit a5eaf63
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Include/cpython/longintrepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ typedef long stwodigits; /* signed variant of twodigits */
*/

typedef struct _PyLongValue {
uintptr_t lv_tag; /* Number of digits, sign and flags */
// uintptr_t lv_tag; /* Number of digits, sign and flags */
uint32_t lv_tag; /* Number of digits, sign and flags */
digit ob_digit[1];
} _PyLongValue;

Expand Down Expand Up @@ -132,7 +133,7 @@ _PyLong_CompactValue(const PyLongObject *op)
Py_ssize_t sign;
assert(PyType_HasFeature(op->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
assert(PyUnstable_Long_IsCompact(op));
sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
sign = 1l - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
return sign * (Py_ssize_t)op->long_value.ob_digit[0];
}

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static inline Py_ssize_t
_PyLong_SignedDigitCount(const PyLongObject *op)
{
assert(PyLong_Check(op));
Py_ssize_t sign = 1 - (op->long_value.lv_tag & SIGN_MASK);
Py_ssize_t sign = 1l - (op->long_value.lv_tag & SIGN_MASK);
return sign * (Py_ssize_t)(op->long_value.lv_tag >> NON_SIZE_BITS);
}

Expand Down
1 change: 1 addition & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ PyLong_AsInt(PyObject *obj)
int overflow;
long result = PyLong_AsLongAndOverflow(obj, &overflow);
if (overflow || result > INT_MAX || result < INT_MIN) {
// if (overflow || (int)result > INT_MAX || (int)result < INT_MIN) {
/* XXX: could be cute and give a different
message for overflow == -1 */
PyErr_SetString(PyExc_OverflowError,
Expand Down

0 comments on commit a5eaf63

Please sign in to comment.