Skip to content

Commit 9aadfc3

Browse files
committed
Make std::rl unsafe. #3921
1 parent c8b4dea commit 9aadfc3

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/librusti/rusti.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,18 @@ pub fn main() {
267267
stmts: ~""
268268
};
269269

270-
do rl::complete |line, suggest| {
271-
if line.starts_with(":") {
272-
suggest(~":clear");
273-
suggest(~":exit");
274-
suggest(~":help");
270+
unsafe {
271+
do rl::complete |line, suggest| {
272+
if line.starts_with(":") {
273+
suggest(~":clear");
274+
suggest(~":exit");
275+
suggest(~":help");
276+
}
275277
}
276278
}
277279

278280
while repl.running {
279-
let result = rl::read(repl.prompt);
281+
let result = unsafe { rl::read(repl.prompt) };
280282

281283
if result.is_none() {
282284
break;
@@ -290,7 +292,7 @@ pub fn main() {
290292
loop;
291293
}
292294

293-
rl::add_history(line);
295+
unsafe { rl::add_history(line) };
294296

295297
if line.starts_with(~":") {
296298
let full = line.substr(1, line.len() - 1);

src/libstd/rl.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME #3921. This is unsafe because linenoise uses global mutable
2+
// state without mutexes.
3+
14
use libc::{c_char, c_int};
25

36
extern mod rustrt {
@@ -12,33 +15,33 @@ extern mod rustrt {
1215
}
1316

1417
/// Add a line to history
15-
pub fn add_history(line: ~str) -> bool {
18+
pub unsafe fn add_history(line: ~str) -> bool {
1619
do str::as_c_str(line) |buf| {
1720
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
1821
}
1922
}
2023

2124
/// Set the maximum amount of lines stored
22-
pub fn set_history_max_len(len: int) -> bool {
25+
pub unsafe fn set_history_max_len(len: int) -> bool {
2326
rustrt::linenoiseHistorySetMaxLen(len as c_int) == 1 as c_int
2427
}
2528

2629
/// Save line history to a file
27-
pub fn save_history(file: ~str) -> bool {
30+
pub unsafe fn save_history(file: ~str) -> bool {
2831
do str::as_c_str(file) |buf| {
2932
rustrt::linenoiseHistorySave(buf) == 1 as c_int
3033
}
3134
}
3235

3336
/// Load line history from a file
34-
pub fn load_history(file: ~str) -> bool {
37+
pub unsafe fn load_history(file: ~str) -> bool {
3538
do str::as_c_str(file) |buf| {
3639
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
3740
}
3841
}
3942

4043
/// Print out a prompt and then wait for input and return it
41-
pub fn read(prompt: ~str) -> Option<~str> {
44+
pub unsafe fn read(prompt: ~str) -> Option<~str> {
4245
do str::as_c_str(prompt) |buf| unsafe {
4346
let line = rustrt::linenoise(buf);
4447

@@ -52,7 +55,7 @@ pub type CompletionCb = fn~(~str, fn(~str));
5255
fn complete_key(_v: @CompletionCb) {}
5356

5457
/// Bind to the main completion callback
55-
pub fn complete(cb: CompletionCb) unsafe {
58+
pub unsafe fn complete(cb: CompletionCb) unsafe {
5659
task::local_data::local_data_set(complete_key, @(move cb));
5760

5861
extern fn callback(line: *c_char, completions: *()) unsafe {

0 commit comments

Comments
 (0)