Skip to content

Commit

Permalink
Don't support NumPy 2 on pre-3.9 Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickJadoul committed Jul 17, 2024
1 parent 06ed2b5 commit 4f80db4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pybind11/include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
# error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included.
#endif

#if !defined(PYBIND11_NUMPY_1_ONLY) & PY_VERSION_HEX < 0x03090000
# define PYBIND11_NUMPY_1_ONLY
#endif

#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
Expand Down Expand Up @@ -85,6 +89,7 @@ struct PyArrayDescr_Proxy {
using PyArrayDescr_Proxy = PyArrayDescr1_Proxy;
#endif

#ifndef PYBIND11_NUMPY_1_ONLY
/* NumPy 2 proxy, including legacy fields */
struct PyArrayDescr2_Proxy {
PyObject_HEAD
Expand All @@ -105,6 +110,7 @@ struct PyArrayDescr2_Proxy {
PyObject *fields;
PyObject *names;
};
#endif

struct PyArray_Proxy {
PyObject_HEAD
Expand Down Expand Up @@ -359,9 +365,11 @@ inline const PyArrayDescr1_Proxy *array_descriptor1_proxy(const PyObject *ptr) {
return reinterpret_cast<const PyArrayDescr1_Proxy *>(ptr);
}

#ifndef PYBIND11_NUMPY_1_ONLY
inline const PyArrayDescr2_Proxy *array_descriptor2_proxy(const PyObject *ptr) {
return reinterpret_cast<const PyArrayDescr2_Proxy *>(ptr);
}
#endif

inline bool check_flags(const void* ptr, int flag) {
return (flag == (array_proxy(ptr)->flags & flag));
Expand Down

0 comments on commit 4f80db4

Please sign in to comment.