Commit ba85d69a authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-29878: Add global instances of int for 0 and 1. (#852)

parent e6911a44
...@@ -209,6 +209,11 @@ PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int); ...@@ -209,6 +209,11 @@ PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
#endif /* !Py_LIMITED_API */ #endif /* !Py_LIMITED_API */
#ifndef Py_LIMITED_API
PyAPI_DATA(PyObject *) _PyLong_Zero;
PyAPI_DATA(PyObject *) _PyLong_One;
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -2267,8 +2267,6 @@ _count_elements(PyObject *self, PyObject *args) ...@@ -2267,8 +2267,6 @@ _count_elements(PyObject *self, PyObject *args)
PyObject *it, *iterable, *mapping, *oldval; PyObject *it, *iterable, *mapping, *oldval;
PyObject *newval = NULL; PyObject *newval = NULL;
PyObject *key = NULL; PyObject *key = NULL;
PyObject *zero = NULL;
PyObject *one = NULL;
PyObject *bound_get = NULL; PyObject *bound_get = NULL;
PyObject *mapping_get; PyObject *mapping_get;
PyObject *dict_get; PyObject *dict_get;
...@@ -2282,10 +2280,6 @@ _count_elements(PyObject *self, PyObject *args) ...@@ -2282,10 +2280,6 @@ _count_elements(PyObject *self, PyObject *args)
if (it == NULL) if (it == NULL)
return NULL; return NULL;
one = PyLong_FromLong(1);
if (one == NULL)
goto done;
/* Only take the fast path when get() and __setitem__() /* Only take the fast path when get() and __setitem__()
* have not been overridden. * have not been overridden.
*/ */
...@@ -2325,10 +2319,10 @@ _count_elements(PyObject *self, PyObject *args) ...@@ -2325,10 +2319,10 @@ _count_elements(PyObject *self, PyObject *args)
if (oldval == NULL) { if (oldval == NULL) {
if (PyErr_Occurred()) if (PyErr_Occurred())
goto done; goto done;
if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0) if (_PyDict_SetItem_KnownHash(mapping, key, _PyLong_One, hash) < 0)
goto done; goto done;
} else { } else {
newval = PyNumber_Add(oldval, one); newval = PyNumber_Add(oldval, _PyLong_One);
if (newval == NULL) if (newval == NULL)
goto done; goto done;
if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0) if (_PyDict_SetItem_KnownHash(mapping, key, newval, hash) < 0)
...@@ -2342,18 +2336,14 @@ _count_elements(PyObject *self, PyObject *args) ...@@ -2342,18 +2336,14 @@ _count_elements(PyObject *self, PyObject *args)
if (bound_get == NULL) if (bound_get == NULL)
goto done; goto done;
zero = PyLong_FromLong(0);
if (zero == NULL)
goto done;
while (1) { while (1) {
key = PyIter_Next(it); key = PyIter_Next(it);
if (key == NULL) if (key == NULL)
break; break;
oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL); oldval = PyObject_CallFunctionObjArgs(bound_get, key, _PyLong_Zero, NULL);
if (oldval == NULL) if (oldval == NULL)
break; break;
newval = PyNumber_Add(oldval, one); newval = PyNumber_Add(oldval, _PyLong_One);
Py_DECREF(oldval); Py_DECREF(oldval);
if (newval == NULL) if (newval == NULL)
break; break;
...@@ -2369,8 +2359,6 @@ done: ...@@ -2369,8 +2359,6 @@ done:
Py_XDECREF(key); Py_XDECREF(key);
Py_XDECREF(newval); Py_XDECREF(newval);
Py_XDECREF(bound_get); Py_XDECREF(bound_get);
Py_XDECREF(zero);
Py_XDECREF(one);
if (PyErr_Occurred()) if (PyErr_Occurred())
return NULL; return NULL;
Py_RETURN_NONE; Py_RETURN_NONE;
......
...@@ -3606,12 +3606,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, ...@@ -3606,12 +3606,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes,
case PARAMFLAG_FIN | PARAMFLAG_FLCID: case PARAMFLAG_FIN | PARAMFLAG_FLCID:
/* ['in', 'lcid'] parameter. Always taken from defval, /* ['in', 'lcid'] parameter. Always taken from defval,
if given, else the integer 0. */ if given, else the integer 0. */
if (defval == NULL) { if (defval == NULL)
defval = PyLong_FromLong(0); defval = _PyLong_Zero;
if (defval == NULL) Py_INCREF(defval);
goto error;
} else
Py_INCREF(defval);
PyTuple_SET_ITEM(callargs, i, defval); PyTuple_SET_ITEM(callargs, i, defval);
break; break;
case (PARAMFLAG_FIN | PARAMFLAG_FOUT): case (PARAMFLAG_FIN | PARAMFLAG_FOUT):
......
...@@ -1481,7 +1481,6 @@ cmperror(PyObject *a, PyObject *b) ...@@ -1481,7 +1481,6 @@ cmperror(PyObject *a, PyObject *b)
*/ */
/* Conversion factors. */ /* Conversion factors. */
static PyObject *one = NULL; /* 1 */
static PyObject *us_per_ms = NULL; /* 1000 */ static PyObject *us_per_ms = NULL; /* 1000 */
static PyObject *us_per_second = NULL; /* 1000000 */ static PyObject *us_per_second = NULL; /* 1000000 */
static PyObject *us_per_minute = NULL; /* 1e6 * 60 as Python int */ static PyObject *us_per_minute = NULL; /* 1e6 * 60 as Python int */
...@@ -2201,7 +2200,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw) ...@@ -2201,7 +2200,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
goto Done goto Done
if (us) { if (us) {
y = accum("microseconds", x, us, one, &leftover_us); y = accum("microseconds", x, us, _PyLong_One, &leftover_us);
CLEANUP; CLEANUP;
} }
if (ms) { if (ms) {
...@@ -2241,7 +2240,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw) ...@@ -2241,7 +2240,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
* is odd. Note that x is odd when it's last bit is 1. The * 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 * code below uses bitwise and operation to check the last
* bit. */ * bit. */
temp = PyNumber_And(x, one); /* temp <- x & 1 */ temp = PyNumber_And(x, _PyLong_One); /* temp <- x & 1 */
if (temp == NULL) { if (temp == NULL) {
Py_DECREF(x); Py_DECREF(x);
goto Done; goto Done;
...@@ -5839,12 +5838,11 @@ PyInit__datetime(void) ...@@ -5839,12 +5838,11 @@ PyInit__datetime(void)
Py_BUILD_ASSERT(DI100Y == 25 * DI4Y - 1); Py_BUILD_ASSERT(DI100Y == 25 * DI4Y - 1);
assert(DI100Y == days_before_year(100+1)); assert(DI100Y == days_before_year(100+1));
one = PyLong_FromLong(1);
us_per_ms = PyLong_FromLong(1000); us_per_ms = PyLong_FromLong(1000);
us_per_second = PyLong_FromLong(1000000); us_per_second = PyLong_FromLong(1000000);
us_per_minute = PyLong_FromLong(60000000); us_per_minute = PyLong_FromLong(60000000);
seconds_per_day = PyLong_FromLong(24 * 3600); 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) us_per_minute == NULL || seconds_per_day == NULL)
return NULL; return NULL;
......
...@@ -529,15 +529,8 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) ...@@ -529,15 +529,8 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
PyObject *y; PyObject *y;
PyObject *compare; PyObject *compare;
PyObject *answer; PyObject *answer;
static PyObject *zero;
PyObject* stack[2]; PyObject* stack[2];
if (zero == NULL) {
zero = PyLong_FromLong(0);
if (!zero)
return NULL;
}
if (Py_TYPE(other) != &keyobject_type){ if (Py_TYPE(other) != &keyobject_type){
PyErr_Format(PyExc_TypeError, "other argument must be K instance"); PyErr_Format(PyExc_TypeError, "other argument must be K instance");
return NULL; return NULL;
...@@ -561,7 +554,7 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) ...@@ -561,7 +554,7 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
return NULL; return NULL;
} }
answer = PyObject_RichCompare(res, zero, op); answer = PyObject_RichCompare(res, _PyLong_Zero, op);
Py_DECREF(res); Py_DECREF(res);
return answer; return answer;
} }
......
...@@ -53,7 +53,6 @@ PyObject *_PyIO_str_write; ...@@ -53,7 +53,6 @@ PyObject *_PyIO_str_write;
PyObject *_PyIO_empty_str; PyObject *_PyIO_empty_str;
PyObject *_PyIO_empty_bytes; PyObject *_PyIO_empty_bytes;
PyObject *_PyIO_zero;
PyDoc_STRVAR(module_doc, PyDoc_STRVAR(module_doc,
"The io module provides the Python interfaces to stream handling. The\n" "The io module provides the Python interfaces to stream handling. The\n"
...@@ -790,9 +789,6 @@ PyInit__io(void) ...@@ -790,9 +789,6 @@ PyInit__io(void)
if (!_PyIO_empty_bytes && if (!_PyIO_empty_bytes &&
!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0))) !(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
goto fail; goto fail;
if (!_PyIO_zero &&
!(_PyIO_zero = PyLong_FromLong(0L)))
goto fail;
state->initialized = 1; state->initialized = 1;
......
...@@ -183,6 +183,5 @@ extern PyObject *_PyIO_str_write; ...@@ -183,6 +183,5 @@ extern PyObject *_PyIO_str_write;
extern PyObject *_PyIO_empty_str; extern PyObject *_PyIO_empty_str;
extern PyObject *_PyIO_empty_bytes; extern PyObject *_PyIO_empty_bytes;
extern PyObject *_PyIO_zero;
extern PyTypeObject _PyBytesIOBuffer_Type; extern PyTypeObject _PyBytesIOBuffer_Type;
...@@ -1078,7 +1078,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, ...@@ -1078,7 +1078,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
if (cookieObj == NULL) if (cookieObj == NULL)
goto error; goto error;
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
Py_DECREF(cookieObj); Py_DECREF(cookieObj);
if (cmp < 0) { if (cmp < 0) {
goto error; goto error;
...@@ -1087,7 +1087,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, ...@@ -1087,7 +1087,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
if (cmp == 0) { if (cmp == 0) {
self->encoding_start_of_stream = 0; self->encoding_start_of_stream = 0;
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
_PyIO_zero, NULL); _PyLong_Zero, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
Py_DECREF(res); Py_DECREF(res);
...@@ -2030,7 +2030,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream) ...@@ -2030,7 +2030,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream)
} }
else { else {
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
_PyIO_zero, NULL); _PyLong_Zero, NULL);
self->encoding_start_of_stream = 0; self->encoding_start_of_stream = 0;
} }
if (res == NULL) if (res == NULL)
...@@ -2075,7 +2075,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) ...@@ -2075,7 +2075,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
if (whence == 1) { if (whence == 1) {
/* seek relative to current position */ /* seek relative to current position */
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
if (cmp < 0) if (cmp < 0)
goto fail; goto fail;
...@@ -2094,7 +2094,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) ...@@ -2094,7 +2094,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
} }
else if (whence == 2) { else if (whence == 2) {
/* seek relative to end of file */ /* 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) if (cmp < 0)
goto fail; goto fail;
...@@ -2123,7 +2123,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) ...@@ -2123,7 +2123,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail; goto fail;
if (self->encoder) { if (self->encoder) {
/* If seek() == 0, we are at the start of stream, otherwise not */ /* 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)) { if (cmp < 0 || _textiowrapper_encoder_reset(self, cmp)) {
Py_DECREF(res); Py_DECREF(res);
goto fail; goto fail;
...@@ -2137,7 +2137,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) ...@@ -2137,7 +2137,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail; goto fail;
} }
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_LT); cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_LT);
if (cmp < 0) if (cmp < 0)
goto fail; goto fail;
......
...@@ -2041,7 +2041,7 @@ match_group(MatchObject* self, PyObject* args) ...@@ -2041,7 +2041,7 @@ match_group(MatchObject* self, PyObject* args)
switch (size) { switch (size) {
case 0: case 0:
result = match_getslice(self, Py_False, Py_None); result = match_getslice(self, _PyLong_Zero, Py_None);
break; break;
case 1: case 1:
result = match_getslice(self, PyTuple_GET_ITEM(args, 0), Py_None); result = match_getslice(self, PyTuple_GET_ITEM(args, 0), Py_None);
......
...@@ -3965,24 +3965,16 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -3965,24 +3965,16 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
fast_mode = 0; fast_mode = 0;
} }
} }
Py_INCREF(long_cnt);
} else { } else {
cnt = 0; cnt = 0;
long_cnt = PyLong_FromLong(0); long_cnt = _PyLong_Zero;
if (long_cnt == NULL) {
return NULL;
}
} }
Py_INCREF(long_cnt);
/* If not specified, step defaults to 1 */ /* If not specified, step defaults to 1 */
if (long_step == NULL) { if (long_step == NULL)
long_step = PyLong_FromLong(1); long_step = _PyLong_One;
if (long_step == NULL) { Py_INCREF(long_step);
Py_DECREF(long_cnt);
return NULL;
}
} else
Py_INCREF(long_step);
assert(long_cnt != NULL && long_step != NULL); assert(long_cnt != NULL && long_step != NULL);
......
...@@ -936,7 +936,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) ...@@ -936,7 +936,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
/*[clinic input] /*[clinic input]
@classmethod @classmethod
complex.__new__ as complex_new 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 imag as i: object(c_default="NULL") = 0
Create a complex number from a real part and an optional imaginary part. Create a complex number from a real part and an optional imaginary part.
......
...@@ -100,7 +100,6 @@ enum_traverse(enumobject *en, visitproc visit, void *arg) ...@@ -100,7 +100,6 @@ enum_traverse(enumobject *en, visitproc visit, void *arg)
static PyObject * static PyObject *
enum_next_long(enumobject *en, PyObject* next_item) enum_next_long(enumobject *en, PyObject* next_item)
{ {
static PyObject *one = NULL;
PyObject *result = en->en_result; PyObject *result = en->en_result;
PyObject *next_index; PyObject *next_index;
PyObject *stepped_up; PyObject *stepped_up;
...@@ -110,14 +109,9 @@ enum_next_long(enumobject *en, PyObject* next_item) ...@@ -110,14 +109,9 @@ enum_next_long(enumobject *en, PyObject* next_item)
if (en->en_longindex == NULL) if (en->en_longindex == NULL)
return NULL; return NULL;
} }
if (one == NULL) {
one = PyLong_FromLong(1);
if (one == NULL)
return NULL;
}
next_index = en->en_longindex; next_index = en->en_longindex;
assert(next_index != NULL); assert(next_index != NULL);
stepped_up = PyNumber_Add(next_index, one); stepped_up = PyNumber_Add(next_index, _PyLong_One);
if (stepped_up == NULL) if (stepped_up == NULL)
return NULL; return NULL;
en->en_longindex = stepped_up; en->en_longindex = stepped_up;
......
...@@ -443,7 +443,6 @@ float_richcompare(PyObject *v, PyObject *w, int op) ...@@ -443,7 +443,6 @@ float_richcompare(PyObject *v, PyObject *w, int op)
double fracpart; double fracpart;
double intpart; double intpart;
PyObject *result = NULL; PyObject *result = NULL;
PyObject *one = NULL;
PyObject *vv = NULL; PyObject *vv = NULL;
PyObject *ww = w; PyObject *ww = w;
...@@ -466,23 +465,19 @@ float_richcompare(PyObject *v, PyObject *w, int op) ...@@ -466,23 +465,19 @@ float_richcompare(PyObject *v, PyObject *w, int op)
*/ */
PyObject *temp; PyObject *temp;
one = PyLong_FromLong(1); temp = PyNumber_Lshift(ww, _PyLong_One);
if (one == NULL)
goto Error;
temp = PyNumber_Lshift(ww, one);
if (temp == NULL) if (temp == NULL)
goto Error; goto Error;
Py_DECREF(ww); Py_DECREF(ww);
ww = temp; ww = temp;
temp = PyNumber_Lshift(vv, one); temp = PyNumber_Lshift(vv, _PyLong_One);
if (temp == NULL) if (temp == NULL)
goto Error; goto Error;
Py_DECREF(vv); Py_DECREF(vv);
vv = temp; vv = temp;
temp = PyNumber_Or(vv, one); temp = PyNumber_Or(vv, _PyLong_One);
if (temp == NULL) if (temp == NULL)
goto Error; goto Error;
Py_DECREF(vv); Py_DECREF(vv);
...@@ -496,7 +491,6 @@ float_richcompare(PyObject *v, PyObject *w, int op) ...@@ -496,7 +491,6 @@ float_richcompare(PyObject *v, PyObject *w, int op)
Error: Error:
Py_XDECREF(vv); Py_XDECREF(vv);
Py_XDECREF(ww); Py_XDECREF(ww);
Py_XDECREF(one);
return result; return result;
} }
} /* else if (PyLong_Check(w)) */ } /* else if (PyLong_Check(w)) */
...@@ -1617,7 +1611,7 @@ float_subtype_new(PyTypeObject *type, PyObject *x); ...@@ -1617,7 +1611,7 @@ float_subtype_new(PyTypeObject *type, PyObject *x);
/*[clinic input] /*[clinic input]
@classmethod @classmethod
float.__new__ as float_new 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. Convert a string or number to a floating point number, if possible.
......
...@@ -31,6 +31,9 @@ _Py_IDENTIFIER(big); ...@@ -31,6 +31,9 @@ _Py_IDENTIFIER(big);
(Py_SIZE(x) == 0 ? (sdigit)0 : \ (Py_SIZE(x) == 0 ? (sdigit)0 : \
(sdigit)(x)->ob_digit[0])) (sdigit)(x)->ob_digit[0]))
PyObject *_PyLong_Zero = NULL;
PyObject *_PyLong_One = NULL;
#if NSMALLNEGINTS + NSMALLPOSINTS > 0 #if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* Small integers are preallocated in this array so that they /* Small integers are preallocated in this array so that they
can be shared. can be shared.
...@@ -2551,14 +2554,12 @@ long_divrem(PyLongObject *a, PyLongObject *b, ...@@ -2551,14 +2554,12 @@ long_divrem(PyLongObject *a, PyLongObject *b,
(size_a == size_b && (size_a == size_b &&
a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) { a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) {
/* |a| < |b|. */ /* |a| < |b|. */
*pdiv = (PyLongObject*)PyLong_FromLong(0);
if (*pdiv == NULL)
return -1;
*prem = (PyLongObject *)long_long((PyObject *)a); *prem = (PyLongObject *)long_long((PyObject *)a);
if (*prem == NULL) { if (*prem == NULL) {
Py_CLEAR(*pdiv);
return -1; return -1;
} }
Py_INCREF(_PyLong_Zero);
*pdiv = (PyLongObject*)_PyLong_Zero;
return 0; return 0;
} }
if (size_b == 1) { if (size_b == 1) {
...@@ -3695,7 +3696,6 @@ l_divmod(PyLongObject *v, PyLongObject *w, ...@@ -3695,7 +3696,6 @@ l_divmod(PyLongObject *v, PyLongObject *w,
if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) || if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) ||
(Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) { (Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
PyLongObject *temp; PyLongObject *temp;
PyLongObject *one;
temp = (PyLongObject *) long_add(mod, w); temp = (PyLongObject *) long_add(mod, w);
Py_DECREF(mod); Py_DECREF(mod);
mod = temp; mod = temp;
...@@ -3703,15 +3703,12 @@ l_divmod(PyLongObject *v, PyLongObject *w, ...@@ -3703,15 +3703,12 @@ l_divmod(PyLongObject *v, PyLongObject *w,
Py_DECREF(div); Py_DECREF(div);
return -1; return -1;
} }
one = (PyLongObject *) PyLong_FromLong(1L); temp = (PyLongObject *) long_sub(div, (PyLongObject *)_PyLong_One);
if (one == NULL || if (temp == NULL) {
(temp = (PyLongObject *) long_sub(div, one)) == NULL) {
Py_DECREF(mod); Py_DECREF(mod);
Py_DECREF(div); Py_DECREF(div);
Py_XDECREF(one);
return -1; return -1;
} }
Py_DECREF(one);
Py_DECREF(div); Py_DECREF(div);
div = temp; div = temp;
} }
...@@ -4242,14 +4239,9 @@ long_invert(PyLongObject *v) ...@@ -4242,14 +4239,9 @@ long_invert(PyLongObject *v)
{ {
/* Implement ~x as -(x+1) */ /* Implement ~x as -(x+1) */
PyLongObject *x; PyLongObject *x;
PyLongObject *w;
if (Py_ABS(Py_SIZE(v)) <=1) if (Py_ABS(Py_SIZE(v)) <=1)
return PyLong_FromLong(-(MEDIUM_VALUE(v)+1)); return PyLong_FromLong(-(MEDIUM_VALUE(v)+1));
w = (PyLongObject *)PyLong_FromLong(1L); x = (PyLongObject *) long_add(v, (PyLongObject *)_PyLong_One);
if (w == NULL)
return NULL;
x = (PyLongObject *) long_add(v, w);
Py_DECREF(w);
if (x == NULL) if (x == NULL)
return NULL; return NULL;
_PyLong_Negate(&x); _PyLong_Negate(&x);
...@@ -4932,7 +4924,7 @@ PyObject * ...@@ -4932,7 +4924,7 @@ PyObject *
_PyLong_DivmodNear(PyObject *a, PyObject *b) _PyLong_DivmodNear(PyObject *a, PyObject *b)
{ {
PyLongObject *quo = NULL, *rem = NULL; 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; int cmp, quo_is_odd, quo_is_neg;
/* Equivalent Python code: /* Equivalent Python code:
...@@ -4959,16 +4951,12 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b) ...@@ -4959,16 +4951,12 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
/* Do a and b have different signs? If so, quotient is negative. */ /* Do a and b have different signs? If so, quotient is negative. */
quo_is_neg = (Py_SIZE(a) < 0) != (Py_SIZE(b) < 0); 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) if (long_divrem((PyLongObject*)a, (PyLongObject*)b, &quo, &rem) < 0)
goto error; goto error;
/* compare twice the remainder with the divisor, to see /* compare twice the remainder with the divisor, to see
if we need to adjust the quotient and remainder */ 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) if (twice_rem == NULL)
goto error; goto error;
if (quo_is_neg) { if (quo_is_neg) {
...@@ -4985,9 +4973,9 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b) ...@@ -4985,9 +4973,9 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
if ((Py_SIZE(b) < 0 ? cmp < 0 : cmp > 0) || (cmp == 0 && quo_is_odd)) { if ((Py_SIZE(b) < 0 ? cmp < 0 : cmp > 0) || (cmp == 0 && quo_is_odd)) {
/* fix up quotient */ /* fix up quotient */
if (quo_is_neg) if (quo_is_neg)
temp = long_sub(quo, (PyLongObject *)one); temp = long_sub(quo, (PyLongObject *)_PyLong_One);
else else
temp = long_add(quo, (PyLongObject *)one); temp = long_add(quo, (PyLongObject *)_PyLong_One);
Py_DECREF(quo); Py_DECREF(quo);
quo = (PyLongObject *)temp; quo = (PyLongObject *)temp;
if (quo == NULL) if (quo == NULL)
...@@ -5010,13 +4998,11 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b) ...@@ -5010,13 +4998,11 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
/* PyTuple_SET_ITEM steals references */ /* PyTuple_SET_ITEM steals references */
PyTuple_SET_ITEM(result, 0, (PyObject *)quo); PyTuple_SET_ITEM(result, 0, (PyObject *)quo);
PyTuple_SET_ITEM(result, 1, (PyObject *)rem); PyTuple_SET_ITEM(result, 1, (PyObject *)rem);
Py_DECREF(one);
return result; return result;
error: error:
Py_XDECREF(quo); Py_XDECREF(quo);
Py_XDECREF(rem); Py_XDECREF(rem);
Py_XDECREF(one);
return NULL; return NULL;
} }
...@@ -5505,6 +5491,13 @@ _PyLong_Init(void) ...@@ -5505,6 +5491,13 @@ _PyLong_Init(void)
v->ob_digit[0] = (digit)abs(ival); v->ob_digit[0] = (digit)abs(ival);
} }
#endif #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 */ /* initialize int_info */
if (Int_InfoType.tp_name == NULL) { if (Int_InfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0)
...@@ -5520,6 +5513,8 @@ PyLong_Fini(void) ...@@ -5520,6 +5513,8 @@ PyLong_Fini(void)
/* Integers are currently statically allocated. Py_DECREF is not /* Integers are currently statically allocated. Py_DECREF is not
needed, but Python must forget about the reference or multiple needed, but Python must forget about the reference or multiple
reinitializations will fail. */ reinitializations will fail. */
Py_CLEAR(_PyLong_One);
Py_CLEAR(_PyLong_Zero);
#if NSMALLNEGINTS + NSMALLPOSINTS > 0 #if NSMALLNEGINTS + NSMALLPOSINTS > 0
int i; int i;
PyLongObject *v = small_ints; PyLongObject *v = small_ints;
......
...@@ -83,17 +83,10 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw) ...@@ -83,17 +83,10 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
stop = PyNumber_Index(stop); stop = PyNumber_Index(stop);
if (!stop) if (!stop)
return NULL; return NULL;
start = PyLong_FromLong(0); Py_INCREF(_PyLong_Zero);
if (!start) { start = _PyLong_Zero;
Py_DECREF(stop); Py_INCREF(_PyLong_One);
return NULL; step = _PyLong_One;
}
step = PyLong_FromLong(1);
if (!step) {
Py_DECREF(stop);
Py_DECREF(start);
return NULL;
}
} }
else { else {
if (!PyArg_UnpackTuple(args, "range", 2, 3, if (!PyArg_UnpackTuple(args, "range", 2, 3,
...@@ -162,15 +155,10 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step) ...@@ -162,15 +155,10 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
int cmp_result; int cmp_result;
PyObject *lo, *hi; PyObject *lo, *hi;
PyObject *diff = NULL; PyObject *diff = NULL;
PyObject *one = NULL;
PyObject *tmp1 = NULL, *tmp2 = NULL, *result; PyObject *tmp1 = NULL, *tmp2 = NULL, *result;
/* holds sub-expression evaluations */ /* holds sub-expression evaluations */
PyObject *zero = PyLong_FromLong(0); cmp_result = PyObject_RichCompareBool(step, _PyLong_Zero, Py_GT);
if (zero == NULL)
return NULL;
cmp_result = PyObject_RichCompareBool(step, zero, Py_GT);
Py_DECREF(zero);
if (cmp_result == -1) if (cmp_result == -1)
return NULL; return NULL;
...@@ -195,26 +183,22 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step) ...@@ -195,26 +183,22 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
return PyLong_FromLong(0); return PyLong_FromLong(0);
} }
if ((one = PyLong_FromLong(1L)) == NULL)
goto Fail;
if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL) if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL)
goto Fail; goto Fail;
if ((diff = PyNumber_Subtract(tmp1, one)) == NULL) if ((diff = PyNumber_Subtract(tmp1, _PyLong_One)) == NULL)
goto Fail; goto Fail;
if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL) if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL)
goto Fail; goto Fail;
if ((result = PyNumber_Add(tmp2, one)) == NULL) if ((result = PyNumber_Add(tmp2, _PyLong_One)) == NULL)
goto Fail; goto Fail;
Py_DECREF(tmp2); Py_DECREF(tmp2);
Py_DECREF(diff); Py_DECREF(diff);
Py_DECREF(step); Py_DECREF(step);
Py_DECREF(tmp1); Py_DECREF(tmp1);
Py_DECREF(one);
return result; return result;
Fail: Fail:
...@@ -222,7 +206,6 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step) ...@@ -222,7 +206,6 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
Py_XDECREF(tmp2); Py_XDECREF(tmp2);
Py_XDECREF(diff); Py_XDECREF(diff);
Py_XDECREF(tmp1); Py_XDECREF(tmp1);
Py_XDECREF(one);
return NULL; return NULL;
} }
...@@ -253,10 +236,6 @@ compute_range_item(rangeobject *r, PyObject *arg) ...@@ -253,10 +236,6 @@ compute_range_item(rangeobject *r, PyObject *arg)
int cmp_result; int cmp_result;
PyObject *i, *result; PyObject *i, *result;
PyObject *zero = PyLong_FromLong(0);
if (zero == NULL)
return NULL;
/* PyLong equivalent to: /* PyLong equivalent to:
* if (arg < 0) { * if (arg < 0) {
* i = r->length + arg * i = r->length + arg
...@@ -264,20 +243,18 @@ compute_range_item(rangeobject *r, PyObject *arg) ...@@ -264,20 +243,18 @@ compute_range_item(rangeobject *r, PyObject *arg)
* i = arg * i = arg
* } * }
*/ */
cmp_result = PyObject_RichCompareBool(arg, zero, Py_LT); cmp_result = PyObject_RichCompareBool(arg, _PyLong_Zero, Py_LT);
if (cmp_result == -1) { if (cmp_result == -1) {
Py_DECREF(zero);
return NULL; return NULL;
} }
if (cmp_result == 1) { if (cmp_result == 1) {
i = PyNumber_Add(r->length, arg); i = PyNumber_Add(r->length, arg);
if (!i) { if (!i) {
Py_DECREF(zero); return NULL;
return NULL; }
}
} else { } else {
i = arg; i = arg;
Py_INCREF(i); Py_INCREF(i);
} }
/* PyLong equivalent to: /* PyLong equivalent to:
...@@ -285,8 +262,7 @@ compute_range_item(rangeobject *r, PyObject *arg) ...@@ -285,8 +262,7 @@ compute_range_item(rangeobject *r, PyObject *arg)
* <report index out of bounds> * <report index out of bounds>
* } * }
*/ */
cmp_result = PyObject_RichCompareBool(i, zero, Py_LT); cmp_result = PyObject_RichCompareBool(i, _PyLong_Zero, Py_LT);
Py_DECREF(zero);
if (cmp_result == 0) { if (cmp_result == 0) {
cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE); cmp_result = PyObject_RichCompareBool(i, r->length, Py_GE);
} }
...@@ -364,16 +340,11 @@ range_contains_long(rangeobject *r, PyObject *ob) ...@@ -364,16 +340,11 @@ range_contains_long(rangeobject *r, PyObject *ob)
int cmp1, cmp2, cmp3; int cmp1, cmp2, cmp3;
PyObject *tmp1 = NULL; PyObject *tmp1 = NULL;
PyObject *tmp2 = NULL; PyObject *tmp2 = NULL;
PyObject *zero = NULL;
int result = -1; 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. */ /* 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) if (cmp1 == -1)
goto end; goto end;
if (cmp1 == 1) { /* positive steps: start <= ob < stop */ if (cmp1 == 1) { /* positive steps: start <= ob < stop */
...@@ -400,11 +371,10 @@ range_contains_long(rangeobject *r, PyObject *ob) ...@@ -400,11 +371,10 @@ range_contains_long(rangeobject *r, PyObject *ob)
if (tmp2 == NULL) if (tmp2 == NULL)
goto end; goto end;
/* result = ((int(ob) - start) % step) == 0 */ /* result = ((int(ob) - start) % step) == 0 */
result = PyObject_RichCompareBool(tmp2, zero, Py_EQ); result = PyObject_RichCompareBool(tmp2, _PyLong_Zero, Py_EQ);
end: end:
Py_XDECREF(tmp1); Py_XDECREF(tmp1);
Py_XDECREF(tmp2); Py_XDECREF(tmp2);
Py_XDECREF(zero);
return result; return result;
} }
...@@ -437,7 +407,6 @@ static int ...@@ -437,7 +407,6 @@ static int
range_equals(rangeobject *r0, rangeobject *r1) range_equals(rangeobject *r0, rangeobject *r1)
{ {
int cmp_result; int cmp_result;
PyObject *one;
if (r0 == r1) if (r0 == r1)
return 1; return 1;
...@@ -453,11 +422,7 @@ range_equals(rangeobject *r0, rangeobject *r1) ...@@ -453,11 +422,7 @@ range_equals(rangeobject *r0, rangeobject *r1)
/* Return False or error to the caller. */ /* Return False or error to the caller. */
if (cmp_result != 1) if (cmp_result != 1)
return cmp_result; return cmp_result;
one = PyLong_FromLong(1); cmp_result = PyObject_RichCompareBool(r0->length, _PyLong_One, Py_EQ);
if (!one)
return -1;
cmp_result = PyObject_RichCompareBool(r0->length, one, Py_EQ);
Py_DECREF(one);
/* Return True or error to the caller. */ /* Return True or error to the caller. */
if (cmp_result != 0) if (cmp_result != 0)
return cmp_result; return cmp_result;
...@@ -524,14 +489,9 @@ range_hash(rangeobject *r) ...@@ -524,14 +489,9 @@ range_hash(rangeobject *r)
PyTuple_SET_ITEM(t, 2, Py_None); PyTuple_SET_ITEM(t, 2, Py_None);
} }
else { else {
PyObject *one;
Py_INCREF(r->start); Py_INCREF(r->start);
PyTuple_SET_ITEM(t, 1, r->start); PyTuple_SET_ITEM(t, 1, r->start);
one = PyLong_FromLong(1); cmp_result = PyObject_RichCompareBool(r->length, _PyLong_One, Py_EQ);
if (!one)
goto end;
cmp_result = PyObject_RichCompareBool(r->length, one, Py_EQ);
Py_DECREF(one);
if (cmp_result == -1) if (cmp_result == -1)
goto end; goto end;
if (cmp_result == 1) { if (cmp_result == 1) {
...@@ -556,10 +516,7 @@ range_count(rangeobject *r, PyObject *ob) ...@@ -556,10 +516,7 @@ range_count(rangeobject *r, PyObject *ob)
int result = range_contains_long(r, ob); int result = range_contains_long(r, ob);
if (result == -1) if (result == -1)
return NULL; return NULL;
else if (result) return PyLong_FromLong(result);
return PyLong_FromLong(1);
else
return PyLong_FromLong(0);
} else { } else {
Py_ssize_t count; Py_ssize_t count;
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT); count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);
...@@ -973,24 +930,19 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state) ...@@ -973,24 +930,19 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
int cmp; int cmp;
/* clip the value */ /* clip the value */
PyObject *zero = PyLong_FromLong(0); cmp = PyObject_RichCompareBool(state, _PyLong_Zero, Py_LT);
if (zero == NULL) if (cmp < 0)
return NULL; return NULL;
cmp = PyObject_RichCompareBool(state, zero, Py_LT);
if (cmp > 0) { if (cmp > 0) {
Py_XSETREF(r->index, zero); state = _PyLong_Zero;
Py_RETURN_NONE; }
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_INCREF(state);
Py_XSETREF(r->index, state); Py_XSETREF(r->index, state);
Py_RETURN_NONE; Py_RETURN_NONE;
...@@ -1019,16 +971,11 @@ longrangeiter_dealloc(longrangeiterobject *r) ...@@ -1019,16 +971,11 @@ longrangeiter_dealloc(longrangeiterobject *r)
static PyObject * static PyObject *
longrangeiter_next(longrangeiterobject *r) 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) if (PyObject_RichCompareBool(r->index, r->len, Py_LT) != 1)
return NULL; return NULL;
one = PyLong_FromLong(1); new_index = PyNumber_Add(r->index, _PyLong_One);
if (!one)
return NULL;
new_index = PyNumber_Add(r->index, one);
Py_DECREF(one);
if (!new_index) if (!new_index)
return NULL; return NULL;
...@@ -1122,23 +1069,15 @@ range_iter(PyObject *seq) ...@@ -1122,23 +1069,15 @@ range_iter(PyObject *seq)
if (it == NULL) if (it == NULL)
return NULL; return NULL;
/* Do all initialization here, so we can DECREF on failure. */
it->start = r->start; it->start = r->start;
it->step = r->step; it->step = r->step;
it->len = r->length; it->len = r->length;
it->index = _PyLong_Zero;
Py_INCREF(it->start); Py_INCREF(it->start);
Py_INCREF(it->step); Py_INCREF(it->step);
Py_INCREF(it->len); Py_INCREF(it->len);
Py_INCREF(it->index);
it->index = PyLong_FromLong(0);
if (!it->index)
goto create_failure;
return (PyObject *)it; return (PyObject *)it;
create_failure:
Py_DECREF(it);
return NULL;
} }
static PyObject * static PyObject *
...@@ -1146,7 +1085,7 @@ range_reverse(PyObject *seq) ...@@ -1146,7 +1085,7 @@ range_reverse(PyObject *seq)
{ {
rangeobject *range = (rangeobject*) seq; rangeobject *range = (rangeobject*) seq;
longrangeiterobject *it; longrangeiterobject *it;
PyObject *one, *sum, *diff, *product; PyObject *sum, *diff, *product;
long lstart, lstop, lstep, new_start, new_stop; long lstart, lstop, lstep, new_start, new_stop;
unsigned long ulen; unsigned long ulen;
...@@ -1220,12 +1159,7 @@ long_range: ...@@ -1220,12 +1159,7 @@ long_range:
it->len = range->length; it->len = range->length;
Py_INCREF(it->len); Py_INCREF(it->len);
one = PyLong_FromLong(1); diff = PyNumber_Subtract(it->len, _PyLong_One);
if (!one)
goto create_failure;
diff = PyNumber_Subtract(it->len, one);
Py_DECREF(one);
if (!diff) if (!diff)
goto create_failure; goto create_failure;
...@@ -1244,10 +1178,8 @@ long_range: ...@@ -1244,10 +1178,8 @@ long_range:
if (!it->step) if (!it->step)
goto create_failure; goto create_failure;
it->index = PyLong_FromLong(0); it->index = _PyLong_Zero;
if (!it->index) Py_INCREF(it->index);
goto create_failure;
return (PyObject *)it; return (PyObject *)it;
create_failure: create_failure:
......
...@@ -374,9 +374,8 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, ...@@ -374,9 +374,8 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
/* Convert step to an integer; raise for zero step. */ /* Convert step to an integer; raise for zero step. */
if (self->step == Py_None) { if (self->step == Py_None) {
step = PyLong_FromLong(1L); step = _PyLong_One;
if (step == NULL) Py_INCREF(step);
goto error;
step_is_negative = 0; step_is_negative = 0;
} }
else { else {
...@@ -404,10 +403,8 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, ...@@ -404,10 +403,8 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
goto error; goto error;
} }
else { else {
lower = PyLong_FromLong(0L); lower = _PyLong_Zero;
if (lower == NULL) Py_INCREF(lower);
goto error;
upper = length; upper = length;
Py_INCREF(upper); Py_INCREF(upper);
} }
......
...@@ -287,20 +287,15 @@ static int ...@@ -287,20 +287,15 @@ static int
update_registry(PyObject *registry, PyObject *text, PyObject *category, update_registry(PyObject *registry, PyObject *text, PyObject *category,
int add_zero) int add_zero)
{ {
PyObject *altkey, *zero = NULL; PyObject *altkey;
int rc; int rc;
if (add_zero) { if (add_zero)
zero = PyLong_FromLong(0); altkey = PyTuple_Pack(3, text, category, _PyLong_Zero);
if (zero == NULL)
return -1;
altkey = PyTuple_Pack(3, text, category, zero);
}
else else
altkey = PyTuple_Pack(2, text, category); altkey = PyTuple_Pack(2, text, category);
rc = already_warned(registry, altkey, 1); rc = already_warned(registry, altkey, 1);
Py_XDECREF(zero);
Py_XDECREF(altkey); Py_XDECREF(altkey);
return rc; return rc;
} }
...@@ -1130,7 +1125,6 @@ create_filter(PyObject *category, const char *action) ...@@ -1130,7 +1125,6 @@ create_filter(PyObject *category, const char *action)
static PyObject *default_str = NULL; static PyObject *default_str = NULL;
static PyObject *always_str = NULL; static PyObject *always_str = NULL;
PyObject *action_obj = NULL; PyObject *action_obj = NULL;
PyObject *lineno, *result;
if (!strcmp(action, "ignore")) { if (!strcmp(action, "ignore")) {
if (ignore_str == NULL) { if (ignore_str == NULL) {
...@@ -1169,12 +1163,7 @@ create_filter(PyObject *category, const char *action) ...@@ -1169,12 +1163,7 @@ create_filter(PyObject *category, const char *action)
} }
/* This assumes the line number is zero for now. */ /* This assumes the line number is zero for now. */
lineno = PyLong_FromLong(0); return PyTuple_Pack(5, action_obj, Py_None, category, Py_None, _PyLong_Zero);
if (lineno == NULL)
return NULL;
result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);
Py_DECREF(lineno);
return result;
} }
static PyObject * static PyObject *
......
...@@ -561,7 +561,7 @@ compiler_enter_scope(struct compiler *c, identifier name, ...@@ -561,7 +561,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
if (u->u_ste->ste_needs_class_closure) { if (u->u_ste->ste_needs_class_closure) {
/* Cook up an implicit __class__ cell. */ /* Cook up an implicit __class__ cell. */
_Py_IDENTIFIER(__class__); _Py_IDENTIFIER(__class__);
PyObject *tuple, *name, *zero; PyObject *tuple, *name;
int res; int res;
assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(u->u_scope_type == COMPILER_SCOPE_CLASS);
assert(PyDict_GET_SIZE(u->u_cellvars) == 0); assert(PyDict_GET_SIZE(u->u_cellvars) == 0);
...@@ -575,15 +575,8 @@ compiler_enter_scope(struct compiler *c, identifier name, ...@@ -575,15 +575,8 @@ compiler_enter_scope(struct compiler *c, identifier name,
compiler_unit_free(u); compiler_unit_free(u);
return 0; return 0;
} }
zero = PyLong_FromLong(0); res = PyDict_SetItem(u->u_cellvars, tuple, _PyLong_Zero);
if (!zero) {
Py_DECREF(tuple);
compiler_unit_free(u);
return 0;
}
res = PyDict_SetItem(u->u_cellvars, tuple, zero);
Py_DECREF(tuple); Py_DECREF(tuple);
Py_DECREF(zero);
if (res < 0) { if (res < 0) {
compiler_unit_free(u); compiler_unit_free(u);
return 0; return 0;
...@@ -2596,14 +2589,8 @@ compiler_import(struct compiler *c, stmt_ty s) ...@@ -2596,14 +2589,8 @@ compiler_import(struct compiler *c, stmt_ty s)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i); alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
int r; int r;
PyObject *level;
level = PyLong_FromLong(0); ADDOP_O(c, LOAD_CONST, _PyLong_Zero, consts);
if (level == NULL)
return 0;
ADDOP_O(c, LOAD_CONST, level, consts);
Py_DECREF(level);
ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP_O(c, LOAD_CONST, Py_None, consts);
ADDOP_NAME(c, IMPORT_NAME, alias->name, names); ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment