File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 1
1
use std:: { ffi:: c_void, ptr:: NonNull } ;
2
2
3
- use pyo3:: { prelude:: * , types:: PyCapsule } ;
3
+ use pyo3:: { exceptions :: PyRuntimeError , prelude:: * , types:: PyCapsule } ;
4
4
5
5
#[ repr( C ) ]
6
6
#[ derive( Debug , Clone , Copy ) ]
@@ -12,8 +12,9 @@ pub struct npy_bitgen {
12
12
pub next_raw : NonNull < unsafe extern "C" fn ( * mut c_void ) -> super :: npy_uint64 > , //nogil
13
13
}
14
14
15
- pub fn get_bitgen_api < ' py > ( bitgen : Bound < ' py , PyAny > ) -> PyResult < * mut npy_bitgen > {
15
+ pub fn get_bitgen_api < ' py > ( bitgen : Bound < ' py , PyAny > ) -> PyResult < NonNull < npy_bitgen > > {
16
16
let capsule = bitgen. getattr ( "capsule" ) ?. downcast_into :: < PyCapsule > ( ) ?;
17
17
assert_eq ! ( capsule. name( ) ?, Some ( c"BitGenerator" ) ) ;
18
- Ok ( capsule. pointer ( ) as * mut npy_bitgen )
18
+ let ptr = capsule. pointer ( ) as * mut npy_bitgen ;
19
+ NonNull :: new ( ptr) . ok_or_else ( || PyRuntimeError :: new_err ( "Invalid BitGenerator capsule" ) )
19
20
}
You can’t perform that action at this time.
0 commit comments