@@ -2475,9 +2475,18 @@ shift_guard(PyObject *lhs, PyObject *rhs)
2475
2475
2476
2476
// rshift with value larger the the number of bits is undefined in C
2477
2477
// 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 ) );
2479
2479
}
2480
2480
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
+
2481
2490
#define BITWISE_LONGS_ACTION (NAME , OP ) \
2482
2491
static PyObject * \
2483
2492
(NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2489,7 +2498,7 @@ shift_guard(PyObject *lhs, PyObject *rhs)
2489
2498
BITWISE_LONGS_ACTION (compactlongs_or , |)
2490
2499
BITWISE_LONGS_ACTION (compactlongs_and , & )
2491
2500
BITWISE_LONGS_ACTION (compactlongs_xor , ^)
2492
- BITWISE_LONGS_ACTION (compactlongs_lshift , <<)
2501
+ BITWISE_LONGS_ACTION_STWODIGITS (compactlongs_lshift , <<)
2493
2502
BITWISE_LONGS_ACTION (compactlongs_rshift , >>)
2494
2503
#undef BITWISE_LONGS_ACTION
2495
2504
0 commit comments