From: Mark Wooding Date: Wed, 3 May 2017 11:48:27 +0000 (+0100) Subject: Return `long' objects when `int' is requested but the value won't fit. X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/commitdiff_plain/418f92ba4381a52e6ab83142bbe64b8923261870 Return `long' objects when `int' is requested but the value won't fit. Mostly, Python handles the error from the `int' conversion and falls back to long, but there's something weird in iteration, where if you say for i in ...: print '%d' % x then the loop finishes and /then/ you get an exception for the overflow from the failed conversion of x to an `int'. Follow Python's actual behaviour: have `mp_tolong_checked' take an extra argument indicating whether to throw an exception, and modify most of the call sites to fall back to a conversion based on `mp_topylong'. --- diff --git a/catacomb-python.h b/catacomb-python.h index a379e1d..bed97d5 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -317,7 +317,7 @@ extern PyObject *gf_pywrap(mp *); extern mp *mp_frompyobject(PyObject *, int); extern PyObject *mp_topystring(mp *, int, const char *, const char *, const char *); -extern int mp_tolong_checked(mp *, long *); +extern int mp_tolong_checked(mp *, long *, int); /*----- Abstract fields ---------------------------------------------------*/