# define MAX_LONG_DIGITS ((INT64_MAX-1) / PyLong_SHIFT)
#endif
-PyLongObject *
-_PyLong_New(Py_ssize_t size)
+static PyLongObject *
+long_alloc(Py_ssize_t size)
{
assert(size >= 0);
PyLongObject *result = NULL;
return result;
}
+PyLongObject *
+_PyLong_New(Py_ssize_t size)
+{
+ return long_alloc(size);
+}
+
PyLongObject *
_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits)
{
if (digit_count == 0) {
return (PyLongObject *)_PyLong_GetZero();
}
- PyLongObject *result = _PyLong_New(digit_count);
+ PyLongObject *result = long_alloc(digit_count);
if (result == NULL) {
PyErr_NoMemory();
return NULL;
++ndigits;
t >>= PyLong_SHIFT;
}
- PyLongObject *v = _PyLong_New(ndigits);
+ PyLongObject *v = long_alloc(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
_PyLong_SetSignAndDigitCount(v, sign, ndigits);
}
/* Construct output value. */
- v = _PyLong_New(ndigits);
+ v = long_alloc(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
_PyLong_SetSignAndDigitCount(v, ival < 0 ? -1 : 1, ndigits);
++ndigits; \
t >>= PyLong_SHIFT; \
} \
- PyLongObject *v = _PyLong_New(ndigits); \
+ PyLongObject *v = long_alloc(ndigits); \
if (v == NULL) { \
return NULL; \
} \
frac = frexp(dval, &expo); /* dval = frac*2**expo; 0.0 <= frac < 1.0 */
assert(expo > 0);
ndig = (expo-1) / PyLong_SHIFT + 1; /* Number of 'digits' in result */
- v = _PyLong_New(ndig);
+ v = long_alloc(ndig);
if (v == NULL)
return NULL;
frac = ldexp(frac, (expo-1) % PyLong_SHIFT + 1);
return NULL;
}
ndigits = (numsignificantbytes * 8 + PyLong_SHIFT - 1) / PyLong_SHIFT;
- v = _PyLong_New(ndigits);
+ v = long_alloc(ndigits);
if (v == NULL)
return NULL;
}
/* Construct output value. */
- v = _PyLong_New(ndigits);
+ v = long_alloc(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
_PyLong_SetSignAndDigitCount(v, ival < 0 ? -1 : 1, ndigits);
++ndigits;
t >>= PyLong_SHIFT;
}
- v = _PyLong_New(ndigits);
+ v = long_alloc(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
_PyLong_SetSignAndDigitCount(v, negative ? -1 : 1, ndigits);
PyLongObject *z;
assert(n > 0 && n <= PyLong_MASK);
- z = _PyLong_New(size);
+ z = long_alloc(size);
if (z == NULL)
return NULL;
*prem = inplace_divrem1(z->long_value.ob_digit, a->long_value.ob_digit, size, n);
(10 * PyLong_SHIFT - 33 * _PyLong_DECIMAL_SHIFT);
assert(size_a < PY_SSIZE_T_MAX/2);
size = 1 + size_a + size_a / d;
- scratch = _PyLong_New(size);
+ scratch = long_alloc(size);
if (scratch == NULL)
return -1;
return 0;
}
n = (digits * bits_per_char + PyLong_SHIFT - 1) / PyLong_SHIFT;
- z = _PyLong_New(n);
+ z = long_alloc(n);
if (z == NULL) {
*res = NULL;
return 0;
*/
double fsize_z = (double)digits * log_base_BASE[base] + 1.0;
if (fsize_z > (double)MAX_LONG_DIGITS) {
- /* The same exception as in _PyLong_New(). */
+ /* The same exception as in long_alloc(). */
PyErr_SetString(PyExc_OverflowError,
"too many digits in integer");
*res = NULL;
/* Uncomment next line to test exceedingly rare copy code */
/* size_z = 1; */
assert(size_z > 0);
- z = _PyLong_New(size_z);
+ z = long_alloc(size_z);
if (z == NULL) {
*res = NULL;
return 0;
PyLongObject *tmp;
/* Extremely rare. Get more space. */
assert(_PyLong_DigitCount(z) == size_z);
- tmp = _PyLong_New(size_z + 1);
+ tmp = long_alloc(size_z + 1);
if (tmp == NULL) {
Py_DECREF(z);
*res = NULL;
size_v = _PyLong_DigitCount(v1);
size_w = _PyLong_DigitCount(w1);
assert(size_v >= size_w && size_w >= 2); /* Assert checks by div() */
- v = _PyLong_New(size_v+1);
+ v = long_alloc(size_v+1);
if (v == NULL) {
*prem = NULL;
return NULL;
}
- w = _PyLong_New(size_w);
+ w = long_alloc(size_w);
if (w == NULL) {
Py_DECREF(v);
*prem = NULL;
at most (and usually exactly) k = size_v - size_w digits. */
k = size_v - size_w;
assert(k >= 0);
- a = _PyLong_New(k);
+ a = long_alloc(k);
if (a == NULL) {
Py_DECREF(w);
Py_DECREF(v);
size_a = size_b;
size_b = size_temp; }
}
- z = _PyLong_New(size_a+1);
+ z = long_alloc(size_a+1);
if (z == NULL)
return NULL;
for (i = 0; i < size_b; ++i) {
}
size_a = size_b = i+1;
}
- z = _PyLong_New(size_a);
+ z = long_alloc(size_a);
if (z == NULL)
return NULL;
for (i = 0; i < size_b; ++i) {
Py_ssize_t size_b = _PyLong_DigitCount(b);
Py_ssize_t i;
- z = _PyLong_New(size_a + size_b);
+ z = long_alloc(size_a + size_b);
if (z == NULL)
return NULL;
size_lo = Py_MIN(size_n, size);
size_hi = size_n - size_lo;
- if ((hi = _PyLong_New(size_hi)) == NULL)
+ if ((hi = long_alloc(size_hi)) == NULL)
return -1;
- if ((lo = _PyLong_New(size_lo)) == NULL) {
+ if ((lo = long_alloc(size_lo)) == NULL) {
Py_DECREF(hi);
return -1;
}
*/
/* 1. Allocate result space. */
- ret = _PyLong_New(asize + bsize);
+ ret = long_alloc(asize + bsize);
if (ret == NULL) goto fail;
#ifdef Py_DEBUG
/* Fill with trash, to catch reference to uninitialized digits. */
assert(2 * asize <= bsize);
/* Allocate result space, and zero it out. */
- ret = _PyLong_New(asize + bsize);
+ ret = long_alloc(asize + bsize);
if (ret == NULL)
return NULL;
memset(ret->long_value.ob_digit, 0, _PyLong_DigitCount(ret) * sizeof(digit));
/* Successive slices of b are copied into bslice. */
- bslice = _PyLong_New(asize);
+ bslice = long_alloc(asize);
if (bslice == NULL)
goto fail;
"intermediate overflow during division");
goto error;
}
- x = _PyLong_New(a_size + shift_digits + 1);
+ x = long_alloc(a_size + shift_digits + 1);
if (x == NULL)
goto error;
for (i = 0; i < shift_digits; i++)
digit rem;
/* x = a >> shift */
assert(a_size >= shift_digits);
- x = _PyLong_New(a_size - shift_digits);
+ x = long_alloc(a_size - shift_digits);
if (x == NULL)
goto error;
rem = v_rshift(x->long_value.ob_digit, a->long_value.ob_digit + shift_digits,
/* Shifting all the bits of 'a' out gives either -1 or 0. */
return PyLong_FromLong(-a_negative);
}
- z = _PyLong_New(newsize);
+ z = long_alloc(newsize);
if (z == NULL) {
return NULL;
}
newsize = oldsize + wordshift;
if (remshift)
++newsize;
- z = _PyLong_New(newsize);
+ z = long_alloc(newsize);
if (z == NULL)
return NULL;
if (_PyLong_IsNegative(a)) {
size_a = _PyLong_DigitCount(a);
nega = _PyLong_IsNegative(a);
if (nega) {
- z = _PyLong_New(size_a);
+ z = long_alloc(size_a);
if (z == NULL)
return NULL;
v_complement(z->long_value.ob_digit, a->long_value.ob_digit, size_a);
size_b = _PyLong_DigitCount(b);
negb = _PyLong_IsNegative(b);
if (negb) {
- z = _PyLong_New(size_b);
+ z = long_alloc(size_b);
if (z == NULL) {
Py_DECREF(a);
return NULL;
/* We allow an extra digit if z is negative, to make sure that
the final two's complement of z doesn't overflow. */
- z = _PyLong_New(size_z + negz);
+ z = long_alloc(size_z + negz);
if (z == NULL) {
Py_DECREF(a);
Py_DECREF(b);
}
else {
alloc_a = size_a;
- c = _PyLong_New(size_a);
+ c = long_alloc(size_a);
if (c == NULL)
goto error;
}
}
else {
alloc_b = size_a;
- d = _PyLong_New(size_a);
+ d = long_alloc(size_a);
if (d == NULL)
goto error;
}
}
assert(digits != NULL);
- PyLongObject *obj = _PyLong_New(ndigits);
+ PyLongObject *obj = long_alloc(ndigits);
if (obj == NULL) {
goto error;
}