* This is a renamed copy of the Python non-limited API function _PyLong_AsInt. It is * included here because it is missing from the PyPy API. It completes the PyLong_As* * group of functions and can be useful in replacing PyInt_Check. */
| 37 | * group of functions and can be useful in replacing PyInt_Check. |
| 38 | */ |
| 39 | static inline int |
| 40 | Npy__PyLong_AsInt(PyObject *obj) |
| 41 | { |
| 42 | int overflow; |
| 43 | long result = PyLong_AsLongAndOverflow(obj, &overflow); |
| 44 | |
| 45 | /* INT_MAX and INT_MIN are defined in Python.h */ |
| 46 | if (overflow || result > INT_MAX || result < INT_MIN) { |
| 47 | /* XXX: could be cute and give a different |
| 48 | message for overflow == -1 */ |
| 49 | PyErr_SetString(PyExc_OverflowError, |
| 50 | "Python int too large to convert to C int"); |
| 51 | return -1; |
| 52 | } |
| 53 | return (int)result; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | #if defined(NPY_PY3K) |
nothing calls this directly
no outgoing calls
no test coverage detected