Skip to content

Commit 5a60764

Browse files
committed
[compat] numpy 1.x and 2.x compatibility macros try 3
1 parent f9c9757 commit 5a60764

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/decoder.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
/* NumPy 1.x/2.x compatibility macros */
3131
/******************************************************************************/
3232

33-
#include <numpy/npy_common.h>
34-
35-
#if NPY_ABI_VERSION < 0x02000000
33+
/* Check for NumPy 2.x using NPY_ABI_VERSION if available, otherwise assume 1.x */
34+
#if defined(NPY_ABI_VERSION) && NPY_ABI_VERSION >= 0x02000000
35+
/* NumPy 2.x: macros are provided by NumPy headers */
36+
#else
37+
/* NumPy 1.x: define compatibility macros */
3638
#define PyDataType_ELSIZE(d) ((d)->elsize)
3739
#define PyDataType_TYPE_NUM(d) ((d)->type_num)
3840
#endif

src/encoder.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
/* NumPy 1.x/2.x compatibility macros */
3232
/******************************************************************************/
3333

34-
#include <numpy/npy_common.h>
35-
36-
#if NPY_ABI_VERSION < 0x02000000
34+
/* Check for NumPy 2.x using NPY_ABI_VERSION if available, otherwise assume 1.x */
35+
#if defined(NPY_ABI_VERSION) && NPY_ABI_VERSION >= 0x02000000
36+
/* NumPy 2.x: macros are provided by NumPy headers */
37+
#else
38+
/* NumPy 1.x: define compatibility macros */
3739
#define PyDataType_ELSIZE(d) ((d)->elsize)
3840
#define PyDataType_TYPE_NUM(d) ((d)->type_num)
3941
#endif

0 commit comments

Comments
 (0)