@@ -2475,9 +2475,18 @@ shift_guard(PyObject *lhs, PyObject *rhs)
24752475
24762476 // rshift with value larger the the number of bits is undefined in C
24772477 // for lshift we do not want to overflow, but we always have at least 16 bits available
2478- return (is_compactlong (lhs ) && is_compactnonnegativelong (rhs ) && (_PyLong_CompactValue ((PyLongObject * )rhs ) <= 12 ) );
2478+ return (is_compactlong (lhs ) && is_compactnonnegativelong (rhs ) && (_PyLong_CompactValue ((PyLongObject * )rhs ) <= 16 ) );
24792479}
24802480
2481+ #define BITWISE_LONGS_ACTION_STWODIGITS (NAME , OP ) \
2482+ static PyObject * \
2483+ (NAME)(PyObject *lhs, PyObject *rhs) \
2484+ { \
2485+ stwodigits rhs_val = (stwodigits)_PyLong_CompactValue((PyLongObject *)rhs); \
2486+ stwodigits lhs_val = (stwodigits) _PyLong_CompactValue((PyLongObject *)lhs); \
2487+ return PyLong_FromLongLong(lhs_val OP rhs_val); \
2488+ }
2489+
24812490#define BITWISE_LONGS_ACTION (NAME , OP ) \
24822491 static PyObject * \
24832492 (NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2489,7 +2498,7 @@ shift_guard(PyObject *lhs, PyObject *rhs)
24892498BITWISE_LONGS_ACTION (compactlongs_or , |)
24902499BITWISE_LONGS_ACTION (compactlongs_and , & )
24912500BITWISE_LONGS_ACTION (compactlongs_xor , ^)
2492- BITWISE_LONGS_ACTION (compactlongs_lshift , <<)
2501+ BITWISE_LONGS_ACTION_STWODIGITS (compactlongs_lshift , <<)
24932502BITWISE_LONGS_ACTION (compactlongs_rshift , >>)
24942503#undef BITWISE_LONGS_ACTION
24952504
0 commit comments