@@ -90,7 +90,7 @@ pub unsafe extern "C" fn DType_free(dtype: *mut DType) {
9090/// Get the dtype variant tag for an [`DType`].
9191#[ unsafe( no_mangle) ]
9292pub unsafe extern "C" fn DType_get ( dtype : * const DType ) -> u8 {
93- match & * dtype {
93+ match dtype. as_ref ( ) . vortex_expect ( "null dtype" ) {
9494 DType :: Null => DTYPE_NULL ,
9595 DType :: Bool ( _) => DTYPE_BOOL ,
9696 DType :: Primitive ( ptype, _) => match ptype {
@@ -116,14 +116,15 @@ pub unsafe extern "C" fn DType_get(dtype: *const DType) -> u8 {
116116
117117#[ unsafe( no_mangle) ]
118118pub unsafe extern "C" fn DType_nullable ( dtype : * const DType ) -> bool {
119- let dtype = & * dtype;
119+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
120120 dtype. is_nullable ( )
121121}
122122
123123/// For `DTYPE_STRUCT` variant DTypes, get the number of fields.
124124#[ unsafe( no_mangle) ]
125125pub unsafe extern "C" fn DType_field_count ( dtype : * const DType ) -> u32 {
126- let DType :: Struct ( struct_dtype, _) = & * dtype else {
126+ let DType :: Struct ( struct_dtype, _) = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" )
127+ else {
127128 panic ! ( "FFIDType_field_count: not a struct dtype" )
128129 } ;
129130
@@ -143,7 +144,8 @@ pub unsafe extern "C" fn DType_field_name(
143144 assert ! ( !dst. is_null( ) , "DType_field_name: null ptr dst" ) ;
144145 assert ! ( !len. is_null( ) , "DType_field_name: null ptr len" ) ;
145146
146- let DType :: Struct ( struct_dtype, _) = & * dtype else {
147+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
148+ let DType :: Struct ( struct_dtype, _) = dtype else {
147149 panic ! ( "FFIDType_field_name: not a struct dtype" )
148150 } ;
149151
@@ -162,7 +164,8 @@ pub unsafe extern "C" fn DType_field_name(
162164/// by the caller.
163165#[ unsafe( no_mangle) ]
164166pub unsafe extern "C" fn DType_field_dtype ( dtype : * const DType , index : u32 ) -> * mut DType {
165- let DType :: Struct ( struct_dtype, _) = & * dtype else {
167+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
168+ let DType :: Struct ( struct_dtype, _) = dtype else {
166169 panic ! ( "DType_field_dtype: not a struct dtype" )
167170 } ;
168171
@@ -184,7 +187,8 @@ pub unsafe extern "C" fn DType_field_dtype(dtype: *const DType, index: u32) -> *
184187pub unsafe extern "C" fn DType_element_type ( dtype : * const DType ) -> * const DType {
185188 assert ! ( !dtype. is_null( ) , "DType_element_type: null ptr" ) ;
186189
187- let DType :: List ( element_dtype, _) = & * dtype else {
190+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
191+ let DType :: List ( element_dtype, _) = dtype else {
188192 panic ! ( "DType_element_type: not a list dtype" )
189193 } ;
190194
@@ -193,31 +197,39 @@ pub unsafe extern "C" fn DType_element_type(dtype: *const DType) -> *const DType
193197
194198#[ unsafe( no_mangle) ]
195199pub unsafe extern "C" fn DType_is_time ( dtype : * const DType ) -> bool {
196- match & * dtype {
200+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
201+
202+ match dtype {
197203 DType :: Extension ( ext_dtype) => ext_dtype. id ( ) == & * TIME_ID ,
198204 _ => false ,
199205 }
200206}
201207
202208#[ unsafe( no_mangle) ]
203209pub unsafe extern "C" fn DType_is_date ( dtype : * const DType ) -> bool {
204- match & * dtype {
210+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
211+
212+ match dtype {
205213 DType :: Extension ( ext_dtype) => ext_dtype. id ( ) == & * DATE_ID ,
206214 _ => false ,
207215 }
208216}
209217
210218#[ unsafe( no_mangle) ]
211219pub unsafe extern "C" fn DType_is_timestamp ( dtype : * const DType ) -> bool {
212- match & * dtype {
220+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
221+
222+ match dtype {
213223 DType :: Extension ( ext_dtype) => ext_dtype. id ( ) == & * TIMESTAMP_ID ,
214224 _ => false ,
215225 }
216226}
217227
218228#[ unsafe( no_mangle) ]
219229pub unsafe extern "C" fn DType_time_unit ( dtype : * const DType ) -> u8 {
220- let DType :: Extension ( ext_dtype) = & * dtype else {
230+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
231+
232+ let DType :: Extension ( ext_dtype) = dtype else {
221233 panic ! ( "DType_time_unit: not a time dtype" )
222234 } ;
223235
@@ -229,7 +241,9 @@ pub unsafe extern "C" fn DType_time_unit(dtype: *const DType) -> u8 {
229241
230242#[ unsafe( no_mangle) ]
231243pub unsafe extern "C" fn DType_time_zone ( dtype : * const DType , dst : * mut c_void , len : * mut c_int ) {
232- let DType :: Extension ( ext_dtype) = & * dtype else {
244+ let dtype = unsafe { dtype. as_ref ( ) } . vortex_expect ( "dtype null" ) ;
245+
246+ let DType :: Extension ( ext_dtype) = dtype else {
233247 panic ! ( "DType_time_unit: not a time dtype" )
234248 } ;
235249
0 commit comments