Zooko O'Whielacronx <zo...@zooko.com> added the comment: 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); } ---------- nosy: +zooko _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7406> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com