@@ -4,40 +4,49 @@ use pyo3::pyclass_slots::PyClassDummySlot;
44use pyo3:: type_object:: { LazyStaticType , PyTypeInfo } ;
55use pyo3:: { ffi, types:: PyAny , PyCell } ;
66
7- pub ( crate ) struct SliceBox < T > {
8- data : Box < [ T ] > ,
7+ pub ( crate ) struct SliceBox {
8+ ptr : * mut [ u8 ] ,
9+ drop : unsafe fn ( * mut [ u8 ] ) ,
910}
1011
11- impl < T > SliceBox < T > {
12- pub ( crate ) fn new ( data : Box < [ T ] > ) -> Self {
13- Self { data }
12+ unsafe impl Send for SliceBox { }
13+
14+ impl SliceBox {
15+ pub ( crate ) fn new < T : Send > ( data : Box < [ T ] > ) -> Self {
16+ unsafe fn drop_boxed_slice < T > ( ptr : * mut [ u8 ] ) {
17+ let _ = Box :: from_raw ( ptr as * mut [ T ] ) ;
18+ }
19+
20+ let ptr = Box :: into_raw ( data) as * mut [ u8 ] ;
21+ let drop = drop_boxed_slice :: < T > ;
22+
23+ Self { ptr, drop }
24+ }
25+ }
26+
27+ impl Drop for SliceBox {
28+ fn drop ( & mut self ) {
29+ unsafe {
30+ ( self . drop ) ( self . ptr ) ;
31+ }
1432 }
1533}
1634
17- impl < T > PyClass for SliceBox < T >
18- where
19- T : Send ,
20- {
35+ impl PyClass for SliceBox {
2136 type Dict = PyClassDummySlot ;
2237 type WeakRef = PyClassDummySlot ;
2338 type BaseNativeType = PyAny ;
2439}
2540
26- impl < T > PyClassImpl for SliceBox < T >
27- where
28- T : Send ,
29- {
41+ impl PyClassImpl for SliceBox {
3042 const DOC : & ' static str = "Memory store for PyArray using rust's Box<[T]> \0 " ;
3143
3244 type BaseType = PyAny ;
3345 type Layout = PyCell < Self > ;
3446 type ThreadChecker = ThreadCheckerStub < Self > ;
3547}
3648
37- unsafe impl < T > PyTypeInfo for SliceBox < T >
38- where
39- T : Send ,
40- {
49+ unsafe impl PyTypeInfo for SliceBox {
4150 type AsRefTarget = PyCell < Self > ;
4251 const NAME : & ' static str = "SliceBox" ;
4352 const MODULE : Option < & ' static str > = Some ( "_rust_numpy" ) ;
0 commit comments