Skip to content

Commit 32f1f51

Browse files
committed
---
yaml --- r: 79859 b: refs/heads/master c: 4ed5fcb h: refs/heads/master i: 79857: 5a98009 79855: 2039d4e v: v3
1 parent 9ec723e commit 32f1f51

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fe03d827a4910c561507be0802bb5f39a477cc02
2+
refs/heads/master: 4ed5fcb122870d5b0876b32e2dffeb4ea2bd6aed
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 54ae2800ffb30513f89ce13d27ac3c8d095d98ac
55
refs/heads/try: 71bebebc37fbb229877da88dde13c2f35913bd77

trunk/src/libextra/rl.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ pub fn set_history_max_len(len: int) -> bool {
7474
/// Save line history to a file
7575
pub fn save_history(file: &str) -> bool {
7676
do file.with_c_str |buf| {
77-
(locked!(rustrt::linenoiseHistorySave(buf))) == 1 as c_int
77+
// 0 on success, -1 on failure
78+
(locked!(rustrt::linenoiseHistorySave(buf))) == 0 as c_int
7879
}
7980
}
8081

8182
/// Load line history from a file
8283
pub fn load_history(file: &str) -> bool {
8384
do file.with_c_str |buf| {
84-
(locked!(rustrt::linenoiseHistoryLoad(buf))) == 1 as c_int
85+
// 0 on success, -1 on failure
86+
(locked!(rustrt::linenoiseHistoryLoad(buf))) == 0 as c_int
8587
}
8688
}
8789

@@ -107,29 +109,35 @@ pub fn read(prompt: &str) -> Option<~str> {
107109

108110
pub type CompletionCb = @fn(~str, @fn(~str));
109111

110-
static complete_key: local_data::Key<@CompletionCb> = &local_data::Key;
112+
static complete_key: local_data::Key<CompletionCb> = &local_data::Key;
111113

112-
/// Bind to the main completion callback.
114+
/// Bind to the main completion callback in the current task.
113115
///
114116
/// The completion callback should not call any `extra::rl` functions
115117
/// other than the closure that it receives as its second
116118
/// argument. Calling such a function will deadlock on the mutex used
117119
/// to ensure that the calls are thread-safe.
118120
pub fn complete(cb: CompletionCb) {
119-
local_data::set(complete_key, @cb);
120-
121-
extern fn callback(line: *c_char, completions: *()) {
122-
do local_data::get(complete_key) |cb| {
123-
let cb = **cb.unwrap();
124-
125-
unsafe {
126-
do cb(str::raw::from_c_str(line)) |suggestion| {
127-
do suggestion.with_c_str |buf| {
128-
// This isn't locked, because `callback` gets
129-
// called inside `rustrt::linenoise`, which
130-
// *is* already inside the mutex, so
131-
// re-locking would be a deadlock.
132-
rustrt::linenoiseAddCompletion(completions, buf);
121+
local_data::set(complete_key, cb);
122+
123+
extern fn callback(c_line: *c_char, completions: *()) {
124+
do local_data::get(complete_key) |opt_cb| {
125+
// only fetch completions if a completion handler has been
126+
// registered in the current task.
127+
match opt_cb {
128+
None => {},
129+
Some(cb) => {
130+
let line = unsafe { str::raw::from_c_str(c_line) };
131+
do (*cb)(line) |suggestion| {
132+
do suggestion.with_c_str |buf| {
133+
// This isn't locked, because `callback` gets
134+
// called inside `rustrt::linenoise`, which
135+
// *is* already inside the mutex, so
136+
// re-locking would be a deadlock.
137+
unsafe {
138+
rustrt::linenoiseAddCompletion(completions, buf);
139+
}
140+
}
133141
}
134142
}
135143
}

0 commit comments

Comments
 (0)