@@ -25,7 +25,10 @@ pub struct vx_array {
2525/// Get the length of the array.
2626#[ unsafe( no_mangle) ]
2727pub unsafe extern "C-unwind" fn vx_array_len ( array : * const vx_array ) -> u64 {
28- array. as_ref ( ) . vortex_expect ( "array null" ) . inner . len ( ) as u64
28+ unsafe { array. as_ref ( ) }
29+ . vortex_expect ( "array null" )
30+ . inner
31+ . len ( ) as u64
2932}
3033
3134/// Get a pointer to the data type for an array.
@@ -34,7 +37,10 @@ pub unsafe extern "C-unwind" fn vx_array_len(array: *const vx_array) -> u64 {
3437/// for ensuring that it is never dereferenced after the array has been freed.
3538#[ unsafe( no_mangle) ]
3639pub unsafe extern "C-unwind" fn vx_array_dtype ( array : * const vx_array ) -> * const DType {
37- array. as_ref ( ) . vortex_expect ( "array null" ) . inner . dtype ( )
40+ unsafe { array. as_ref ( ) }
41+ . vortex_expect ( "array null" )
42+ . inner
43+ . dtype ( )
3844}
3945
4046#[ unsafe( no_mangle) ]
@@ -44,7 +50,7 @@ pub unsafe extern "C-unwind" fn vx_array_get_field(
4450 error : * mut * mut vx_error ,
4551) -> * const vx_array {
4652 try_or ( error, ptr:: null ( ) , || {
47- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
53+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
4854
4955 let field_array = array
5056 . inner
@@ -75,7 +81,7 @@ pub unsafe extern "C-unwind" fn vx_array_slice(
7581 stop : u32 ,
7682 error : * mut * mut vx_error ,
7783) -> * const vx_array {
78- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
84+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
7985 try_or ( error, ptr:: null_mut ( ) , || {
8086 let sliced = array. inner . as_ref ( ) . slice ( start as usize , stop as usize ) ?;
8187 Ok ( Box :: into_raw ( Box :: new ( vx_array { inner : sliced } ) ) )
@@ -88,7 +94,7 @@ pub unsafe extern "C-unwind" fn vx_array_is_null(
8894 index : u32 ,
8995 error : * mut * mut vx_error ,
9096) -> bool {
91- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
97+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
9298 try_or ( error, false , || array. inner . is_invalid ( index as usize ) )
9399}
94100
@@ -97,7 +103,7 @@ pub unsafe extern "C-unwind" fn vx_array_null_count(
97103 array : * const vx_array ,
98104 error : * mut * mut vx_error ,
99105) -> u32 {
100- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
106+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
101107 try_or ( error, 0 , || {
102108 Ok ( array. inner . as_ref ( ) . invalid_count ( ) ?. try_into ( ) ?)
103109 } )
@@ -108,7 +114,7 @@ macro_rules! ffiarray_get_ptype {
108114 paste:: paste! {
109115 #[ unsafe ( no_mangle) ]
110116 pub unsafe extern "C-unwind" fn [ <vx_array_get_ $ptype>] ( array: * const vx_array, index: u32 ) -> $ptype {
111- let array = array. as_ref( ) . vortex_expect( "array null" ) ;
117+ let array = unsafe { array. as_ref( ) } . vortex_expect( "array null" ) ;
112118 let value = array. inner. scalar_at( index as usize ) . vortex_expect( "scalar_at" ) ;
113119 value. as_primitive( )
114120 . as_:: <$ptype>( )
@@ -118,7 +124,7 @@ macro_rules! ffiarray_get_ptype {
118124
119125 #[ unsafe ( no_mangle) ]
120126 pub unsafe extern "C-unwind" fn [ <vx_array_get_storage_ $ptype>] ( array: * const vx_array, index: u32 ) -> $ptype {
121- let array = array. as_ref( ) . vortex_expect( "array null" ) ;
127+ let array = unsafe { array. as_ref( ) } . vortex_expect( "array null" ) ;
122128 let value = array. inner. scalar_at( index as usize ) . vortex_expect( "scalar_at" ) ;
123129 value. as_extension( )
124130 . storage( )
@@ -152,7 +158,7 @@ pub unsafe extern "C-unwind" fn vx_array_get_utf8(
152158 dst : * mut c_void ,
153159 len : * mut c_int ,
154160) {
155- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
161+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
156162 let value = array
157163 . inner
158164 . as_ref ( )
@@ -161,9 +167,9 @@ pub unsafe extern "C-unwind" fn vx_array_get_utf8(
161167 let utf8_scalar = value. as_utf8 ( ) ;
162168 if let Some ( buffer) = utf8_scalar. value ( ) {
163169 let bytes = buffer. as_bytes ( ) ;
164- let dst = std:: slice:: from_raw_parts_mut ( dst as * mut u8 , bytes. len ( ) ) ;
170+ let dst = unsafe { std:: slice:: from_raw_parts_mut ( dst as * mut u8 , bytes. len ( ) ) } ;
165171 dst. copy_from_slice ( bytes) ;
166- * len = bytes. len ( ) . try_into ( ) . vortex_unwrap ( ) ;
172+ unsafe { * len = bytes. len ( ) . try_into ( ) . vortex_unwrap ( ) } ;
167173 }
168174}
169175
@@ -176,16 +182,16 @@ pub unsafe extern "C-unwind" fn vx_array_get_binary(
176182 dst : * mut c_void ,
177183 len : * mut c_int ,
178184) {
179- let array = array. as_ref ( ) . vortex_expect ( "array null" ) ;
185+ let array = unsafe { array. as_ref ( ) } . vortex_expect ( "array null" ) ;
180186 let value = array
181187 . inner
182188 . scalar_at ( index as usize )
183189 . vortex_expect ( "scalar_at" ) ;
184190 let utf8_scalar = value. as_binary ( ) ;
185191 if let Some ( bytes) = utf8_scalar. value ( ) {
186- let dst = std:: slice:: from_raw_parts_mut ( dst as * mut u8 , bytes. len ( ) ) ;
192+ let dst = unsafe { std:: slice:: from_raw_parts_mut ( dst as * mut u8 , bytes. len ( ) ) } ;
187193 dst. copy_from_slice ( & bytes) ;
188- * len = bytes. len ( ) . try_into ( ) . vortex_unwrap ( ) ;
194+ unsafe { * len = bytes. len ( ) . try_into ( ) . vortex_unwrap ( ) } ;
189195 }
190196}
191197
@@ -203,20 +209,20 @@ mod tests {
203209 fn test_simple ( ) {
204210 unsafe {
205211 let primitive = PrimitiveArray :: new ( buffer ! [ 1i32 , 2i32 , 3i32 ] , Validity :: NonNullable ) ;
206- let ffi_array = Box :: new ( vx_array {
212+ let vx_array = Box :: new ( vx_array {
207213 inner : primitive. to_array ( ) ,
208214 } ) ;
209215
210- assert_eq ! ( vx_array_len( & * ffi_array ) , 3 ) ;
216+ assert_eq ! ( vx_array_len( & * vx_array ) , 3 ) ;
211217
212- let array_dtype = vx_array_dtype ( & * ffi_array ) ;
218+ let array_dtype = vx_array_dtype ( & * vx_array ) ;
213219 assert_eq ! ( vx_dtype_get( array_dtype) , DTYPE_PRIMITIVE_I32 ) ;
214220
215- assert_eq ! ( vx_array_get_i32( & * ffi_array , 0 ) , 1 ) ;
216- assert_eq ! ( vx_array_get_i32( & * ffi_array , 1 ) , 2 ) ;
217- assert_eq ! ( vx_array_get_i32( & * ffi_array , 2 ) , 3 ) ;
221+ assert_eq ! ( vx_array_get_i32( & * vx_array , 0 ) , 1 ) ;
222+ assert_eq ! ( vx_array_get_i32( & * vx_array , 1 ) , 2 ) ;
223+ assert_eq ! ( vx_array_get_i32( & * vx_array , 2 ) , 3 ) ;
218224
219- vx_array_free ( Box :: into_raw ( ffi_array ) ) ;
225+ vx_array_free ( Box :: into_raw ( vx_array ) ) ;
220226 }
221227 }
222228}
0 commit comments