@@ -9,7 +9,7 @@ use std::ptr::null_mut;
9
9
10
10
use pyo3:: ffi;
11
11
use pyo3:: ffi:: { PyObject , PyTypeObject } ;
12
- use pyo3:: { ObjectProtocol , PyModule , PyResult , Python } ;
12
+ use pyo3:: { ObjectProtocol , PyModule , PyResult , Python , ToPyPointer } ;
13
13
14
14
use npyffi:: * ;
15
15
@@ -20,15 +20,15 @@ use npyffi::*;
20
20
/// Some APIs (including most accessor) in the above URL are not implemented
21
21
/// since they are defined as C macro, and cannot be called from rust.
22
22
/// Some of these are implemented on the high-level interface as a Rust function.
23
- pub struct PyArrayModule {
24
- numpy : PyModule ,
23
+ pub struct PyArrayModule < ' py > {
24
+ numpy : & ' py PyModule ,
25
25
api : * const * const c_void ,
26
26
}
27
27
28
- impl Deref for PyArrayModule {
28
+ impl < ' py > Deref for PyArrayModule < ' py > {
29
29
type Target = PyModule ;
30
30
fn deref ( & self ) -> & Self :: Target {
31
- & self . numpy
31
+ self . numpy
32
32
}
33
33
}
34
34
@@ -42,14 +42,13 @@ pub unsafe fn $fname(&self, $($arg : $t), *) $( -> $ret )* {
42
42
}
43
43
} } // pyarray_api!
44
44
45
- impl PyArrayModule {
45
+ impl < ' py > PyArrayModule < ' py > {
46
46
/// Import `numpy.core.multiarray` to use Array API.
47
- pub fn import ( py : Python ) -> PyResult < Self > {
47
+ pub fn import ( py : Python < ' py > ) -> PyResult < Self > {
48
48
let numpy = py. import ( "numpy.core.multiarray" ) ?;
49
- let c_api = numpy. as_object ( ) . getattr ( py , "_ARRAY_API" ) ?;
49
+ let c_api = numpy. getattr ( "_ARRAY_API" ) ?;
50
50
let api = unsafe {
51
- pyo3:: ffi:: PyCapsule_GetPointer ( c_api. as_object ( ) . as_ptr ( ) , null_mut ( ) )
52
- as * const * const c_void
51
+ ffi:: PyCapsule_GetPointer ( c_api. as_ptr ( ) , null_mut ( ) ) as * const * const c_void
53
52
} ;
54
53
Ok ( Self {
55
54
numpy : numpy,
@@ -322,7 +321,7 @@ macro_rules! impl_array_type {
322
321
#[ allow( non_camel_case_types) ]
323
322
#[ repr( i32 ) ]
324
323
pub enum ArrayType { $( $tname) ,* }
325
- impl PyArrayModule {
324
+ impl < ' py> PyArrayModule < ' py> {
326
325
pub unsafe fn get_type_object( & self , ty: ArrayType ) -> * mut PyTypeObject {
327
326
match ty {
328
327
$( ArrayType :: $tname => * ( self . api. offset( $offset) ) as * mut PyTypeObject ) ,*
@@ -375,10 +374,10 @@ impl_array_type!(
375
374
376
375
#[ allow( non_snake_case) ]
377
376
pub unsafe fn PyArray_Check ( np : & PyArrayModule , op : * mut PyObject ) -> c_int {
378
- pyo3 :: ffi:: PyObject_TypeCheck ( op, np. get_type_object ( ArrayType :: PyArray_Type ) )
377
+ ffi:: PyObject_TypeCheck ( op, np. get_type_object ( ArrayType :: PyArray_Type ) )
379
378
}
380
379
381
380
#[ allow( non_snake_case) ]
382
381
pub unsafe fn PyArray_CheckExact ( np : & PyArrayModule , op : * mut PyObject ) -> c_int {
383
- ( pyo3 :: ffi:: Py_TYPE ( op) == np. get_type_object ( ArrayType :: PyArray_Type ) ) as c_int
382
+ ( ffi:: Py_TYPE ( op) == np. get_type_object ( ArrayType :: PyArray_Type ) ) as c_int
384
383
}
0 commit comments