tustvold commented on code in PR #5080:
URL: https://github.com/apache/arrow-rs/pull/5080#discussion_r1395521974
##########
arrow-integration-testing/src/lib.rs:
##########
@@ -100,3 +166,147 @@ pub fn read_gzip_json(version: &str, path: &str) ->
ArrowJson {
let arrow_json: ArrowJson = serde_json::from_str(&s).unwrap();
arrow_json
}
+
+//
+// C Data Integration entrypoints
+//
+
+fn cdata_integration_export_schema_from_json(
+ c_json_name: *const i8,
+ out: *mut FFI_ArrowSchema,
+) -> Result<()> {
+ let json_name = unsafe { CStr::from_ptr(c_json_name) };
+ let f = read_json_file_metadata(json_name.to_str()?)?;
+ let c_schema = FFI_ArrowSchema::try_from(&f.schema)?;
+ // Move exported schema into output struct
+ unsafe { ptr::write(out, c_schema) };
+ Ok(())
+}
+
+fn cdata_integration_export_batch_from_json(
+ c_json_name: *const i8,
+ batch_num: c_int,
+ out: *mut FFI_ArrowArray,
+) -> Result<()> {
+ let json_name = unsafe { CStr::from_ptr(c_json_name) };
+ let b = read_single_batch_from_json_file(json_name.to_str()?,
batch_num.try_into().unwrap())?;
+ let a = StructArray::from(b).into_data();
+ let c_array = FFI_ArrowArray::new(&a);
+ // Move exported array into output struct
+ unsafe { ptr::write(out, c_array) };
+ Ok(())
+}
+
+fn cdata_integration_import_schema_and_compare_to_json(
+ c_json_name: *const i8,
+ c_schema: *mut FFI_ArrowSchema,
+) -> Result<()> {
+ let json_name = unsafe { CStr::from_ptr(c_json_name) };
+ let json_schema = read_json_file_metadata(json_name.to_str()?)?.schema;
+
+ // The source ArrowSchema will be released when this is dropped
+ let imported_schema = unsafe { std::ptr::replace(c_schema,
FFI_ArrowSchema::empty()) };
Review Comment:
Is that not a bug in archery, perhaps I've been marinating in Rust for too
long, but passing ownership with a pointer seems to be relying on very weak
implicit guarantees? What happens if the function bails out before taking
ownership or something? I would have expected it to call release unless the
data had been moved out?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]