PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
#endif /* !Py_LIMITED_API */
+#ifndef Py_LIMITED_API
+PyAPI_DATA(PyObject *) _PyLong_Zero;
+PyAPI_DATA(PyObject *) _PyLong_One;
+#endif
+
#ifdef __cplusplus
}
#endif
PyObject *it, *iterable, *mapping, *oldval;
PyObject *newval = NULL;
PyObject *key = NULL;
- PyObject *zero = NULL;
- PyObject *one = NULL;
PyObject *bound_get = NULL;
PyObject *mapping_get;
PyObject *dict_get;
if (it == NULL)
return NULL;
- one = PyLong_FromLong(1);
- if (one == NULL)
- goto done;
-
/* Only take the fast path when get() and __setitem__()
* have not been overridden.
*/
if (oldval == NULL) {
if (PyErr_Occurred())
goto done;
- if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0)
+ if (_PyDict_SetItem_KnownHash(mapping, key, _PyLong_One, hash) < 0)
goto done;
} else {
- newval = PyNumber_Add(oldval, one);
+ newval = PyNumber_Add(oldval, _PyLong_One);
if (newval == NULL)
goto done;
if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0)
if (bound_get == NULL)
goto done;
- zero = PyLong_FromLong(0);
- if (zero == NULL)
- goto done;
-
while (1) {
key = PyIter_Next(it);
if (key == NULL)
break;
- oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL);
+ oldval = PyObject_CallFunctionObjArgs(bound_get, key, _PyLong_Zero, NULL);
if (oldval == NULL)
break;
- newval = PyNumber_Add(oldval, one);
+ newval = PyNumber_Add(oldval, _PyLong_One);
Py_DECREF(oldval);
if (newval == NULL)
break;
Py_XDECREF(key);
Py_XDECREF(newval);
Py_XDECREF(bound_get);
- Py_XDECREF(zero);
- Py_XDECREF(one);
if (PyErr_Occurred())
return NULL;
Py_RETURN_NONE;
case PARAMFLAG_FIN | PARAMFLAG_FLCID:
/* ['in', 'lcid'] parameter. Always taken from defval,
if given, else the integer 0. */
- if (defval == NULL) {
- defval = PyLong_FromLong(0);
- if (defval == NULL)
- goto error;
- } else
- Py_INCREF(defval);
+ if (defval == NULL)
+ defval = _PyLong_Zero;
+ Py_INCREF(defval);
PyTuple_SET_ITEM(callargs, i, defval);
break;
case (PARAMFLAG_FIN | PARAMFLAG_FOUT):
*/
/* Conversion factors. */
-static PyObject *one = NULL; /* 1 */
static PyObject *us_per_ms = NULL; /* 1000 */
static PyObject *us_per_second = NULL; /* 1000000 */
static PyObject *us_per_minute = NULL; /* 1e6 * 60 as Python int */
goto Done
if (us) {
- y = accum("microseconds", x, us, one, &leftover_us);
+ y = accum("microseconds", x, us, _PyLong_One, &leftover_us);
CLEANUP;
}
if (ms) {
* is odd. Note that x is odd when it's last bit is 1. The
* code below uses bitwise and operation to check the last
* bit. */
- temp = PyNumber_And(x, one); /* temp <- x & 1 */
+ temp = PyNumber_And(x, _PyLong_One); /* temp <- x & 1 */
if (temp == NULL) {
Py_DECREF(x);
goto Done;
Py_BUILD_ASSERT(DI100Y == 25 * DI4Y - 1);
assert(DI100Y == days_before_year(100+1));
- one = PyLong_FromLong(1);
us_per_ms = PyLong_FromLong(1000);
us_per_second = PyLong_FromLong(1000000);
us_per_minute = PyLong_FromLong(60000000);
seconds_per_day = PyLong_FromLong(24 * 3600);
- if (one == NULL || us_per_ms == NULL || us_per_second == NULL ||
+ if (us_per_ms == NULL || us_per_second == NULL ||
us_per_minute == NULL || seconds_per_day == NULL)
return NULL;
PyObject *y;
PyObject *compare;
PyObject *answer;
- static PyObject *zero;
PyObject* stack[2];
- if (zero == NULL) {
- zero = PyLong_FromLong(0);
- if (!zero)
- return NULL;
- }
-
if (Py_TYPE(other) != &keyobject_type){
PyErr_Format(PyExc_TypeError, "other argument must be K instance");
return NULL;
return NULL;
}
- answer = PyObject_RichCompare(res, zero, op);
+ answer = PyObject_RichCompare(res, _PyLong_Zero, op);
Py_DECREF(res);
return answer;
}
PyObject *_PyIO_empty_str;
PyObject *_PyIO_empty_bytes;
-PyObject *_PyIO_zero;
PyDoc_STRVAR(module_doc,
"The io module provides the Python interfaces to stream handling. The\n"
if (!_PyIO_empty_bytes &&
!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
goto fail;
- if (!_PyIO_zero &&
- !(_PyIO_zero = PyLong_FromLong(0L)))
- goto fail;
state->initialized = 1;
extern PyObject *_PyIO_empty_str;
extern PyObject *_PyIO_empty_bytes;
-extern PyObject *_PyIO_zero;
extern PyTypeObject _PyBytesIOBuffer_Type;
if (cookieObj == NULL)
goto error;
- cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
+ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
Py_DECREF(cookieObj);
if (cmp < 0) {
goto error;
if (cmp == 0) {
self->encoding_start_of_stream = 0;
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
- _PyIO_zero, NULL);
+ _PyLong_Zero, NULL);
if (res == NULL)
goto error;
Py_DECREF(res);
}
else {
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
- _PyIO_zero, NULL);
+ _PyLong_Zero, NULL);
self->encoding_start_of_stream = 0;
}
if (res == NULL)
if (whence == 1) {
/* seek relative to current position */
- cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
+ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
if (cmp < 0)
goto fail;
}
else if (whence == 2) {
/* seek relative to end of file */
- cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
+ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
if (cmp < 0)
goto fail;
goto fail;
if (self->encoder) {
/* If seek() == 0, we are at the start of stream, otherwise not */
- cmp = PyObject_RichCompareBool(res, _PyIO_zero, Py_EQ);
+ cmp = PyObject_RichCompareBool(res, _PyLong_Zero, Py_EQ);
if (cmp < 0 || _textiowrapper_encoder_reset(self, cmp)) {
Py_DECREF(res);
goto fail;
goto fail;
}
- cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_LT);
+ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_LT);
if (cmp < 0)
goto fail;
switch (size) {
case 0:
- result = match_getslice(self, Py_False, Py_None);
+ result = match_getslice(self, _PyLong_Zero, Py_None);
break;
case 1:
result = match_getslice(self, PyTuple_GET_ITEM(args, 0), Py_None);
fast_mode = 0;
}
}
- Py_INCREF(long_cnt);
} else {
cnt = 0;
- long_cnt = PyLong_FromLong(0);
- if (long_cnt == NULL) {
- return NULL;
- }
+ long_cnt = _PyLong_Zero;
}
+ Py_INCREF(long_cnt);
/* If not specified, step defaults to 1 */
- if (long_step == NULL) {
- long_step = PyLong_FromLong(1);
- if (long_step == NULL) {
- Py_DECREF(long_cnt);
- return NULL;
- }
- } else
- Py_INCREF(long_step);
+ if (long_step == NULL)
+ long_step = _PyLong_One;
+ Py_INCREF(long_step);
assert(long_cnt != NULL && long_step != NULL);
/*[clinic input]
@classmethod
complex.__new__ as complex_new
- real as r: object(c_default="Py_False") = 0
+ real as r: object(c_default="_PyLong_Zero") = 0
imag as i: object(c_default="NULL") = 0
Create a complex number from a real part and an optional imaginary part.
static PyObject *
enum_next_long(enumobject *en, PyObject* next_item)
{
- static PyObject *one = NULL;
PyObject *result = en->en_result;
PyObject *next_index;
PyObject *stepped_up;
if (en->en_longindex == NULL)
return NULL;
}
- if (one == NULL) {
- one = PyLong_FromLong(1);
- if (one == NULL)
- return NULL;
- }
next_index = en->en_longindex;
assert(next_index != NULL);
- stepped_up = PyNumber_Add(next_index, one);
+ stepped_up = PyNumber_Add(next_index, _PyLong_One);
if (stepped_up == NULL)
return NULL;
en->en_longindex = stepped_up;
double fracpart;
double intpart;
PyObject *result = NULL;
- PyObject *one = NULL;
PyObject *vv = NULL;
PyObject *ww = w;
*/
PyObject *temp;
- one = PyLong_FromLong(1);
- if (one == NULL)
- goto Error;
-
- temp = PyNumber_Lshift(ww, one);
+ temp = PyNumber_Lshift(ww, _PyLong_One);
if (temp == NULL)
goto Error;
Py_DECREF(ww);
ww = temp;
- temp = PyNumber_Lshift(vv, one);
+ temp = PyNumber_Lshift(vv, _PyLong_One);
if (temp == NULL)
goto Error;
Py_DECREF(vv);
vv = temp;
- temp = PyNumber_Or(vv, one);
+ temp = PyNumber_Or(vv, _PyLong_One);
if (temp == NULL)
goto Error;
Py_DECREF(vv);
Error:
Py_XDECREF(vv);
Py_XDECREF(ww);
- Py_XDECREF(one);
return result;
}
} /* else if (PyLong_Check(w)) */
/*[clinic input]
@classmethod
float.__new__ as float_new
- x: object(c_default="Py_False") = 0
+ x: object(c_default="_PyLong_Zero") = 0
/
Convert a string or number to a floating point number, if possible.
(Py_SIZE(x) == 0 ? (sdigit)0 : \
(sdigit)(x)->ob_digit[0]))
+PyObject *_PyLong_Zero = NULL;
+PyObject *_PyLong_One = NULL;
+
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* Small integers are preallocated in this array so that they
can be shared.
(size_a == size_b &&
a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) {
/* |a| < |b|. */
- *pdiv = (PyLongObject*)PyLong_FromLong(0);
- if (*pdiv == NULL)
- return -1;
*prem = (PyLongObject *)long_long((PyObject *)a);
if (*prem == NULL) {
- Py_CLEAR(*pdiv);
return -1;
}
+ Py_INCREF(_PyLong_Zero);
+ *pdiv = (PyLongObject*)_PyLong_Zero;
return 0;
}
if (size_b == 1) {
if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) ||
(Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
PyLongObject *temp;
- PyLongObject *one;
temp = (PyLongObject *) long_add(mod, w);
Py_DECREF(mod);
mod = temp;
Py_DECREF(div);
return -1;
}
- one = (PyLongObject *) PyLong_FromLong(1L);
- if (one == NULL ||
- (temp = (PyLongObject *) long_sub(div, one)) == NULL) {
+ temp = (PyLongObject *) long_sub(div, (PyLongObject *)_PyLong_One);
+ if (temp == NULL) {
Py_DECREF(mod);
Py_DECREF(div);
- Py_XDECREF(one);
return -1;
}
- Py_DECREF(one);
Py_DECREF(div);
div = temp;
}
{
/* Implement ~x as -(x+1) */
PyLongObject *x;
- PyLongObject *w;
if (Py_ABS(Py_SIZE(v)) <=1)
return PyLong_FromLong(-(MEDIUM_VALUE(v)+1));
- w = (PyLongObject *)PyLong_FromLong(1L);
- if (w == NULL)
- return NULL;
- x = (PyLongObject *) long_add(v, w);
- Py_DECREF(w);
+ x = (PyLongObject *) long_add(v, (PyLongObject *)_PyLong_One);
if (x == NULL)
return NULL;
_PyLong_Negate(&x);
_PyLong_DivmodNear(PyObject *a, PyObject *b)
{
PyLongObject *quo = NULL, *rem = NULL;
- PyObject *one = NULL, *twice_rem, *result, *temp;
+ PyObject *twice_rem, *result, *temp;
int cmp, quo_is_odd, quo_is_neg;
/* Equivalent Python code:
/* Do a and b have different signs? If so, quotient is negative. */
quo_is_neg = (Py_SIZE(a) < 0) != (Py_SIZE(b) < 0);
- one = PyLong_FromLong(1L);
- if (one == NULL)
- return NULL;
-
if (long_divrem((PyLongObject*)a, (PyLongObject*)b, &quo, &rem) < 0)
goto error;
/* compare twice the remainder with the divisor, to see
if we need to adjust the quotient and remainder */
- twice_rem = long_lshift((PyObject *)rem, one);
+ twice_rem = long_lshift((PyObject *)rem, _PyLong_One);
if (twice_rem == NULL)
goto error;
if (quo_is_neg) {
if ((Py_SIZE(b) < 0 ? cmp < 0 : cmp > 0) || (cmp == 0 && quo_is_odd)) {
/* fix up quotient */
if (quo_is_neg)
- temp = long_sub(quo, (PyLongObject *)one);
+ temp = long_sub(quo, (PyLongObject *)_PyLong_One);
else
- temp = long_add(quo, (PyLongObject *)one);
+ temp = long_add(quo, (PyLongObject *)_PyLong_One);
Py_DECREF(quo);
quo = (PyLongObject *)temp;
if (quo == NULL)
/* PyTuple_SET_ITEM steals references */
PyTuple_SET_ITEM(result, 0, (PyObject *)quo);
PyTuple_SET_ITEM(result, 1, (PyObject *)rem);
- Py_DECREF(one);
return result;
error:
Py_XDECREF(quo);
Py_XDECREF(rem);
- Py_XDECREF(one);
return NULL;
}
v->ob_digit[0] = (digit)abs(ival);
}
#endif
+ _PyLong_Zero = PyLong_FromLong(0);
+ if (_PyLong_Zero == NULL)
+ return 0;
+ _PyLong_One = PyLong_FromLong(1);
+ if (_PyLong_One == NULL)
+ return 0;
+
/* initialize int_info */
if (Int_InfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0)
/* Integers are currently statically allocated. Py_DECREF is not
needed, but Python must forget about the reference or multiple
reinitializations will fail. */
+ Py_CLEAR(_PyLong_One);
+ Py_CLEAR(_PyLong_Zero);
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
int i;
PyLongObject *v = small_ints;
stop = PyNumber_Index(stop);
if (!stop)
return NULL;
- start = PyLong_FromLong(0);
- if (!start) {
- Py_DECREF(stop);
- return NULL;
- }
- step = PyLong_FromLong(1);
- if (!step) {
- Py_DECREF(stop);
- Py_DECREF(start);
- return NULL;
- }
+ Py_INCREF(_PyLong_Zero);
+ start = _PyLong_Zero;
+ Py_INCREF(_PyLong_One);
+ step = _PyLong_One;
}
else {
if (!PyArg_UnpackTuple(args, "range", 2, 3,
int cmp_result;
PyObject *lo, *hi;
PyObject *diff = NULL;
- PyObject *one = NULL;
PyObject *tmp1 = NULL, *tmp2 = NULL, *result;
/* holds sub-expression evaluations */
- PyObject *zero = PyLong_FromLong(0);
- if (zero == NULL)
- return NULL;
- cmp_result = PyObject_RichCompareBool(step, zero, Py_GT);
- Py_DECREF(zero);
+ cmp_result = PyObject_RichCompareBool(step, _PyLong_Zero, Py_GT);
if (cmp_result == -1)
return NULL;
return PyLong_FromLong(0);
}
- if ((one = PyLong_FromLong(1L)) == NULL)
- goto Fail;
-
if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL)
goto Fail;
- if ((diff = PyNumber_Subtract(tmp1, one)) == NULL)
+ if ((diff = PyNumber_Subtract(tmp1, _PyLong_One)) == NULL)
goto Fail;
if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL)
goto Fail;
- if ((result = PyNumber_Add(tmp2, one)) == NULL)
+ if ((result = PyNumber_Add(tmp2, _PyLong_One)) == NULL)
goto Fail;
Py_DECREF(tmp2);
Py_DECREF(diff);
Py_DECREF(step);
Py_DECREF(tmp1);
- Py_DECREF(one);
return result;
Fail:
Py_XDECREF(tmp2);
Py_XDECREF(diff);
Py_XDECREF(tmp1);
- Py_XDECREF(one);
return NULL;
}
int cmp_result;
PyObject *i, *result;
- PyObject *zero = PyLong_FromLong(0);
- if (zero == NULL)
- return NULL;
-
/* PyLong equivalent to:
* if (arg < 0) {
* i = r->length + arg
* i = arg
* }
*/
- cmp_result = PyObject_RichCompareBool(arg, zero, Py_LT);
+ cmp_result = PyObject_RichCompareBool(arg, _PyLong_Zero, Py_LT);
if (cmp_result == -1) {
- Py_DECREF(zero);
return NULL;
}
if (cmp_result == 1) {
- i = PyNumber_Add(r->length, arg);
- if (!i) {
- Py_DECREF(zero);
- return NULL;
- }
+ i = PyNumber_Add(r->length, arg);
+ if (!i) {
+ return NULL;
+ }
} else {
- i = arg;
- Py_INCREF(i);
+ i = arg;
+ Py_INCREF(i);
}
/* PyLong equivalent to:
* <report index out of bounds>
* }
*/
- cmp_result = PyObject_RichCompareBool(i, zero, Py_LT);
- Py_DECREF(zero);
+ cmp_result = PyObject_RichCompareBool(i, _PyLong_Zero, Py_LT);
if (cmp_result == 0) {
cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE);
}
int cmp1, cmp2, cmp3;
PyObject *tmp1 = NULL;
PyObject *tmp2 = NULL;
- PyObject *zero = NULL;
int result = -1;
- zero = PyLong_FromLong(0);
- if (zero == NULL) /* MemoryError in int(0) */
- goto end;
-
/* Check if the value can possibly be in the range. */
- cmp1 = PyObject_RichCompareBool(r->step, zero, Py_GT);
+ cmp1 = PyObject_RichCompareBool(r->step, _PyLong_Zero, Py_GT);
if (cmp1 == -1)
goto end;
if (cmp1 == 1) { /* positive steps: start <= ob < stop */
if (tmp2 == NULL)
goto end;
/* result = ((int(ob) - start) % step) == 0 */
- result = PyObject_RichCompareBool(tmp2, zero, Py_EQ);
+ result = PyObject_RichCompareBool(tmp2, _PyLong_Zero, Py_EQ);
end:
Py_XDECREF(tmp1);
Py_XDECREF(tmp2);
- Py_XDECREF(zero);
return result;
}
range_equals(rangeobject *r0, rangeobject *r1)
{
int cmp_result;
- PyObject *one;
if (r0 == r1)
return 1;
/* Return False or error to the caller. */
if (cmp_result != 1)
return cmp_result;
- one = PyLong_FromLong(1);
- if (!one)
- return -1;
- cmp_result = PyObject_RichCompareBool(r0->length, one, Py_EQ);
- Py_DECREF(one);
+ cmp_result = PyObject_RichCompareBool(r0->length, _PyLong_One, Py_EQ);
/* Return True or error to the caller. */
if (cmp_result != 0)
return cmp_result;
PyTuple_SET_ITEM(t, 2, Py_None);
}
else {
- PyObject *one;
Py_INCREF(r->start);
PyTuple_SET_ITEM(t, 1, r->start);
- one = PyLong_FromLong(1);
- if (!one)
- goto end;
- cmp_result = PyObject_RichCompareBool(r->length, one, Py_EQ);
- Py_DECREF(one);
+ cmp_result = PyObject_RichCompareBool(r->length, _PyLong_One, Py_EQ);
if (cmp_result == -1)
goto end;
if (cmp_result == 1) {
int result = range_contains_long(r, ob);
if (result == -1)
return NULL;
- else if (result)
- return PyLong_FromLong(1);
- else
- return PyLong_FromLong(0);
+ return PyLong_FromLong(result);
} else {
Py_ssize_t count;
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);
int cmp;
/* clip the value */
- PyObject *zero = PyLong_FromLong(0);
- if (zero == NULL)
+ cmp = PyObject_RichCompareBool(state, _PyLong_Zero, Py_LT);
+ if (cmp < 0)
return NULL;
- cmp = PyObject_RichCompareBool(state, zero, Py_LT);
if (cmp > 0) {
- Py_XSETREF(r->index, zero);
- Py_RETURN_NONE;
+ state = _PyLong_Zero;
+ }
+ else {
+ cmp = PyObject_RichCompareBool(r->len, state, Py_LT);
+ if (cmp < 0)
+ return NULL;
+ if (cmp > 0)
+ state = r->len;
}
- Py_DECREF(zero);
- if (cmp < 0)
- return NULL;
-
- cmp = PyObject_RichCompareBool(r->len, state, Py_LT);
- if (cmp < 0)
- return NULL;
- if (cmp > 0)
- state = r->len;
-
Py_INCREF(state);
Py_XSETREF(r->index, state);
Py_RETURN_NONE;
static PyObject *
longrangeiter_next(longrangeiterobject *r)
{
- PyObject *one, *product, *new_index, *result;
+ PyObject *product, *new_index, *result;
if (PyObject_RichCompareBool(r->index, r->len, Py_LT) != 1)
return NULL;
- one = PyLong_FromLong(1);
- if (!one)
- return NULL;
-
- new_index = PyNumber_Add(r->index, one);
- Py_DECREF(one);
+ new_index = PyNumber_Add(r->index, _PyLong_One);
if (!new_index)
return NULL;
if (it == NULL)
return NULL;
- /* Do all initialization here, so we can DECREF on failure. */
it->start = r->start;
it->step = r->step;
it->len = r->length;
+ it->index = _PyLong_Zero;
Py_INCREF(it->start);
Py_INCREF(it->step);
Py_INCREF(it->len);
-
- it->index = PyLong_FromLong(0);
- if (!it->index)
- goto create_failure;
-
+ Py_INCREF(it->index);
return (PyObject *)it;
-
-create_failure:
- Py_DECREF(it);
- return NULL;
}
static PyObject *
{
rangeobject *range = (rangeobject*) seq;
longrangeiterobject *it;
- PyObject *one, *sum, *diff, *product;
+ PyObject *sum, *diff, *product;
long lstart, lstop, lstep, new_start, new_stop;
unsigned long ulen;
it->len = range->length;
Py_INCREF(it->len);
- one = PyLong_FromLong(1);
- if (!one)
- goto create_failure;
-
- diff = PyNumber_Subtract(it->len, one);
- Py_DECREF(one);
+ diff = PyNumber_Subtract(it->len, _PyLong_One);
if (!diff)
goto create_failure;
if (!it->step)
goto create_failure;
- it->index = PyLong_FromLong(0);
- if (!it->index)
- goto create_failure;
-
+ it->index = _PyLong_Zero;
+ Py_INCREF(it->index);
return (PyObject *)it;
create_failure:
/* Convert step to an integer; raise for zero step. */
if (self->step == Py_None) {
- step = PyLong_FromLong(1L);
- if (step == NULL)
- goto error;
+ step = _PyLong_One;
+ Py_INCREF(step);
step_is_negative = 0;
}
else {
goto error;
}
else {
- lower = PyLong_FromLong(0L);
- if (lower == NULL)
- goto error;
-
+ lower = _PyLong_Zero;
+ Py_INCREF(lower);
upper = length;
Py_INCREF(upper);
}
update_registry(PyObject *registry, PyObject *text, PyObject *category,
int add_zero)
{
- PyObject *altkey, *zero = NULL;
+ PyObject *altkey;
int rc;
- if (add_zero) {
- zero = PyLong_FromLong(0);
- if (zero == NULL)
- return -1;
- altkey = PyTuple_Pack(3, text, category, zero);
- }
+ if (add_zero)
+ altkey = PyTuple_Pack(3, text, category, _PyLong_Zero);
else
altkey = PyTuple_Pack(2, text, category);
rc = already_warned(registry, altkey, 1);
- Py_XDECREF(zero);
Py_XDECREF(altkey);
return rc;
}
static PyObject *default_str = NULL;
static PyObject *always_str = NULL;
PyObject *action_obj = NULL;
- PyObject *lineno, *result;
if (!strcmp(action, "ignore")) {
if (ignore_str == NULL) {
}
/* This assumes the line number is zero for now. */
- lineno = PyLong_FromLong(0);
- if (lineno == NULL)
- return NULL;
- result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);
- Py_DECREF(lineno);
- return result;
+ return PyTuple_Pack(5, action_obj, Py_None, category, Py_None, _PyLong_Zero);
}
static PyObject *
if (u->u_ste->ste_needs_class_closure) {
/* Cook up an implicit __class__ cell. */
_Py_IDENTIFIER(__class__);
- PyObject *tuple, *name, *zero;
+ PyObject *tuple, *name;
int res;
assert(u->u_scope_type == COMPILER_SCOPE_CLASS);
assert(PyDict_GET_SIZE(u->u_cellvars) == 0);
compiler_unit_free(u);
return 0;
}
- zero = PyLong_FromLong(0);
- if (!zero) {
- Py_DECREF(tuple);
- compiler_unit_free(u);
- return 0;
- }
- res = PyDict_SetItem(u->u_cellvars, tuple, zero);
+ res = PyDict_SetItem(u->u_cellvars, tuple, _PyLong_Zero);
Py_DECREF(tuple);
- Py_DECREF(zero);
if (res < 0) {
compiler_unit_free(u);
return 0;
for (i = 0; i < n; i++) {
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
int r;
- PyObject *level;
- level = PyLong_FromLong(0);
- if (level == NULL)
- return 0;
-
- ADDOP_O(c, LOAD_CONST, level, consts);
- Py_DECREF(level);
+ ADDOP_O(c, LOAD_CONST, _PyLong_Zero, consts);
ADDOP_O(c, LOAD_CONST, Py_None, consts);
ADDOP_NAME(c, IMPORT_NAME, alias->name, names);