mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
This commit is contained in:
parent
0fbab7ff8d
commit
d1a1d1ed80
15 changed files with 134 additions and 54 deletions
|
@ -1623,10 +1623,14 @@ builtin_sum(PyObject *self, PyObject *args)
|
|||
Assumes all inputs are the same type. If the assumption fails, default
|
||||
to the more general routine.
|
||||
*/
|
||||
if (PyInt_CheckExact(result)) {
|
||||
long i_result = PyLong_AS_LONG(result);
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
if (PyLong_CheckExact(result)) {
|
||||
int overflow;
|
||||
long i_result = PyLong_AsLongAndOverflow(result, &overflow);
|
||||
/* If this already overflowed, don't even enter the loop. */
|
||||
if (overflow == 0) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
}
|
||||
while(result == NULL) {
|
||||
item = PyIter_Next(iter);
|
||||
if (item == NULL) {
|
||||
|
@ -1635,10 +1639,10 @@ builtin_sum(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
return PyLong_FromLong(i_result);
|
||||
}
|
||||
if (PyInt_CheckExact(item)) {
|
||||
long b = PyLong_AS_LONG(item);
|
||||
if (PyLong_CheckExact(item)) {
|
||||
long b = PyLong_AsLongAndOverflow(item, &overflow);
|
||||
long x = i_result + b;
|
||||
if ((x^i_result) >= 0 || (x^b) >= 0) {
|
||||
if (overflow == 0 && ((x^i_result) >= 0 || (x^b) >= 0)) {
|
||||
i_result = x;
|
||||
Py_DECREF(item);
|
||||
continue;
|
||||
|
@ -1676,12 +1680,17 @@ builtin_sum(PyObject *self, PyObject *args)
|
|||
Py_DECREF(item);
|
||||
continue;
|
||||
}
|
||||
if (PyInt_CheckExact(item)) {
|
||||
PyFPE_START_PROTECT("add", return 0)
|
||||
f_result += (double)PyLong_AS_LONG(item);
|
||||
PyFPE_END_PROTECT(f_result)
|
||||
Py_DECREF(item);
|
||||
continue;
|
||||
if (PyLong_CheckExact(item)) {
|
||||
long value;
|
||||
int overflow;
|
||||
value = PyLong_AsLongAndOverflow(item, &overflow);
|
||||
if (!overflow) {
|
||||
PyFPE_START_PROTECT("add", return 0)
|
||||
f_result += (double)value;
|
||||
PyFPE_END_PROTECT(f_result)
|
||||
Py_DECREF(item);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result = PyFloat_FromDouble(f_result);
|
||||
temp = PyNumber_Add(result, item);
|
||||
|
|
|
@ -3711,14 +3711,7 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
|
|||
{
|
||||
if (v != NULL) {
|
||||
Py_ssize_t x;
|
||||
if (PyInt_CheckExact(v)) {
|
||||
/* XXX(nnorwitz): I think PyLong_AS_LONG is correct,
|
||||
however, it looks like it should be AsSsize_t.
|
||||
There should be a comment here explaining why.
|
||||
*/
|
||||
x = PyLong_AS_LONG(v);
|
||||
}
|
||||
else if (PyIndex_Check(v)) {
|
||||
if (PyIndex_Check(v)) {
|
||||
x = PyNumber_AsSsize_t(v, NULL);
|
||||
if (x == -1 && PyErr_Occurred())
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue