43
43
//! let (out_array, out_schema) = to_ffi(&data)?;
44
44
//!
45
45
//! // import it
46
- //! let data = from_ffi(out_array, &out_schema)?;
46
+ //! let data = unsafe { from_ffi(out_array, &out_schema) } ?;
47
47
//! let array = Int32Array::from(data);
48
48
//!
49
49
//! // perform some operation
80
80
//! let mut schema = FFI_ArrowSchema::empty();
81
81
//! let mut array = FFI_ArrowArray::empty();
82
82
//! foreign.export_to_c(addr_of_mut!(array), addr_of_mut!(schema));
83
- //! Ok(make_array(from_ffi(array, &schema)?))
83
+ //! Ok(make_array(unsafe { from_ffi(array, &schema) } ?))
84
84
//! }
85
85
//! ```
86
86
@@ -234,7 +234,7 @@ pub fn to_ffi(data: &ArrayData) -> Result<(FFI_ArrowArray, FFI_ArrowSchema)> {
234
234
/// # Safety
235
235
///
236
236
/// This struct assumes that the incoming data agrees with the C data interface.
237
- pub fn from_ffi ( array : FFI_ArrowArray , schema : & FFI_ArrowSchema ) -> Result < ArrayData > {
237
+ pub unsafe fn from_ffi ( array : FFI_ArrowArray , schema : & FFI_ArrowSchema ) -> Result < ArrayData > {
238
238
let dt = DataType :: try_from ( schema) ?;
239
239
let array = Arc :: new ( array) ;
240
240
let tmp = ImportedArrowArray {
@@ -250,7 +250,10 @@ pub fn from_ffi(array: FFI_ArrowArray, schema: &FFI_ArrowSchema) -> Result<Array
250
250
/// # Safety
251
251
///
252
252
/// This struct assumes that the incoming data agrees with the C data interface.
253
- pub fn from_ffi_and_data_type ( array : FFI_ArrowArray , data_type : DataType ) -> Result < ArrayData > {
253
+ pub unsafe fn from_ffi_and_data_type (
254
+ array : FFI_ArrowArray ,
255
+ data_type : DataType ,
256
+ ) -> Result < ArrayData > {
254
257
let array = Arc :: new ( array) ;
255
258
let tmp = ImportedArrowArray {
256
259
array : & array,
@@ -487,7 +490,7 @@ mod tests {
487
490
let ( array, schema) = to_ffi ( & array. into_data ( ) ) . unwrap ( ) ;
488
491
489
492
// (simulate consumer) import it
490
- let array = Int32Array :: from ( from_ffi ( array, & schema) . unwrap ( ) ) ;
493
+ let array = Int32Array :: from ( unsafe { from_ffi ( array, & schema) } . unwrap ( ) ) ;
491
494
let array = kernels:: numeric:: add ( & array, & array) . unwrap ( ) ;
492
495
493
496
// verify
@@ -531,7 +534,7 @@ mod tests {
531
534
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
532
535
533
536
// (simulate consumer) import it
534
- let data = from_ffi ( array, & schema) ?;
537
+ let data = unsafe { from_ffi ( array, & schema) } ?;
535
538
let array = make_array ( data) ;
536
539
537
540
// perform some operation
@@ -561,7 +564,7 @@ mod tests {
561
564
let ( array, schema) = to_ffi ( & original_array. to_data ( ) ) ?;
562
565
563
566
// (simulate consumer) import it
564
- let data = from_ffi ( array, & schema) ?;
567
+ let data = unsafe { from_ffi ( array, & schema) } ?;
565
568
let array = make_array ( data) ;
566
569
567
570
// perform some operation
@@ -583,7 +586,7 @@ mod tests {
583
586
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
584
587
585
588
// (simulate consumer) import it
586
- let data = from_ffi ( array, & schema) ?;
589
+ let data = unsafe { from_ffi ( array, & schema) } ?;
587
590
let array = make_array ( data) ;
588
591
589
592
// perform some operation
@@ -652,7 +655,7 @@ mod tests {
652
655
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
653
656
654
657
// (simulate consumer) import it
655
- let data = from_ffi ( array, & schema) ?;
658
+ let data = unsafe { from_ffi ( array, & schema) } ?;
656
659
let array = make_array ( data) ;
657
660
658
661
// downcast
@@ -692,7 +695,7 @@ mod tests {
692
695
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
693
696
694
697
// (simulate consumer) import it
695
- let data = from_ffi ( array, & schema) ?;
698
+ let data = unsafe { from_ffi ( array, & schema) } ?;
696
699
let array = make_array ( data) ;
697
700
698
701
// perform some operation
@@ -737,7 +740,7 @@ mod tests {
737
740
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
738
741
739
742
// (simulate consumer) import it
740
- let data = from_ffi ( array, & schema) ?;
743
+ let data = unsafe { from_ffi ( array, & schema) } ?;
741
744
let array = make_array ( data) ;
742
745
743
746
// perform some operation
@@ -763,7 +766,7 @@ mod tests {
763
766
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
764
767
765
768
// (simulate consumer) import it
766
- let data = from_ffi ( array, & schema) ?;
769
+ let data = unsafe { from_ffi ( array, & schema) } ?;
767
770
let array = make_array ( data) ;
768
771
769
772
// perform some operation
@@ -792,7 +795,7 @@ mod tests {
792
795
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
793
796
794
797
// (simulate consumer) import it
795
- let data = from_ffi ( array, & schema) ?;
798
+ let data = unsafe { from_ffi ( array, & schema) } ?;
796
799
let array = make_array ( data) ;
797
800
798
801
// perform some operation
@@ -828,7 +831,7 @@ mod tests {
828
831
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
829
832
830
833
// (simulate consumer) import it
831
- let data = from_ffi ( array, & schema) ?;
834
+ let data = unsafe { from_ffi ( array, & schema) } ?;
832
835
let array = make_array ( data) ;
833
836
834
837
// perform some operation
@@ -889,7 +892,7 @@ mod tests {
889
892
let ( array, schema) = to_ffi ( & list_data) ?;
890
893
891
894
// (simulate consumer) import it
892
- let data = from_ffi ( array, & schema) ?;
895
+ let data = unsafe { from_ffi ( array, & schema) } ?;
893
896
let array = make_array ( data) ;
894
897
895
898
// perform some operation
@@ -934,7 +937,7 @@ mod tests {
934
937
let ( array, schema) = to_ffi ( & dict_array. to_data ( ) ) ?;
935
938
936
939
// (simulate consumer) import it
937
- let data = from_ffi ( array, & schema) ?;
940
+ let data = unsafe { from_ffi ( array, & schema) } ?;
938
941
let array = make_array ( data) ;
939
942
940
943
// perform some operation
@@ -972,7 +975,7 @@ mod tests {
972
975
}
973
976
974
977
// (simulate consumer) import it
975
- let data = from_ffi ( out_array, & out_schema) ?;
978
+ let data = unsafe { from_ffi ( out_array, & out_schema) } ?;
976
979
let array = make_array ( data) ;
977
980
978
981
// perform some operation
@@ -993,7 +996,7 @@ mod tests {
993
996
let ( array, schema) = to_ffi ( & array. to_data ( ) ) ?;
994
997
995
998
// (simulate consumer) import it
996
- let data = from_ffi ( array, & schema) ?;
999
+ let data = unsafe { from_ffi ( array, & schema) } ?;
997
1000
let array = make_array ( data) ;
998
1001
999
1002
// perform some operation
@@ -1030,7 +1033,7 @@ mod tests {
1030
1033
let ( array, schema) = to_ffi ( & map_array. to_data ( ) ) ?;
1031
1034
1032
1035
// (simulate consumer) import it
1033
- let data = from_ffi ( array, & schema) ?;
1036
+ let data = unsafe { from_ffi ( array, & schema) } ?;
1034
1037
let array = make_array ( data) ;
1035
1038
1036
1039
// perform some operation
@@ -1053,7 +1056,7 @@ mod tests {
1053
1056
let ( array, schema) = to_ffi ( & struct_array. to_data ( ) ) ?;
1054
1057
1055
1058
// (simulate consumer) import it
1056
- let data = from_ffi ( array, & schema) ?;
1059
+ let data = unsafe { from_ffi ( array, & schema) } ?;
1057
1060
let array = make_array ( data) ;
1058
1061
1059
1062
// perform some operation
@@ -1077,7 +1080,7 @@ mod tests {
1077
1080
let ( array, schema) = to_ffi ( & union. to_data ( ) ) ?;
1078
1081
1079
1082
// (simulate consumer) import it
1080
- let data = from_ffi ( array, & schema) ?;
1083
+ let data = unsafe { from_ffi ( array, & schema) } ?;
1081
1084
let array = make_array ( data) ;
1082
1085
1083
1086
let array = array. as_any ( ) . downcast_ref :: < UnionArray > ( ) . unwrap ( ) ;
@@ -1138,7 +1141,7 @@ mod tests {
1138
1141
let ( array, schema) = to_ffi ( & union. to_data ( ) ) ?;
1139
1142
1140
1143
// (simulate consumer) import it
1141
- let data = from_ffi ( array, & schema) ?;
1144
+ let data = unsafe { from_ffi ( array, & schema) } ?;
1142
1145
let array = UnionArray :: from ( data) ;
1143
1146
1144
1147
let expected_type_ids = vec ! [ 0_i8 , 0 , 1 , 0 ] ;
0 commit comments