Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2992,7 +2992,11 @@ long_dealloc(PyObject *v)
Py_TYPE(v)->tp_free(v);
}

static int
/* Returns a negative number when a < b
Returns 0 when a = b
Returns a positive number when a > b */

static Py_ssize_t
long_compare(PyLongObject *a, PyLongObject *b)
{
Py_ssize_t sign;
Expand All @@ -3012,14 +3016,14 @@ long_compare(PyLongObject *a, PyLongObject *b)
sign = -sign;
}
}
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
return sign;
}

static PyObject *
long_richcompare(PyObject *self, PyObject *other, int op)
{
int result;
CHECK_BINOP(self, other);
Py_ssize_t result;
CHECK_BINOP(other, self);
if (self == other)
result = 0;
else
Expand Down Expand Up @@ -3180,7 +3184,7 @@ long_add(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_ABS(Py_SIZE(a)) <= 1 && Py_ABS(Py_SIZE(b)) <= 1) {
return PyLong_FromLong(MEDIUM_VALUE(a) + MEDIUM_VALUE(b));
Expand Down Expand Up @@ -3214,7 +3218,7 @@ long_sub(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_ABS(Py_SIZE(a)) <= 1 && Py_ABS(Py_SIZE(b)) <= 1) {
return PyLong_FromLong(MEDIUM_VALUE(a) - MEDIUM_VALUE(b));
Expand Down Expand Up @@ -3646,7 +3650,7 @@ long_mul(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

/* fast path for single-digit multiplication */
if (Py_ABS(Py_SIZE(a)) <= 1 && Py_ABS(Py_SIZE(b)) <= 1) {
Expand Down Expand Up @@ -3800,7 +3804,7 @@ long_div(PyObject *a, PyObject *b)
{
PyLongObject *div;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_ABS(Py_SIZE(a)) == 1 && Py_ABS(Py_SIZE(b)) == 1) {
return fast_floor_div((PyLongObject*)a, (PyLongObject*)b);
Expand All @@ -3825,7 +3829,7 @@ long_true_divide(PyObject *v, PyObject *w)
int inexact, negate, a_is_small, b_is_small;
double dx, result;

CHECK_BINOP(v, w);
CHECK_BINOP(w, v);
a = (PyLongObject *)v;
b = (PyLongObject *)w;

Expand Down Expand Up @@ -4079,7 +4083,7 @@ long_mod(PyObject *a, PyObject *b)
{
PyLongObject *mod;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_ABS(Py_SIZE(a)) == 1 && Py_ABS(Py_SIZE(b)) == 1) {
return fast_mod((PyLongObject*)a, (PyLongObject*)b);
Expand All @@ -4096,7 +4100,7 @@ long_divmod(PyObject *a, PyObject *b)
PyLongObject *div, *mod;
PyObject *z;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (l_divmod((PyLongObject*)a, (PyLongObject*)b, &div, &mod) < 0) {
return NULL;
Expand Down Expand Up @@ -4131,7 +4135,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

/* a, b, c = v, w, x */
CHECK_BINOP(v, w);
CHECK_BINOP(w, v);
a = (PyLongObject*)v; Py_INCREF(a);
b = (PyLongObject*)w; Py_INCREF(b);
if (PyLong_Check(x)) {
Expand Down Expand Up @@ -4387,7 +4391,7 @@ long_rshift(PyLongObject *a, PyLongObject *b)
Py_ssize_t newsize, wordshift, hishift, i, j;
digit loshift, lomask, himask;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_SIZE(b) < 0) {
PyErr_SetString(PyExc_ValueError,
Expand Down Expand Up @@ -4441,7 +4445,7 @@ long_lshift(PyObject *v, PyObject *w)
digit remshift;
twodigits accum;

CHECK_BINOP(a, b);
CHECK_BINOP(b, a);

if (Py_SIZE(b) < 0) {
PyErr_SetString(PyExc_ValueError, "negative shift count");
Expand Down Expand Up @@ -4626,7 +4630,7 @@ static PyObject *
long_and(PyObject *a, PyObject *b)
{
PyObject *c;
CHECK_BINOP(a, b);
CHECK_BINOP(b, a);
c = long_bitwise((PyLongObject*)a, '&', (PyLongObject*)b);
return c;
}
Expand All @@ -4635,7 +4639,7 @@ static PyObject *
long_xor(PyObject *a, PyObject *b)
{
PyObject *c;
CHECK_BINOP(a, b);
CHECK_BINOP(b, a);
c = long_bitwise((PyLongObject*)a, '^', (PyLongObject*)b);
return c;
}
Expand All @@ -4644,7 +4648,7 @@ static PyObject *
long_or(PyObject *a, PyObject *b)
{
PyObject *c;
CHECK_BINOP(a, b);
CHECK_BINOP(b, a);
c = long_bitwise((PyLongObject*)a, '|', (PyLongObject*)b);
return c;
}
Expand Down Expand Up @@ -5023,7 +5027,8 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
{
PyLongObject *quo = NULL, *rem = NULL;
PyObject *twice_rem, *result, *temp;
int cmp, quo_is_odd, quo_is_neg;
Py_ssize_t cmp;
int quo_is_odd, quo_is_neg;

/* Equivalent Python code:

Expand Down