@@ -4,40 +4,49 @@ use pyo3::pyclass_slots::PyClassDummySlot;
4
4
use pyo3:: type_object:: { LazyStaticType , PyTypeInfo } ;
5
5
use pyo3:: { ffi, types:: PyAny , PyCell } ;
6
6
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 ] ) ,
9
10
}
10
11
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
+ }
14
32
}
15
33
}
16
34
17
- impl < T > PyClass for SliceBox < T >
18
- where
19
- T : Send ,
20
- {
35
+ impl PyClass for SliceBox {
21
36
type Dict = PyClassDummySlot ;
22
37
type WeakRef = PyClassDummySlot ;
23
38
type BaseNativeType = PyAny ;
24
39
}
25
40
26
- impl < T > PyClassImpl for SliceBox < T >
27
- where
28
- T : Send ,
29
- {
41
+ impl PyClassImpl for SliceBox {
30
42
const DOC : & ' static str = "Memory store for PyArray using rust's Box<[T]> \0 " ;
31
43
32
44
type BaseType = PyAny ;
33
45
type Layout = PyCell < Self > ;
34
46
type ThreadChecker = ThreadCheckerStub < Self > ;
35
47
}
36
48
37
- unsafe impl < T > PyTypeInfo for SliceBox < T >
38
- where
39
- T : Send ,
40
- {
49
+ unsafe impl PyTypeInfo for SliceBox {
41
50
type AsRefTarget = PyCell < Self > ;
42
51
const NAME : & ' static str = "SliceBox" ;
43
52
const MODULE : Option < & ' static str > = Some ( "_rust_numpy" ) ;
0 commit comments