@@ -46,21 +46,25 @@ struct RwLockCtxRead<Array> where Array: 'static {
4646}
4747
4848unsafe extern "C" fn rwlock_write_deleter_fn < T > ( tensor : * mut sys:: DLManagedTensorVersioned ) where T : ' static {
49- // Reconstruct the box and drop it, freeing the memory.
50- let ctx = ( * tensor) . manager_ctx . cast :: < RwLockCtxWrite < T > > ( ) ;
51- let _ = Box :: from_raw ( ctx) ;
49+ unsafe {
50+ // Reconstruct the box and drop it, freeing the memory.
51+ let ctx = ( * tensor) . manager_ctx . cast :: < RwLockCtxWrite < T > > ( ) ;
52+ let _ = Box :: from_raw ( ctx) ;
5253
53- // also drop the tensor itself
54- let _ = Box :: from_raw ( tensor) ;
54+ // also drop the tensor itself
55+ let _ = Box :: from_raw ( tensor) ;
56+ }
5557}
5658
5759unsafe extern "C" fn rwlock_read_deleter_fn < T > ( tensor : * mut sys:: DLManagedTensorVersioned ) where T : ' static {
58- // Reconstruct the box and drop it, freeing the memory.
59- let ctx = ( * tensor) . manager_ctx . cast :: < RwLockCtxRead < T > > ( ) ;
60- let _ = Box :: from_raw ( ctx) ;
60+ unsafe {
61+ // Reconstruct the box and drop it, freeing the memory.
62+ let ctx = ( * tensor) . manager_ctx . cast :: < RwLockCtxRead < T > > ( ) ;
63+ let _ = Box :: from_raw ( ctx) ;
6164
62- // also drop the tensor itself
63- let _ = Box :: from_raw ( tensor) ;
65+ // also drop the tensor itself
66+ let _ = Box :: from_raw ( tensor) ;
67+ }
6468}
6569
6670impl < T , D > TryFrom < ReadWrite < Arc < RwLock < Array < T , D > > > > > for DLPackTensor
@@ -227,12 +231,14 @@ struct MutexCtx<Array> where Array: 'static {
227231}
228232
229233unsafe extern "C" fn mutex_deleter_fn < T > ( tensor : * mut sys:: DLManagedTensorVersioned ) where T : ' static {
230- // Reconstruct the box and drop it, freeing the memory.
231- let ctx = ( * tensor) . manager_ctx . cast :: < MutexCtx < T > > ( ) ;
232- let _ = Box :: from_raw ( ctx) ;
234+ unsafe {
235+ // Reconstruct the box and drop it, freeing the memory.
236+ let ctx = ( * tensor) . manager_ctx . cast :: < MutexCtx < T > > ( ) ;
237+ let _ = Box :: from_raw ( ctx) ;
233238
234- // also drop the tensor itself
235- let _ = Box :: from_raw ( tensor) ;
239+ // also drop the tensor itself
240+ let _ = Box :: from_raw ( tensor) ;
241+ }
236242}
237243
238244impl < T , D > TryFrom < Arc < Mutex < Array < T , D > > > > for DLPackTensor
0 commit comments