Created
March 31, 2016 09:43
-
-
Save sargun/e665eb598aec0aaa5465fd330c6e2607 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
int pants() { | |
char *foo = crud(); | |
printf("Crud: %s\n", foo); | |
rust_free(foo); | |
} |
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
#[no_mangle] | |
pub extern fn crud() -> *const u8 { | |
Box::new("Hello!\0").as_ptr() | |
} | |
#[no_mangle] | |
pub extern fn rust_free(mem : *mut u8) { | |
unsafe { | |
drop(Box::from_raw(mem)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment