I am struggling using ffi to call an external C function and return a struct allocated in the function. I am using a u64 handle from a previously call and passing it in to the function. The prototype (rust) looks as follows :
extern "C" {
fn Get_MetaData(handle : u64, name : *const c_char) -> * const MetaDataList;
}
Rust Structures
#[repr(C)]
pub struct Attribute {
name: *mut c_char,
r#type : i32,
length : i32
}
#[repr(C)]
pub struct MetaData {
name: *mut c_char,
r#objectid : i32,
r#count : i32,
attributes : [*mut Attribute]
}
#[repr(C)]
pub struct MetaDataList {
r#count : i32,
metadatalist : [*mut MetaData]
}
When I call the function I see the handle is the correct on the calling side, however, when it is received in the 'C' side it is corrupted.
Calling get_metdata with handle 2023188093856 <- Rust
Rebar_Get_MetaData - Handle 584424880536 <- 'C'
If I change the return type from * const MetaDataList to u64 it works (but I canot cast u64 return into a * const MetaDataList).
Does anyone have any insight?