File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
crates/swc_plugin_proxy/src/memory_interop Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,14 @@ fn read_returned_result_from_host_inner<F>(f: F) -> Option<AllocatedBytesPtr>
4141where
4242 F : FnOnce ( u32 ) -> u32 ,
4343{
44+ use std:: cell:: UnsafeCell ;
45+
4446 // Allocate AllocatedBytesPtr to get return value from the host
45- let mut allocated_bytes_ptr = [ 0u32 , 0u32 ] ;
46- let serialized_allocated_bytes_raw_ptr = allocated_bytes_ptr. as_mut_ptr ( ) ;
47+ //
48+ // I'm not sure if `.as_mut_ptr()` creates an alias for array,
49+ // using `UnsafeCell` here makes the semantics clearer.
50+ let mut allocated_bytes_ptr: UnsafeCell < [ u32 ; 2 ] > = UnsafeCell :: new ( [ 0 ; 2 ] ) ;
51+ let serialized_allocated_bytes_raw_ptr = allocated_bytes_ptr. get ( ) ;
4752
4853 assert_eq ! ( std:: mem:: size_of:: <* mut u32 >( ) , std:: mem:: size_of:: <u32 >( ) ) ;
4954
5762 return None ;
5863 }
5964
65+ let allocated_bytes_ptr = allocated_bytes_ptr. into_inner ( ) ;
66+
6067 // Return reconstructted AllocatedBytesPtr to reveal ptr to the allocated bytes
6168 Some ( AllocatedBytesPtr (
6269 allocated_bytes_ptr[ 0 ] ,
You can’t perform that action at this time.
0 commit comments