@@ -3942,6 +3942,15 @@ _wide_op_result(int64_t v)
39423942 return PyStackRef_FromPyObjectStealMortal (result );
39433943}
39443944
3945+ /* Exact int -> int64_t helper for the wide int fast path.
3946+ * Keeps the exact-type check local to this translation unit. */
3947+ static inline bool
3948+ _PyLong_CheckExactAndTryAsInt64 (PyObject * op , int64_t * out )
3949+ {
3950+ return PyLong_CheckExact (op ) &&
3951+ _PyLong_TryAsInt64Exact ((PyLongObject * )op , out );
3952+ }
3953+
39453954/* Wide variant: operands are exact ints in the full int64 range (may be
39463955 * non-compact). Returns PyStackRef_NULL (without raising) when an input is
39473956 * out of int64 range or the sum overflows int64. Returns PyStackRef_ERROR
@@ -3955,7 +3964,8 @@ _PyCompactLong_AddWide(PyLongObject *a, PyLongObject *b)
39553964 return medium_from_stwodigits (v );
39563965 }
39573966 int64_t va , vb ;
3958- if (!_PyLong_TryAsInt64Exact (a , & va ) || !_PyLong_TryAsInt64Exact (b , & vb )) {
3967+ if (!_PyLong_CheckExactAndTryAsInt64 ((PyObject * )a , & va ) ||
3968+ !_PyLong_CheckExactAndTryAsInt64 ((PyObject * )b , & vb )) {
39593969 return PyStackRef_NULL ;
39603970 }
39613971 int64_t v ;
@@ -3972,7 +3982,6 @@ long_add_method(PyObject *a, PyObject *b)
39723982 return (PyObject * )long_add ((PyLongObject * )a , (PyLongObject * )b );
39733983}
39743984
3975-
39763985static PyLongObject *
39773986long_sub (PyLongObject * a , PyLongObject * b )
39783987{
@@ -4032,7 +4041,8 @@ _PyCompactLong_SubtractWide(PyLongObject *a, PyLongObject *b)
40324041 return medium_from_stwodigits (v );
40334042 }
40344043 int64_t va , vb ;
4035- if (!_PyLong_TryAsInt64Exact (a , & va ) || !_PyLong_TryAsInt64Exact (b , & vb )) {
4044+ if (!_PyLong_CheckExactAndTryAsInt64 ((PyObject * )a , & va ) ||
4045+ !_PyLong_CheckExactAndTryAsInt64 ((PyObject * )b , & vb )) {
40364046 return PyStackRef_NULL ;
40374047 }
40384048 int64_t v ;
0 commit comments