1
- use crate :: types:: TypeNum ;
2
- use pyo3:: class:: methods:: PyMethodsProtocol ;
1
+ use pyo3:: class:: methods:: { PyMethodDefType , PyMethodsProtocol } ;
3
2
use pyo3:: { ffi, type_object, types:: PyAny , AsPyPointer , PyObjectAlloc , Python } ;
4
3
use std:: os:: raw:: c_void;
5
- use std:: ptr:: NonNull ;
6
4
7
5
/// It's a memory store for IntoPyArray.
8
6
/// See IntoPyArray's doc for what concretely this type is for.
@@ -14,8 +12,7 @@ pub(crate) struct SliceBox<T> {
14
12
15
13
impl < T > SliceBox < T > {
16
14
pub ( crate ) unsafe fn new < ' a > ( box_ : Box < [ T ] > ) -> & ' a Self {
17
- // <Self as type_object::PyTypeObject>::init_type();
18
- let type_ob = <Self as type_object:: PyTypeInfo >:: type_object ( ) as * mut _ ;
15
+ let type_ob = <Self as type_object:: PyTypeObject >:: init_type ( ) . as_ptr ( ) ;
19
16
let base = ffi:: _PyObject_New ( type_ob) ;
20
17
* base = ffi:: PyObject_HEAD_INIT ;
21
18
( * base) . ob_type = type_ob;
@@ -43,25 +40,9 @@ impl<T> type_object::PyTypeInfo for SliceBox<T> {
43
40
}
44
41
}
45
42
46
- impl < T : TypeNum > type_object:: PyTypeObject for SliceBox < T >
47
- where
48
- SliceBox < T > : PyMethodsProtocol ,
49
- {
50
- #[ inline( always) ]
51
- fn init_type ( ) -> NonNull < ffi:: PyTypeObject > {
52
- // static START: std::sync::Once = std::sync::ONCE_INIT;
53
- // START.call_once(|| -> NonNull<ffi::PyTypeObject> {
54
- let ty = unsafe { <Self as type_object:: PyTypeInfo >:: type_object ( ) } ;
55
- if ( ty. tp_flags & ffi:: Py_TPFLAGS_READY ) == 0 {
56
- let gil = Python :: acquire_gil ( ) ;
57
- let py = gil. python ( ) ;
58
- // let mod_name = format!("rust_numpy.{:?}", T::npy_data_type());
59
- type_object:: initialize_type :: < Self > ( py)
60
- . map_err ( |e| e. print ( py) )
61
- . expect ( "Failed to initialize SliceBox" ) ;
62
- }
63
- unsafe { NonNull :: new_unchecked ( ty) }
64
- // })
43
+ impl < T > PyMethodsProtocol for SliceBox < T > {
44
+ fn py_methods ( ) -> Vec < & ' static PyMethodDefType > {
45
+ Vec :: new ( )
65
46
}
66
47
}
67
48
0 commit comments