mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-25 23:14:12 +00:00
Rollup merge of #22295 - steveklabnik:gh9980, r=alexcrichton
Fixes #9980
This commit is contained in:
commit
0f66e314db
@ -420,7 +420,7 @@ fn main() {
|
||||
```
|
||||
|
||||
Alternatively, you may need to alter global state provided by a foreign
|
||||
interface. To do this, statics can be declared with `mut` so rust can mutate
|
||||
interface. To do this, statics can be declared with `mut` so we can mutate
|
||||
them.
|
||||
|
||||
```no_run
|
||||
@ -436,12 +436,19 @@ extern {
|
||||
|
||||
fn main() {
|
||||
let prompt = CString::from_slice(b"[my-awesome-shell] $");
|
||||
unsafe { rl_prompt = prompt.as_ptr(); }
|
||||
// get a line, process it
|
||||
unsafe { rl_prompt = ptr::null(); }
|
||||
unsafe {
|
||||
rl_prompt = prompt.as_ptr();
|
||||
|
||||
println!("{}", rl_prompt);
|
||||
|
||||
rl_prompt = ptr::null();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that all interaction with a `static mut` is unsafe, both reading and
|
||||
writing. Dealing with global mutable state requires a great deal of care.
|
||||
|
||||
# Foreign calling conventions
|
||||
|
||||
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when
|
||||
|
Loading…
Reference in New Issue
Block a user