File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change
1
+ #![ deny( unsafe_op_in_unsafe_fn) ]
2
+
1
3
use crate :: src:: c_box:: CBox ;
2
4
use crate :: src:: error:: Rav1dResult ;
3
5
use std:: marker:: PhantomData ;
@@ -212,7 +214,7 @@ impl<T: ?Sized> CArc<T> {
212
214
pub unsafe fn from_raw ( raw : RawCArc < T > ) -> Self {
213
215
// Safety: The [`RawCArc`] contains the output of [`Arc::into_raw`],
214
216
// so we can call [`Arc::from_raw`] on it.
215
- let owner = raw. 0 . into_arc ( ) ;
217
+ let owner = unsafe { raw. 0 . into_arc ( ) } ;
216
218
owner. into ( )
217
219
}
218
220
}
Original file line number Diff line number Diff line change
1
+ #![ deny( unsafe_op_in_unsafe_fn) ]
2
+
1
3
use std:: ffi:: c_void;
2
4
use std:: marker:: PhantomData ;
3
5
use std:: ops:: Deref ;
@@ -15,8 +17,15 @@ pub struct Free {
15
17
}
16
18
17
19
impl Free {
20
+ /// # Safety
21
+ ///
22
+ /// `ptr` is a [`NonNull`]`<T>` and `free` deallocates it.
23
+ /// It must not be used after this call as it is deallocated.
18
24
pub unsafe fn free ( & self , ptr : * mut c_void ) {
19
- ( self . free ) ( ptr as * const u8 , self . cookie )
25
+ // SAFETY: `self` came from `CBox::from_c`,
26
+ // which requires `self.free` to deallocate the `NonNull<T>` passed to it,
27
+ // and `self.cookie` to be passed to it, which it is.
28
+ unsafe { ( self . free ) ( ptr as * const u8 , self . cookie ) }
20
29
}
21
30
}
22
31
@@ -85,7 +94,9 @@ impl<T: ?Sized> CBox<T> {
85
94
/// # Safety
86
95
///
87
96
/// `data` must be valid to dereference
88
- /// until `free` is called on it, which must deallocate it.
97
+ /// until `free.free` is called on it, which must deallocate it.
98
+ /// `free.free` is always called with `free.cookie`,
99
+ /// which must be accessed thread-safely.
89
100
pub unsafe fn from_c ( data : NonNull < T > , free : Free ) -> Self {
90
101
Self :: C {
91
102
data,
You can’t perform that action at this time.
0 commit comments