memcpy(tmp->ob_digit,
z->ob_digit,
sizeof(digit) * size_z);
- Py_DECREF(z);
- z = tmp;
+ Py_SETREF(z, tmp);
z->ob_digit[size_z] = (digit)c;
++size_z;
}
(Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
PyLongObject *temp;
temp = (PyLongObject *) long_add(mod, w);
- Py_DECREF(mod);
- mod = temp;
+ Py_SETREF(mod, temp);
if (mod == NULL) {
Py_DECREF(div);
return -1;
Py_DECREF(div);
return -1;
}
- Py_DECREF(div);
- div = temp;
+ Py_SETREF(div, temp);
}
if (pdiv != NULL)
*pdiv = div;
(Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
PyLongObject *temp;
temp = (PyLongObject *) long_add(mod, w);
- Py_DECREF(mod);
- mod = temp;
+ Py_SETREF(mod, temp);
if (mod == NULL)
return -1;
}
else {
PyLongObject *div, *rem;
div = x_divrem(x, b, &rem);
- Py_DECREF(x);
- x = div;
+ Py_SETREF(x, div);
if (x == NULL)
goto error;
if (Py_SIZE(rem))
if (l_divmod(a, n, &q, &r) == -1) {
goto Error;
}
- Py_DECREF(a);
- a = n;
+ Py_SETREF(a, n);
n = r;
t = (PyLongObject *)long_mul(q, c);
Py_DECREF(q);
if (s == NULL) {
goto Error;
}
- Py_DECREF(b);
- b = c;
+ Py_SETREF(b, c);
c = s;
}
/* references now owned: a, b, c, n */
temp = (PyLongObject *)_PyLong_Copy(c);
if (temp == NULL)
goto Error;
- Py_DECREF(c);
- c = temp;
+ Py_SETREF(c, temp);
temp = NULL;
_PyLong_Negate(&c);
if (c == NULL)
temp = (PyLongObject *)_PyLong_Copy(b);
if (temp == NULL)
goto Error;
- Py_DECREF(b);
- b = temp;
+ Py_SETREF(b, temp);
temp = NULL;
_PyLong_Negate(&b);
if (b == NULL)
temp = long_invmod(a, c);
if (temp == NULL)
goto Error;
- Py_DECREF(a);
- a = temp;
+ Py_SETREF(a, temp);
temp = NULL;
}
if (Py_SIZE(a) < 0 || Py_SIZE(a) > Py_SIZE(c)) {
if (l_mod(a, c, &temp) < 0)
goto Error;
- Py_DECREF(a);
- a = temp;
+ Py_SETREF(a, temp);
temp = NULL;
}
}
* because we're primarily trying to cut overhead for small powers.
*/
assert(bi); /* else there is no significant bit */
- Py_INCREF(a);
- Py_DECREF(z);
- z = a;
+ Py_SETREF(z, Py_NewRef(a));
for (bit = 2; ; bit <<= 1) {
if (bit > bi) { /* found the first bit */
assert((bi & bit) == 0);
temp = (PyLongObject *)long_sub(z, c);
if (temp == NULL)
goto Error;
- Py_DECREF(z);
- z = temp;
+ Py_SETREF(z, temp);
temp = NULL;
}
goto Done;
/* no progress; do a Euclidean step */
if (l_mod(a, b, &r) < 0)
goto error;
- Py_DECREF(a);
- a = b;
+ Py_SETREF(a, b);
b = r;
alloc_a = alloc_b;
alloc_b = Py_SIZE(b);
goto error;
if (quo_is_neg) {
temp = long_neg((PyLongObject*)twice_rem);
- Py_DECREF(twice_rem);
- twice_rem = temp;
+ Py_SETREF(twice_rem, temp);
if (twice_rem == NULL)
goto error;
}
temp = long_sub(quo, (PyLongObject *)one);
else
temp = long_add(quo, (PyLongObject *)one);
- Py_DECREF(quo);
- quo = (PyLongObject *)temp;
+ Py_SETREF(quo, (PyLongObject *)temp);
if (quo == NULL)
goto error;
/* and remainder */
temp = long_add(rem, (PyLongObject *)b);
else
temp = long_sub(rem, (PyLongObject *)b);
- Py_DECREF(rem);
- rem = (PyLongObject *)temp;
+ Py_SETREF(rem, (PyLongObject *)temp);
if (rem == NULL)
goto error;
}
/* result = self - divmod_near(self, 10 ** -ndigits)[1] */
temp = long_neg((PyLongObject*)ndigits);
- Py_DECREF(ndigits);
- ndigits = temp;
+ Py_SETREF(ndigits, temp);
if (ndigits == NULL)
return NULL;
temp = long_pow(result, ndigits, Py_None);
Py_DECREF(ndigits);
- Py_DECREF(result);
- result = temp;
+ Py_SETREF(result, temp);
if (result == NULL)
return NULL;
temp = _PyLong_DivmodNear(self, result);
- Py_DECREF(result);
- result = temp;
+ Py_SETREF(result, temp);
if (result == NULL)
return NULL;
temp = long_sub((PyLongObject *)self,
(PyLongObject *)PyTuple_GET_ITEM(result, 1));
- Py_DECREF(result);
- result = temp;
+ Py_SETREF(result, temp);
return result;
}
Py_DECREF(x);
if (y == NULL)
goto error;
- Py_DECREF(result);
- result = y;
+ Py_SETREF(result, y);
x = (PyLongObject *)PyLong_FromLong((long)msd_bits);
if (x == NULL)
Py_DECREF(x);
if (y == NULL)
goto error;
- Py_DECREF(result);
- result = y;
+ Py_SETREF(result, y);
return (PyObject *)result;
if (y == NULL) {
goto error;
}
- Py_DECREF(result);
- result = y;
+ Py_SETREF(result, y);
}
return result;