8000 BUILD: clean out py2 stuff from npy_3kcompat.h by mattip · Pull Request #26842 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUILD: clean out py2 stuff from npy_3kcompat.h #26842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MAINT: restore Npy__PyLong_AsInt
  • Loading branch information
mattip committed Jul 3, 2024
commit 5954b85950638a122bdc0662720627e1a35937e5
27 changes: 22 additions & 5 deletions numpy/_core/include/numpy/npy_3kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,32 @@
extern "C" {
#endif

/*
* Macros to protect CRT calls against instant termination when passed an
* invalid parameter (https://bugs.python.org/issue23524).
*/
/* Python13 removes _PyLong_AsInt */
static inline int
Npy__PyLong_AsInt(PyObject *obj)
{
int overflow;
long result = PyLong_AsLongAndOverflow(obj, &overflow);

/* INT_MAX and INT_MIN are defined in Python.h */
if (overflow || result > INT_MAX || result < INT_MIN) {
/* XXX: could be cute and give a different
message for overflow == -1 */
PyErr_SetString(PyExc_OverflowError,
"Python int too large to convert to C int");
return -1;
}
return (int)result;
}

#if defined _MSC_VER && _MSC_VER >= 1900

#include <stdlib.h>

/*
* Macros to protect CRT calls against instant termination when passed an
* invalid parameter (https://bugs.python.org/issue23524).
*/
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
#define NPY_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
Expand All @@ -40,7 +58,6 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;

#endif /* _MSC_VER >= 1900 */


/*
* PyFile_* compatibility
*/
Expand Down
4 changes: 2 additions & 2 deletions numpy/f2py/cfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,13 @@
PyObject* tmp = NULL;

if (PyLong_Check(obj)) {
*v = _PyLong_AsInt(obj);
*v = Npy__PyLong_AsInt(obj);
return !(*v == -1 && PyErr_Occurred());
}

tmp = PyNumber_Long(obj);
if (tmp) {
*v = _PyLong_AsInt(tmp);
*v = Npy__PyLong_AsInt(tmp);
Py_DECREF(tmp);
return !(*v == -1 && PyErr_Occurred());
}
Expand Down
Loading
0