@@ -30,46 +30,59 @@ pub mod rustrt {
30
30
31
31
macro_rules! locked {
32
32
( $expr: expr) => {
33
- // FIXME #9105: can't use a static mutex in pure Rust yet.
34
- rustrt:: rust_take_linenoise_lock( ) ;
35
- let x = $expr;
36
- rustrt:: rust_drop_linenoise_lock( ) ;
37
- x
33
+ {
34
+ // FIXME #9105: can't use a static mutex in pure Rust yet.
35
+ rustrt:: rust_take_linenoise_lock( ) ;
36
+ let x = $expr;
37
+ rustrt:: rust_drop_linenoise_lock( ) ;
38
+ x
39
+ }
38
40
}
39
41
}
40
42
41
43
/// Add a line to history
42
44
pub fn add_history ( line : & str ) -> bool {
43
45
do line. with_c_str |buf| {
44
- ( locked ! ( rustrt:: linenoiseHistoryAdd( buf) ) ) == 1 as c_int
46
+ unsafe {
47
+ ( locked ! ( rustrt:: linenoiseHistoryAdd( buf) ) ) == 1 as c_int
48
+ }
45
49
}
46
50
}
47
51
48
52
/// Set the maximum amount of lines stored
49
53
pub fn set_history_max_len ( len : int ) -> bool {
50
- ( locked ! ( rustrt:: linenoiseHistorySetMaxLen( len as c_int) ) ) == 1 as c_int
54
+ unsafe {
55
+ ( locked ! ( rustrt:: linenoiseHistorySetMaxLen( len as c_int) ) ) == 1
56
+ as c_int
57
+ }
51
58
}
52
59
53
60
/// Save line history to a file
54
61
pub fn save_history ( file : & str ) -> bool {
55
62
do file. with_c_str |buf| {
56
63
// 0 on success, -1 on failure
57
- ( locked ! ( rustrt:: linenoiseHistorySave( buf) ) ) == 0 as c_int
64
+ unsafe {
65
+ ( locked ! ( rustrt:: linenoiseHistorySave( buf) ) ) == 0 as c_int
66
+ }
58
67
}
59
68
}
60
69
61
70
/// Load line history from a file
62
71
pub fn load_history ( file : & str ) -> bool {
63
72
do file. with_c_str |buf| {
64
73
// 0 on success, -1 on failure
65
- ( locked ! ( rustrt:: linenoiseHistoryLoad( buf) ) ) == 0 as c_int
74
+ unsafe {
75
+ ( locked ! ( rustrt:: linenoiseHistoryLoad( buf) ) ) == 0 as c_int
76
+ }
66
77
}
67
78
}
68
79
69
80
/// Print out a prompt and then wait for input and return it
70
81
pub fn read ( prompt : & str ) -> Option < ~str > {
71
82
do prompt. with_c_str |buf| {
72
- let line = locked ! ( rustrt:: linenoise( buf) ) ;
83
+ let line = unsafe {
84
+ locked ! ( rustrt:: linenoise( buf) )
85
+ } ;
73
86
74
87
if line. is_null ( ) { None }
75
88
else {
0 commit comments