Skip to content

Commit 47a0636

Browse files
committed
Add some new FFIs
1 parent fb703b7 commit 47a0636

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/npyffi/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ impl PyArrayAPI {
313313
impl_api![299; PyDataMem_NEW_ZEROED(size: usize, elsize: usize) -> *mut c_void];
314314
impl_api![300; PyArray_CheckAnyScalarExact(obj: *mut PyObject) -> c_int];
315315
impl_api![301; PyArray_MapIterArrayCopyIfOverlap(a: *mut PyArrayObject, index: *mut PyObject, copy_if_overlap: c_int, extra_op: *mut PyArrayObject) -> *mut PyObject];
316+
impl_api![302; PyArray_ResolveWritebackIfCopy(self_: *mut PyArrayObject) -> c_int];
317+
impl_api![303; PyArray_SetWritebackIfCopyBase(arr: *mut PyArrayObject, base: *mut PyArrayObject) -> c_int];
316318
}
317319

318320
/// Define PyTypeObject related to Array API

src/npyffi/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ Please make sure that you get gil, by `let gil = Python::acquire_gil();`"
2828

2929
// Define Array&UFunc APIs
3030
macro_rules! impl_api {
31-
[ $offset:expr; $fname:ident ( $($arg:ident : $t:ty),* ) $( -> $ret:ty )* ] => {
31+
[$offset: expr; $fname: ident ( $($arg: ident : $t: ty),* ) $( -> $ret: ty )* ] => {
3232
#[allow(non_snake_case)]
3333
pub unsafe fn $fname(&self, $($arg : $t), *) $( -> $ret )* {
3434
let fptr = self.get($offset)
3535
as *const extern fn ($($arg : $t), *) $( -> $ret )*;
3636
(*fptr)($($arg), *)
3737
}
38+
};
39+
// To allow fn a(b: type,) -> ret
40+
[$offset: expr; $fname: ident ( $($arg: ident : $t:ty,)* ) $( -> $ret: ty )* ] => {
41+
impl_api![$offset; $fname( $($arg: $t),*) $( -> $ret )*];
3842
}
3943
}
4044

src/npyffi/ufunc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,18 @@ impl PyUFuncAPI {
8181
impl_api![39; PyUFunc_DefaultTypeResolver(ufunc: *mut PyUFuncObject, casting: NPY_CASTING, operands: *mut *mut PyArrayObject, type_tup: *mut PyObject, out_dtypes: *mut *mut PyArray_Descr) -> c_int];
8282
impl_api![40; PyUFunc_ValidateCasting(ufunc: *mut PyUFuncObject, casting: NPY_CASTING, operands: *mut *mut PyArrayObject, dtypes: *mut *mut PyArray_Descr) -> c_int];
8383
impl_api![41; PyUFunc_RegisterLoopForDescr(ufunc: *mut PyUFuncObject, user_dtype: *mut PyArray_Descr, function: PyUFuncGenericFunction, arg_dtypes: *mut *mut PyArray_Descr, data: *mut c_void) -> c_int];
84+
impl_api![42; PyUFunc_FromFuncAndDataAndSignatureAndIdentity(
85+
ufunc: *mut PyUFuncObject,
86+
data: *mut *mut c_void,
87+
types: *mut c_char,
88+
ntypes: c_int,
89+
nin: c_int,
90+
nout: c_int,
91+
identity: c_int,
92+
name: *const c_char,
93+
doc: *const c_char,
94+
unused: c_int,
95+
signature: *const c_char,
96+
identity_value: *const c_char,
97+
) -> c_int];
8498
}

0 commit comments

Comments
 (0)