summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-12-04 22:10:37 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-12-04 22:10:37 (GMT)
commitd1a1d1ed802187cd1a9a8a95ac5d758c7acffee6 (patch)
tree17489e6ea4df32ba3b3bbda6e4b31155a460f265 /Python
parent0fbab7ff8d2efd92e222fcc13c0aff0998c3c158 (diff)
downloadcpython-d1a1d1ed802187cd1a9a8a95ac5d758c7acffee6.zip
cpython-d1a1d1ed802187cd1a9a8a95ac5d758c7acffee6.tar.gz
cpython-d1a1d1ed802187cd1a9a8a95ac5d758c7acffee6.tar.bz2
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c35
-rw-r--r--Python/ceval.c9
2 files changed, 23 insertions, 21 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index b57083b..56ec738 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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);
diff --git a/Python/ceval.c b/Python/ceval.c
index 9aa83c7..813f6f6 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;