Skip to content

Commit bc25546

Browse files
committed
Fix struct definitions to match target api version
1 parent 2ccf1d0 commit bc25546

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/npyffi/objects.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(non_camel_case_types)]
55

66
use libc::FILE;
7+
use pyo3::ffi::vectorcallfunc;
78
use pyo3::ffi::*;
89
use std::os::raw::*;
910

@@ -21,6 +22,12 @@ pub struct PyArrayObject {
2122
pub descr: *mut PyArray_Descr,
2223
pub flags: c_int,
2324
pub weakreflist: *mut PyObject,
25+
26+
#[cfg(Numpy_1_20)]
27+
pub _buffer_info: *mut c_void,
28+
29+
#[cfg(Numpy_1_22)]
30+
pub mem_handler: *mut PyObject,
2431
}
2532

2633
#[repr(C)]
@@ -32,6 +39,19 @@ pub struct PyArray_Descr {
3239
pub byteorder: c_char,
3340
pub _former_flags: c_char,
3441
pub type_num: c_int,
42+
43+
#[cfg(Numpy_2_0)]
44+
pub flags: npy_uint64,
45+
#[cfg(Numpy_2_0)]
46+
pub elsize: npy_intp,
47+
#[cfg(Numpy_2_0)]
48+
pub alignment: npy_intp,
49+
#[cfg(Numpy_2_0)]
50+
pub metadata: *mut PyObject,
51+
#[cfg(Numpy_2_0)]
52+
pub hash: npy_hash_t,
53+
#[cfg(Numpy_2_0)]
54+
pub reserved_null: [*mut c_void; 2],
3555
}
3656

3757
#[repr(C)]
@@ -365,11 +385,31 @@ pub struct PyUFuncObject {
365385
pub core_offsets: *mut c_int,
366386
pub core_signature: *mut c_char,
367387
pub type_resolver: PyUFunc_TypeResolutionFunc,
368-
pub legacy_inner_loop_selector: PyUFunc_LegacyInnerLoopSelectionFunc,
369-
pub reserved2: *mut c_void,
370-
pub masked_inner_loop_selector: PyUFunc_MaskedInnerLoopSelectionFunc,
388+
pub dict: *mut PyObject,
389+
390+
#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
391+
pub vectorcall: Option<vectorcallfunc>,
392+
#[cfg(any(not(Py_3_8), Py_LIMITED_API))]
393+
pub vectorcall: *mut c_void,
394+
395+
pub reserved3: *mut c_void,
371396
pub op_flags: *mut npy_uint32,
372397
pub iter_flags: npy_uint32,
398+
399+
#[cfg(Numpy_1_16)]
400+
pub core_dim_sizes: *mut npy_intp,
401+
#[cfg(Numpy_1_16)]
402+
pub core_dim_flags: *mut npy_uint32,
403+
#[cfg(Numpy_1_16)]
404+
pub identity_value: *mut PyObject,
405+
406+
#[cfg(Numpy_1_22)]
407+
pub _dispatch_cache: *mut c_void,
408+
#[cfg(Numpy_1_22)]
409+
pub _loops: *mut PyObject,
410+
411+
#[cfg(Numpy_2_1)]
412+
pub process_core_dims_func: PyUFunc_ProcessCoreDimsFunc,
373413
}
374414

375415
pub type PyUFuncGenericFunction =
@@ -415,6 +455,9 @@ pub type PyUFunc_MaskedInnerLoopSelectionFunc = Option<
415455
) -> c_int,
416456
>;
417457

458+
pub type PyUFunc_ProcessCoreDimsFunc =
459+
Option<unsafe extern "C" fn(*mut PyUFuncObject, *mut npy_intp) -> c_int>;
460+
418461
#[repr(C)]
419462
#[derive(Debug, Copy, Clone)]
420463
pub struct NpyIter([u8; 0]);

src/npyffi/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ pub enum NPY_SELECTKIND {
154154
NPY_INTROSELECT = 0,
155155
}
156156

157+
#[cfg(Numpy_2_4)]
158+
pub const NPY_SAME_VALUE_CASTING_FLAG: u32 = 64;
159+
157160
#[repr(u32)]
158161
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
159162
pub enum NPY_CASTING {
@@ -162,6 +165,9 @@ pub enum NPY_CASTING {
162165
NPY_SAFE_CASTING = 2,
163166
NPY_SAME_KIND_CASTING = 3,
164167
NPY_UNSAFE_CASTING = 4,
168+
169+
#[cfg(Numpy_2_4)]
170+
NPY_SAME_VALUE_CASTING = Self::NPY_UNSAFE_CASTING as u32 | NPY_SAME_VALUE_CASTING_FLAG,
165171
}
166172

167173
#[repr(u32)]

0 commit comments

Comments
 (0)