![](https://secure.gravatar.com/avatar/8b97b5aad24c30e4a1357b38cc39aeaa.jpg?s=120&d=mm&r=g)
Jan. 3, 2010
8:11 a.m.
Case Vanhorsen, 20.12.2009 01:38:
When I ported gmpy (Python to GMP multiple precision library) to Python 3.x, I began to use PyLong_AsLongAndOverflow frequently. I found the code to slightly faster and cleaner than using PyLong_AsLong and checking for overflow.
You might want to look at the code Cython generates for integer type conversions. We use specialised coercion code that gets generated on-the-fly to convert Python long/int from and to all sorts of C integer types with compile time (portability) and runtime size/value checks. Depending on your needs, this may or may not be faster than the above C-API function. Stefan