@@ -2447,12 +2447,25 @@ is_compactlong(PyObject *v)
24472447 _PyLong_IsCompact ((PyLongObject * )v );
24482448}
24492449
2450+ static inline int
2451+ is_compactnonnegativelong (PyObject * v )
2452+ {
2453+ return PyLong_CheckExact (v ) &&
2454+ _PyLong_IsNonNegativeCompact ((PyLongObject * )v );
2455+ }
2456+
24502457static int
24512458compactlongs_guard (PyObject * lhs , PyObject * rhs )
24522459{
24532460 return (is_compactlong (lhs ) && is_compactlong (rhs ));
24542461}
24552462
2463+ static int
2464+ compactlong_compactnonnegativelong_guard (PyObject * lhs , PyObject * rhs )
2465+ {
2466+ return (is_compactlong (lhs ) && is_compactnonnegativelong (rhs );
2467+ }
2468+
24562469#define BITWISE_LONGS_ACTION (NAME , OP ) \
24572470 static PyObject * \
24582471 (NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2541,11 +2554,11 @@ static _PyBinaryOpSpecializationDescr compactlongs_specs[NB_OPARG_LAST+1] = {
25412554 [NB_OR ] = {compactlongs_guard , compactlongs_or },
25422555 [NB_AND ] = {compactlongs_guard , compactlongs_and },
25432556 [NB_XOR ] = {compactlongs_guard , compactlongs_xor },
2544- [NB_RSHIFT ] = {compactlongs_guard , compactlongs_rshift },
2557+ [NB_RSHIFT ] = {compactlong_compactnonnegativelong_guard , compactlongs_rshift },
25452558 [NB_INPLACE_OR ] = {compactlongs_guard , compactlongs_or },
25462559 [NB_INPLACE_AND ] = {compactlongs_guard , compactlongs_and },
25472560 [NB_INPLACE_XOR ] = {compactlongs_guard , compactlongs_xor },
2548- [NB_INPLACE_RSHIFT ] = {compactlongs_guard , compactlongs_rshift },
2561+ [NB_INPLACE_RSHIFT ] = {compactlong_compactnonnegativelong_guard , compactlongs_rshift },
25492562};
25502563
25512564static _PyBinaryOpSpecializationDescr float_compactlong_specs [NB_OPARG_LAST + 1 ] = {
0 commit comments