Created
January 24, 2016 15:23
-
-
Save smaximov/927761521ae9d7b78bb8 to your computer and use it in GitHub Desktop.
Rust FFI
This file contains hidden or 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
Compiling sample v0.1.0 (file:///tmp/sample) | |
main.rs:11:23: 11:26 error: cannot borrow immutable local variable `str` as mutable | |
main.rs:11 unsafe { foo(&mut str) }; | |
^~~ | |
error: aborting due to previous error | |
Could not compile `sample`. | |
To learn more, run the command again with --verbose. |
This file contains hidden or 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
use std::os::raw::c_char; | |
use std::ptr::{null_mut}; | |
#[link(name="sample")] | |
extern { | |
fn foo(_: *mut *mut c_char); | |
} | |
fn main() { | |
let str: *mut c_char = null_mut(); | |
unsafe { foo(&mut str) }; | |
// ... | |
} |
This file contains hidden or 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
#ifndef _SAMPLE_H | |
#define _SAMPLE_H | |
void foo(char **pbuf); | |
#endif /* _SAMPLE_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment