2626#include "markers.h"
2727#include "encoder.h"
2828#include "python_funcs.h"
29-
30- /******************************************************************************/
31- /* NumPy 1.x/2.x compatibility macros */
32- /******************************************************************************/
33-
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 */
39- #define PyDataType_ELSIZE (d ) ((d)->elsize)
40- #define PyDataType_TYPE_NUM (d ) ((d)->type_num)
41- #endif
29+ #include "numpy_compat.h"
4230
4331/******************************************************************************/
4432
@@ -339,7 +327,7 @@ static inline int _is_string_type(int type_num) {
339327
340328/* Recursively check if a dtype is supported for SOA encoding */
341329static int _is_soa_compatible_dtype (PyArray_Descr * fd ) {
342- int type_num = PyDataType_TYPE_NUM (fd );
330+ int type_num = DESCR_TYPE_NUM (fd );
343331
344332 /* String types are supported */
345333 if (_is_string_type (type_num )) {
@@ -481,7 +469,7 @@ static int _encode_field_name(PyObject* name, _bjdata_encoder_buffer_t* buffer)
481469
482470/* Write schema for a field recursively (handles nested structs) */
483471static int _write_field_schema_recursive (PyArray_Descr * fd , _bjdata_encoder_buffer_t * buffer ) {
484- int type_num = PyDataType_TYPE_NUM (fd );
472+ int type_num = DESCR_TYPE_NUM (fd );
485473 Py_ssize_t i ;
486474
487475 /* Handle NPY_VOID: could be sub-array or nested struct */
@@ -501,7 +489,7 @@ static int _write_field_schema_recursive(PyArray_Descr* fd, _bjdata_encoder_buff
501489 }
502490 }
503491
504- int base_type = PyDataType_TYPE_NUM (base_dtype );
492+ int base_type = DESCR_TYPE_NUM (base_dtype );
505493 Py_DECREF (subdtype );
506494
507495 /* Write sub-array schema: [TTT...] */
@@ -589,7 +577,7 @@ static int _write_field_schema_recursive(PyArray_Descr* fd, _bjdata_encoder_buff
589577 /* String types - write NUMPY BYTE SIZE (not character count) */
590578 if (_is_string_type (type_num )) {
591579 WRITE_CHAR_OR_BAIL (TYPE_STRING );
592- BAIL_ON_NONZERO (_encode_longlong (PyDataType_ELSIZE (fd ), buffer ));
580+ BAIL_ON_NONZERO (_encode_longlong (DESCR_ELSIZE (fd ), buffer ));
593581 return 0 ;
594582 }
595583
@@ -929,9 +917,9 @@ static int _encode_soa(PyArrayObject* arr, _bjdata_encoder_buffer_t* buffer, int
929917
930918 PyArray_Descr * fd = (PyArray_Descr * )PyTuple_GET_ITEM (info , 0 );
931919 field_offset [i ] = PyLong_AsSsize_t (PyTuple_GET_ITEM (info , 1 ));
932- field_itemsize [i ] = PyDataType_ELSIZE (fd );
920+ field_itemsize [i ] = DESCR_ELSIZE (fd );
933921
934- int type_num = PyDataType_TYPE_NUM (fd );
922+ int type_num = DESCR_TYPE_NUM (fd );
935923
936924 if (type_num == NPY_BOOL ) {
937925 field_type [i ] = 1 ;
0 commit comments