@@ -2,8 +2,7 @@ use std::ptr::NonNull;
2
2
3
3
pub struct TskBox < T > {
4
4
tsk : NonNull < T > ,
5
- teardown : Option < unsafe extern "C" fn ( * mut T ) -> i32 > ,
6
- owning : bool ,
5
+ teardown : unsafe extern "C" fn ( * mut T ) -> i32 ,
7
6
}
8
7
9
8
impl < T > TskBox < T > {
@@ -14,11 +13,7 @@ impl<T> TskBox<T> {
14
13
let x = unsafe { libc:: malloc ( std:: mem:: size_of :: < T > ( ) ) as * mut T } ;
15
14
let _ = init ( x) ;
16
15
let tsk = NonNull :: new ( x) . unwrap ( ) ;
17
- Self {
18
- tsk,
19
- teardown : Some ( teardown) ,
20
- owning : true ,
21
- }
16
+ Self { tsk, teardown }
22
17
}
23
18
24
19
pub fn as_ref ( & self ) -> & T {
@@ -40,14 +35,10 @@ impl<T> TskBox<T> {
40
35
41
36
impl < T > Drop for TskBox < T > {
42
37
fn drop ( & mut self ) {
43
- if let Some ( teardown) = self . teardown {
44
- unsafe {
45
- ( teardown) ( self . tsk . as_mut ( ) as * mut T ) ;
46
- }
47
- }
48
- if self . owning {
49
- unsafe { libc:: free ( self . tsk . as_ptr ( ) as * mut libc:: c_void ) }
38
+ unsafe {
39
+ ( self . teardown ) ( self . tsk . as_mut ( ) as * mut T ) ;
50
40
}
41
+ unsafe { libc:: free ( self . tsk . as_ptr ( ) as * mut libc:: c_void ) }
51
42
}
52
43
}
53
44
@@ -70,7 +61,7 @@ fn test_miri() {
70
61
71
62
let options = 0_i32 ;
72
63
73
- let b = TskBox :: new (
64
+ let _ = TskBox :: new (
74
65
|x : * mut X | unsafe {
75
66
( * x) . data = options;
76
67
0
@@ -93,7 +84,7 @@ fn test_table_collection_tskbox() {
93
84
#[ test]
94
85
fn test_table_collection_tskbox_shared_ptr ( ) {
95
86
let flags: u32 = 0 ;
96
- let tables = TskBox :: new (
87
+ let _ = TskBox :: new (
97
88
|t : * mut super :: bindings:: tsk_table_collection_t | unsafe {
98
89
super :: bindings:: tsk_table_collection_init ( t, flags)
99
90
} ,
0 commit comments