1
+ // FIXME #3921. This is unsafe because linenoise uses global mutable
2
+ // state without mutexes.
3
+
1
4
use libc:: { c_char, c_int} ;
2
5
3
6
extern mod rustrt {
@@ -12,33 +15,33 @@ extern mod rustrt {
12
15
}
13
16
14
17
/// Add a line to history
15
- pub fn add_history ( line : ~str ) -> bool {
18
+ pub unsafe fn add_history ( line : ~str ) -> bool {
16
19
do str:: as_c_str ( line) |buf| {
17
20
rustrt:: linenoiseHistoryAdd ( buf) == 1 as c_int
18
21
}
19
22
}
20
23
21
24
/// 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 {
23
26
rustrt:: linenoiseHistorySetMaxLen ( len as c_int ) == 1 as c_int
24
27
}
25
28
26
29
/// Save line history to a file
27
- pub fn save_history ( file : ~str ) -> bool {
30
+ pub unsafe fn save_history ( file : ~str ) -> bool {
28
31
do str:: as_c_str ( file) |buf| {
29
32
rustrt:: linenoiseHistorySave ( buf) == 1 as c_int
30
33
}
31
34
}
32
35
33
36
/// Load line history from a file
34
- pub fn load_history ( file : ~str ) -> bool {
37
+ pub unsafe fn load_history ( file : ~str ) -> bool {
35
38
do str:: as_c_str ( file) |buf| {
36
39
rustrt:: linenoiseHistoryLoad ( buf) == 1 as c_int
37
40
}
38
41
}
39
42
40
43
/// 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 > {
42
45
do str:: as_c_str ( prompt) |buf| unsafe {
43
46
let line = rustrt:: linenoise ( buf) ;
44
47
@@ -52,7 +55,7 @@ pub type CompletionCb = fn~(~str, fn(~str));
52
55
fn complete_key ( _v : @CompletionCb ) { }
53
56
54
57
/// Bind to the main completion callback
55
- pub fn complete ( cb : CompletionCb ) unsafe {
58
+ pub unsafe fn complete ( cb : CompletionCb ) unsafe {
56
59
task:: local_data:: local_data_set ( complete_key, @( move cb) ) ;
57
60
58
61
extern fn callback ( line : * c_char , completions : * ( ) ) unsafe {
0 commit comments