Skip to content

Commit 0a5dc24

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

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
@@ -21,6 +21,12 @@ pub struct PyArrayObject {
2121
pub descr: *mut PyArray_Descr,
2222
pub flags: c_int,
2323
pub weakreflist: *mut PyObject,
24+
25+
#[cfg(Numpy_1_20)]
26+
pub _buffer_info: *mut c_void,
27+
28+
#[cfg(Numpy_1_22)]
29+
pub mem_handler: *mut PyObject,
2430
}
2531

2632
#[repr(C)]
@@ -32,6 +38,19 @@ pub struct PyArray_Descr {
3238
pub byteorder: c_char,
3339
pub _former_flags: c_char,
3440
pub type_num: c_int,
41+
42+
#[cfg(Numpy_2_0)]
43+
pub flags: npy_uint64,
44+
#[cfg(Numpy_2_0)]
45+
pub elsize: npy_intp,
46+
#[cfg(Numpy_2_0)]
47+
pub alignment: npy_intp,
48+
#[cfg(Numpy_2_0)]
49+
pub metadata: *mut PyObject,
50+
#[cfg(Numpy_2_0)]
51+
pub hash: npy_hash_t,
52+
#[cfg(Numpy_2_0)]
53+
pub reserved_null: [*mut c_void; 2],
3554
}
3655

3756
#[repr(C)]
@@ -365,11 +384,31 @@ pub struct PyUFuncObject {
365384
pub core_offsets: *mut c_int,
366385
pub core_signature: *mut c_char,
367386
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,
387+
pub dict: *mut PyObject,
388+
389+
#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
390+
pub vectorcall: Option<vectorcallfunc>,
391+
#[cfg(not(all(Py_3_8, not(Py_LIMITED_API))))]
392+
pub vectorcall: *mut c_void,
393+
394+
pub reserved3: *mut c_void,
371395
pub op_flags: *mut npy_uint32,
372396
pub iter_flags: npy_uint32,
397+
398+
#[cfg(Numpy_1_16)]
399+
pub core_dim_sizes: *mut npy_intp,
400+
#[cfg(Numpy_1_16)]
401+
pub core_dim_flags: *mut npy_uint32,
402+
#[cfg(Numpy_1_16)]
403+
pub identity_value: *mut PyObject,
404+
405+
#[cfg(Numpy_1_22)]
406+
pub _dispatch_cache: *mut c_void,
407+
#[cfg(Numpy_1_22)]
408+
pub _loops: *mut PyObject,
409+
410+
#[cfg(Numpy_2_1)]
411+
pub process_core_dims_func: PyUFunc_ProcessCoreDimsFunc,
373412
}
374413

375414
pub type PyUFuncGenericFunction =
@@ -415,6 +454,10 @@ pub type PyUFunc_MaskedInnerLoopSelectionFunc = Option<
415454
) -> c_int,
416455
>;
417456

457+
#[cfg(Numpy_2_1)]
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)