Last active
November 2, 2016 03:45
-
-
Save mzumi/a1fc670bb0267b228904f29f62a286f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(libc)] | |
extern crate libc; | |
use libc::*; | |
use std::ffi::{CStr, CString}; | |
#[repr(C)] | |
pub struct SampleStruct { | |
i: i32, | |
b: bool, | |
s: *const c_char | |
} | |
#[no_mangle] | |
pub extern fn create_sample_struct() -> *mut SampleStruct { | |
let b = Box::new(SampleStruct { | |
i: 1, | |
b: true, | |
s: CString::new("hello").unwrap().into_raw() | |
}); | |
Box::into_raw(b) | |
} | |
#[no_mangle] | |
pub extern fn free_sample_struct(s: *mut SampleStruct) { | |
unsafe { | |
drop(Box::from_raw(s)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment