Skip to content

Commit ead2a39

Browse files
committed
Update nix and rustyline
1 parent d146cdb commit ead2a39

File tree

8 files changed

+37
-85
lines changed

8 files changed

+37
-85
lines changed

Cargo.lock

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ flame = { version = "0.2.2", optional = true }
4949
flamescope = { version = "0.1.2", optional = true }
5050

5151
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
52-
rustyline = "9.1.2"
52+
rustyline = "10.0.0"
5353

5454
[dev-dependencies]
5555
cpython = "0.7.0"

src/shell.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
112112
ReadlineResult::Eof => {
113113
break;
114114
}
115-
ReadlineResult::EncodingError => {
116-
eprintln!("Invalid UTF-8 entered");
117-
Ok(())
118-
}
119115
ReadlineResult::Other(err) => {
120116
eprintln!("Readline error: {:?}", err);
121117
break;

stdlib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ base64 = "0.13.0"
5656
csv-core = "0.1.10"
5757
hex = "0.4.3"
5858
puruspe = "0.1.5"
59-
nix = "0.23.1"
59+
nix = "0.24"
6060
xml-rs = "0.8.4"
6161
libc = "0.2.126"
6262
cfg-if = "1.0.0"

stdlib/src/socket.rs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ mod _socket {
20842084
fn if_nameindex(vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {
20852085
#[cfg(not(windows))]
20862086
{
2087-
let list = if_nameindex()
2087+
let list = nix::net::if_::if_nameindex()
20882088
.map_err(|err| err.into_pyexception(vm))?
20892089
.to_slice()
20902090
.iter()
@@ -2095,55 +2095,7 @@ mod _socket {
20952095
})
20962096
.collect();
20972097

2098-
return Ok(list);
2099-
2100-
// all the stuff below should be in nix soon, hopefully
2101-
2102-
use ffi::CStr;
2103-
use std::ptr::NonNull;
2104-
2105-
#[repr(transparent)]
2106-
struct Interface(libc::if_nameindex);
2107-
2108-
impl Interface {
2109-
fn index(&self) -> libc::c_uint {
2110-
self.0.if_index
2111-
}
2112-
fn name(&self) -> &CStr {
2113-
unsafe { CStr::from_ptr(self.0.if_name) }
2114-
}
2115-
}
2116-
2117-
struct Interfaces {
2118-
ptr: NonNull<libc::if_nameindex>,
2119-
}
2120-
2121-
impl Interfaces {
2122-
fn to_slice(&self) -> &[Interface] {
2123-
let ifs = self.ptr.as_ptr() as *const Interface;
2124-
let mut len = 0;
2125-
unsafe {
2126-
while (*ifs.add(len)).0.if_index != 0 {
2127-
len += 1
2128-
}
2129-
std::slice::from_raw_parts(ifs, len)
2130-
}
2131-
}
2132-
}
2133-
2134-
impl Drop for Interfaces {
2135-
fn drop(&mut self) {
2136-
unsafe { libc::if_freenameindex(self.ptr.as_ptr()) };
2137-
}
2138-
}
2139-
2140-
fn if_nameindex() -> nix::Result<Interfaces> {
2141-
unsafe {
2142-
let ifs = libc::if_nameindex();
2143-
let ptr = NonNull::new(ifs).ok_or_else(nix::Error::last)?;
2144-
Ok(Interfaces { ptr })
2145-
}
2146-
}
2098+
Ok(list)
21472099
}
21482100
#[cfg(windows)]
21492101
{

vm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ indexmap = "1.8.1"
5050
ahash = "0.7.6"
5151
bitflags = "1.3.2"
5252
libc = "0.2.126"
53-
nix = "0.23.1"
53+
nix = "0.24.2"
5454
paste = "1.0.7"
5555
is-macro = "0.2.0"
5656
result-like = "0.4.5"
@@ -101,7 +101,7 @@ strum = "0.24.0"
101101
strum_macros = "0.24.0"
102102

103103
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
104-
rustyline = "9"
104+
rustyline = "10.0.0"
105105
which = "4.2.5"
106106

107107
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]

vm/src/readline.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub enum ReadlineResult {
88
Eof,
99
Interrupt,
1010
Io(std::io::Error),
11-
EncodingError,
1211
Other(OtherError),
1312
}
1413

@@ -51,11 +50,8 @@ mod basic_readline {
5150
match next_line {
5251
Some(Ok(line)) => ReadlineResult::Line(line),
5352
None => ReadlineResult::Eof,
54-
Some(Err(e)) => match e.kind() {
55-
io::ErrorKind::Interrupted => ReadlineResult::Interrupt,
56-
io::ErrorKind::InvalidData => ReadlineResult::EncodingError,
57-
_ => ReadlineResult::Io(e),
58-
},
53+
Some(Err(e)) if e.kind() == io::ErrorKind::Interrupted => ReadlineResult::Interrupt,
54+
Some(Err(e)) => ReadlineResult::Io(e),
5955
}
6056
}
6157
}
@@ -82,7 +78,8 @@ mod rustyline_readline {
8278
.tab_stop(8)
8379
.bracketed_paste(false) // multi-line paste
8480
.build(),
85-
);
81+
)
82+
.expect("failed to initialize line editor");
8683
repl.set_helper(Some(helper));
8784
Readline { repl }
8885
}
@@ -109,16 +106,15 @@ mod rustyline_readline {
109106

110107
pub fn readline(&mut self, prompt: &str) -> ReadlineResult {
111108
use rustyline::error::ReadlineError;
112-
match self.repl.readline(prompt) {
113-
Ok(line) => ReadlineResult::Line(line),
114-
Err(ReadlineError::Interrupted) => ReadlineResult::Interrupt,
115-
Err(ReadlineError::Eof) => ReadlineResult::Eof,
116-
Err(ReadlineError::Io(e)) => ReadlineResult::Io(e),
117-
#[cfg(unix)]
118-
Err(ReadlineError::Utf8Error) => ReadlineResult::EncodingError,
119-
#[cfg(windows)]
120-
Err(ReadlineError::Decode(_)) => ReadlineResult::EncodingError,
121-
Err(e) => ReadlineResult::Other(e.into()),
109+
loop {
110+
break match self.repl.readline(prompt) {
111+
Ok(line) => ReadlineResult::Line(line),
112+
Err(ReadlineError::Interrupted) => ReadlineResult::Interrupt,
113+
Err(ReadlineError::Eof) => ReadlineResult::Eof,
114+
Err(ReadlineError::Io(e)) => ReadlineResult::Io(e),
115+
Err(ReadlineError::WindowResized) => continue,
116+
Err(e) => ReadlineResult::Other(e.into()),
117+
};
122118
}
123119
}
124120
}

vm/src/stdlib/builtins.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,6 @@ mod builtins {
402402
Err(vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.to_owned()))
403403
}
404404
ReadlineResult::Io(e) => Err(vm.new_os_error(e.to_string())),
405-
ReadlineResult::EncodingError => {
406-
Err(vm.new_unicode_decode_error("Error decoding readline input".to_owned()))
407-
}
408405
ReadlineResult::Other(e) => Err(vm.new_runtime_error(e.to_string())),
409406
}
410407
} else {

0 commit comments

Comments
 (0)