diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 164977f7fc..6726d7e2b4 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -145,14 +145,17 @@ struct npy_api { NPY_UINT8_ = NPY_UBYTE_, NPY_INT16_ = NPY_SHORT_, NPY_UINT16_ = NPY_USHORT_, - NPY_INT32_ = platform_lookup({{ - NPY_SHORT_, NPY_INT_, NPY_LONG_}}), - NPY_UINT32_ = platform_lookup({{ - NPY_USHORT_, NPY_UINT_, NPY_ULONG_}}), - NPY_INT64_ = platform_lookup({{ - NPY_INT_, NPY_LONG_, NPY_LONGLONG_}}), - NPY_UINT64_ = platform_lookup({{ - NPY_UINT_, NPY_ULONG_, NPY_ULONGLONG_}}), + // `npy_common.h` defines the integer aliases. In order, it checks: + // NPY_BITSOF_LONG, NPY_BITSOF_LONGLONG, NPY_BITSOF_INT, NPY_BITSOF_SHORT, NPY_BITSOF_CHAR + // and assigns the alias to the first matching size, so we should check in this order. + NPY_INT32_ = platform_lookup({{ + NPY_LONG_, NPY_INT_, NPY_SHORT_}}), + NPY_UINT32_ = platform_lookup({{ + NPY_ULONG_, NPY_UINT_, NPY_USHORT_}}), + NPY_INT64_ = platform_lookup({{ + NPY_LONG_, NPY_LONGLONG_, NPY_INT_}}), + NPY_UINT64_ = platform_lookup({{ + NPY_ULONG_, NPY_ULONGLONG_, NPY_UINT_}}), }; typedef struct {