@@ -18,28 +18,24 @@ fn get_numpy_api(_py: Python, module: &str, capsule: &str) -> *const *const c_vo
1818 let module = CString :: new ( module) . unwrap ( ) ;
1919 let capsule = CString :: new ( capsule) . unwrap ( ) ;
2020 unsafe {
21- let numpy = ffi:: PyImport_ImportModule ( module. as_ptr ( ) ) ;
22- assert ! ( !numpy . is_null( ) , "Failed to import numpy module" ) ;
23- let capsule = ffi:: PyObject_GetAttrString ( numpy as _ , capsule. as_ptr ( ) ) ;
24- assert ! ( !capsule. is_null( ) , "Failed to get numpy capsule API" ) ;
21+ let module = ffi:: PyImport_ImportModule ( module. as_ptr ( ) ) ;
22+ assert ! ( !module . is_null( ) , "Failed to import NumPy module" ) ;
23+ let capsule = ffi:: PyObject_GetAttrString ( module as _ , capsule. as_ptr ( ) ) ;
24+ assert ! ( !capsule. is_null( ) , "Failed to get NumPy API capsule " ) ;
2525 ffi:: PyCapsule_GetPointer ( capsule, null_mut ( ) ) as _
2626 }
2727}
2828
29- // Define Array& UFunc APIs
29+ // Implements wrappers for NumPy's Array and UFunc API
3030macro_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 , py: Python , $( $arg : $t) , * ) $( -> $ret ) * {
3434 let fptr = self . get( py, $offset)
3535 as * const extern fn ( $( $arg : $t) , * ) $( -> $ret ) * ;
3636 ( * fptr) ( $( $arg) , * )
3737 }
3838 } ;
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 ) * ] ;
42- }
4339}
4440
4541pub mod array;
0 commit comments