Skip to content

Instantly share code, notes, and snippets.

@smaximov
Created January 24, 2016 15:23
Show Gist options
  • Save smaximov/927761521ae9d7b78bb8 to your computer and use it in GitHub Desktop.
Save smaximov/927761521ae9d7b78bb8 to your computer and use it in GitHub Desktop.
Rust FFI
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.
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) };
// ...
}
#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