8000 MAINT: restore Npy__PyLong_AsInt · numpy/numpy@dfa6beb · GitHub
[go: up one dir, main page]

Skip to content

Commit dfa6beb

Browse files
committed
MAINT: restore Npy__PyLong_AsInt
1 parent 64cffe1 commit dfa6beb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

numpy/_core/include/numpy/npy_3kcompat.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
4040

4141
#endif /* _MSC_VER >= 1900 */
4242

43+
/* Python13 removes _PyLong_AsInt */
44+
static inline int
45+
Npy__PyLong_AsInt(PyObject *obj)
46+
{
47+
int overflow;
48+
long result = PyLong_AsLongAndOverflow(obj, &overflow);
49+
50+
/* INT_MAX and INT_MIN are defined in Python.h */
51+
if (overflow || result > INT_MAX || result < INT_MIN) {
52+
/* XXX: could be cute and give a different
53+
* message for overflow == -1 */
54+
PyErr_SetString(PyExc_OverflowError,
55+
"Python int too large to convert to C int");
56+
return -1;
57+
}
58+
return (int)result;
59+
}
60+
61+
4362

4463
/*
4564
* PyFile_* compatibility

numpy/f2py/cfuncs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,13 +878,13 @@
878878
PyObject* tmp = NULL;
879879
880880
if (PyLong_Check(obj)) {
881-
*v = _PyLong_AsInt(obj);
881+
*v = Npy__PyLong_AsInt(obj);
882882
return !(*v == -1 && PyErr_Occurred());
883883
}
884884
885885
tmp = PyNumber_Long(obj);
886886
if (tmp) {
887-
*v = _PyLong_AsInt(tmp);
887+
*v = Npy__PyLong_AsInt(tmp);
888888
Py_DECREF(tmp);
889889
return !(*v == -1 && PyErr_Occurred());
890890
}

0 commit comments

Comments
 (0)
0