C構造体のポインタをRUSTで扱うには
下記の様なC構造体のポインターをRUSTで扱うにはどうすれば良いですか?
c code.
typedef struct {
int value;
} DATA;
DATA* new_data(){
return (DATA*)malloc(sizeof(DATA));
}
void del_data(DATA* data){
free(data);
}
下記の様に試したのですが、errorが取れません.
malloc: *** error for object 0x700002fba9b0: pointer being freed was not allocated
malloc: *** set a breakpoint in malloc_error_break to debug
rust code
#[repr(C)]
pub struct DATA {
count: u32
}
#[link(name = "clibrary", kind = "static")]
extern "C" {
fn new_data() -> *mut DATA;
fn del_data(data: *mut DATA);
}
fn main(){
unsafe{
let raw = new_data();
del_data(raw);
}