1- use crate :: types :: TypeNum ;
2- use pyo3:: { ffi, typeob , types:: PyObjectRef , PyObjectAlloc , Python , ToPyPointer } ;
1+ use pyo3 :: class :: methods :: { PyMethodDefType , PyMethodsProtocol } ;
2+ use pyo3:: { ffi, type_object , types:: PyAny , AsPyPointer , PyObjectAlloc , Python } ;
33use std:: os:: raw:: c_void;
44
55/// It's a memory store for IntoPyArray.
@@ -12,8 +12,7 @@ pub(crate) struct SliceBox<T> {
1212
1313impl < T > SliceBox < T > {
1414 pub ( crate ) unsafe fn new < ' a > ( box_ : Box < [ T ] > ) -> & ' a Self {
15- <Self as typeob:: PyTypeObject >:: init_type ( ) ;
16- let type_ob = <Self as typeob:: PyTypeInfo >:: type_object ( ) as * mut _ ;
15+ let type_ob = <Self as type_object:: PyTypeObject >:: init_type ( ) . as_ptr ( ) ;
1716 let base = ffi:: _PyObject_New ( type_ob) ;
1817 * base = ffi:: PyObject_HEAD_INIT ;
1918 ( * base) . ob_type = type_ob;
@@ -26,9 +25,9 @@ impl<T> SliceBox<T> {
2625 }
2726}
2827
29- impl < T > typeob :: PyTypeInfo for SliceBox < T > {
28+ impl < T > type_object :: PyTypeInfo for SliceBox < T > {
3029 type Type = ( ) ;
31- type BaseType = PyObjectRef ;
30+ type BaseType = PyAny ;
3231 const NAME : & ' static str = "SliceBox" ;
3332 const DESCRIPTION : & ' static str = "Memory store for PyArray using rust's Box<[T]>." ;
3433 const FLAGS : usize = 0 ;
@@ -41,38 +40,26 @@ impl<T> typeob::PyTypeInfo for SliceBox<T> {
4140 }
4241}
4342
44- impl < T : TypeNum > typeob:: PyTypeCreate for SliceBox < T > {
45- #[ inline( always) ]
46- fn init_type ( ) {
47- static START : std:: sync:: Once = std:: sync:: ONCE_INIT ;
48- START . call_once ( || {
49- let ty = unsafe { <Self as typeob:: PyTypeInfo >:: type_object ( ) } ;
50- if ( ty. tp_flags & ffi:: Py_TPFLAGS_READY ) == 0 {
51- let gil = Python :: acquire_gil ( ) ;
52- let py = gil. python ( ) ;
53- let mod_name = format ! ( "rust_numpy.{:?}" , T :: npy_data_type( ) ) ;
54- typeob:: initialize_type :: < Self > ( py, Some ( & mod_name) )
55- . map_err ( |e| e. print ( py) )
56- . expect ( "Failed to initialize SliceBox" ) ;
57- }
58- } ) ;
43+ impl < T > PyMethodsProtocol for SliceBox < T > {
44+ fn py_methods ( ) -> Vec < & ' static PyMethodDefType > {
45+ Vec :: new ( )
5946 }
6047}
6148
62- impl < T > ToPyPointer for SliceBox < T > {
49+ impl < T > AsPyPointer for SliceBox < T > {
6350 #[ inline]
6451 fn as_ptr ( & self ) -> * mut ffi:: PyObject {
6552 & self . ob_base as * const _ as * mut _
6653 }
6754}
6855
69- impl < T > PyObjectAlloc < SliceBox < T > > for SliceBox < T > {
56+ impl < T > PyObjectAlloc for SliceBox < T > {
7057 /// Calls the rust destructor for the object.
7158 unsafe fn drop ( py : Python , obj : * mut ffi:: PyObject ) {
7259 let data = ( * ( obj as * mut SliceBox < T > ) ) . inner ;
7360 let boxed_slice = Box :: from_raw ( data) ;
7461 drop ( boxed_slice) ;
75- <Self as typeob :: PyTypeInfo >:: BaseType :: drop ( py, obj) ;
62+ <Self as type_object :: PyTypeInfo >:: BaseType :: drop ( py, obj) ;
7663 }
7764 unsafe fn dealloc ( py : Python , obj : * mut ffi:: PyObject ) {
7865 Self :: drop ( py, obj) ;
0 commit comments