Message95956
Here is a way to test for overflow which is correct for any C implementation:
static PyObject *
int_add(PyIntObject *v, PyIntObject *w)
{
register long a, b;
CONVERT_TO_LONG(v, a);
CONVERT_TO_LONG(w, b);
if (((a>0)&&(b>0)&&((LONG_MAX-a)<b))
||((a<0)&&(b<0)&&((LONG_MIN-a)>b))) {
/* would overflow the long type */
return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
}
return PyInt_FromLong(a+b);
} |
|
Date |
User |
Action |
Args |
2009-12-04 05:22:05 | zooko | set | recipients:
+ zooko, mark.dickinson, eric.smith |
2009-12-04 05:22:04 | zooko | set | messageid: <1259904124.88.0.924866320967.issue7406@psf.upfronthosting.co.za> |
2009-12-04 05:22:02 | zooko | link | issue7406 messages |
2009-12-04 05:22:02 | zooko | create | |
|