diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-05 11:20:44 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-05 11:20:44 -0800 |
| commit | 9aadfc3f4b5df00a7f8e9b362385118ae1dba73e (patch) | |
| tree | edda9195b44db34bf95e2af66c8246f0fd14a987 | |
| parent | c8b4dea4e0261b1e8c079c1fcf3c61ea9cc15e6e (diff) | |
| download | rust-9aadfc3f4b5df00a7f8e9b362385118ae1dba73e.tar.gz rust-9aadfc3f4b5df00a7f8e9b362385118ae1dba73e.zip | |
Make std::rl unsafe. #3921
| -rw-r--r-- | src/librusti/rusti.rs | 16 | ||||
| -rw-r--r-- | src/libstd/rl.rs | 15 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index 8bb52591d61..2f1079d83fc 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -267,16 +267,18 @@ pub fn main() { stmts: ~"" }; - do rl::complete |line, suggest| { - if line.starts_with(":") { - suggest(~":clear"); - suggest(~":exit"); - suggest(~":help"); + unsafe { + do rl::complete |line, suggest| { + if line.starts_with(":") { + suggest(~":clear"); + suggest(~":exit"); + suggest(~":help"); + } } } while repl.running { - let result = rl::read(repl.prompt); + let result = unsafe { rl::read(repl.prompt) }; if result.is_none() { break; @@ -290,7 +292,7 @@ pub fn main() { loop; } - rl::add_history(line); + unsafe { rl::add_history(line) }; if line.starts_with(~":") { let full = line.substr(1, line.len() - 1); diff --git a/src/libstd/rl.rs b/src/libstd/rl.rs index dc098586382..943fecb4115 100644 --- a/src/libstd/rl.rs +++ b/src/libstd/rl.rs @@ -1,3 +1,6 @@ +// FIXME #3921. This is unsafe because linenoise uses global mutable +// state without mutexes. + use libc::{c_char, c_int}; extern mod rustrt { @@ -12,33 +15,33 @@ extern mod rustrt { } /// Add a line to history -pub fn add_history(line: ~str) -> bool { +pub unsafe fn add_history(line: ~str) -> bool { do str::as_c_str(line) |buf| { rustrt::linenoiseHistoryAdd(buf) == 1 as c_int } } /// Set the maximum amount of lines stored -pub fn set_history_max_len(len: int) -> bool { +pub unsafe fn set_history_max_len(len: int) -> bool { rustrt::linenoiseHistorySetMaxLen(len as c_int) == 1 as c_int } /// Save line history to a file -pub fn save_history(file: ~str) -> bool { +pub unsafe fn save_history(file: ~str) -> bool { do str::as_c_str(file) |buf| { rustrt::linenoiseHistorySave(buf) == 1 as c_int } } /// Load line history from a file -pub fn load_history(file: ~str) -> bool { +pub unsafe fn load_history(file: ~str) -> bool { do str::as_c_str(file) |buf| { rustrt::linenoiseHistoryLoad(buf) == 1 as c_int } } /// Print out a prompt and then wait for input and return it -pub fn read(prompt: ~str) -> Option<~str> { +pub unsafe fn read(prompt: ~str) -> Option<~str> { do str::as_c_str(prompt) |buf| unsafe { let line = rustrt::linenoise(buf); @@ -52,7 +55,7 @@ pub type CompletionCb = fn~(~str, fn(~str)); fn complete_key(_v: @CompletionCb) {} /// Bind to the main completion callback -pub fn complete(cb: CompletionCb) unsafe { +pub unsafe fn complete(cb: CompletionCb) unsafe { task::local_data::local_data_set(complete_key, @(move cb)); extern fn callback(line: *c_char, completions: *()) unsafe { |
