Skip to content

Commit 12b7fc7

Browse files
authored
Merge pull request RustPython#1359 from RustPython/coolreader18/redox-rustyline
Use the rustyline prompt on redox
2 parents 65c90ab + 6a34a72 commit 12b7fc7

File tree

7 files changed

+143
-227
lines changed

7 files changed

+143
-227
lines changed

Cargo.lock

Lines changed: 112 additions & 156 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ dirs = "2.0"
3131
flame = { version = "0.2", optional = true }
3232
flamescope = { version = "0.1", optional = true }
3333

34-
[target.'cfg(not(target_os = "redox"))'.dependencies]
35-
rustyline = "4.1.0"
34+
rustyline = "=5.0.1"
3635

3736

3837
[dev-dependencies.cpython]
@@ -45,6 +44,5 @@ path = "src/main.rs"
4544
[patch.crates-io]
4645
# REDOX START, Uncommment when you want to compile/check with redoxer
4746
# time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" }
48-
# libc = { git = "https://github.com/AdminXVII/libc", branch = "extra-traits-redox" }
4947
# nix = { git = "https://github.com/AdminXVII/nix", branch = "add-redox-support" }
5048
# REDOX END

src/main.rs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use clap::{App, AppSettings, Arg, ArgMatches};
88
use rustpython_compiler::{compile, error::CompileError, error::CompileErrorType};
99
use rustpython_parser::error::ParseErrorType;
1010
use rustpython_vm::{
11-
import,
12-
obj::objstr::PyStringRef,
13-
print_exception,
11+
import, print_exception,
1412
pyobject::{ItemProtocol, PyObjectRef, PyResult},
1513
scope::Scope,
1614
util, PySettings, VirtualMachine,
@@ -463,13 +461,6 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul
463461
}
464462
}
465463

466-
fn get_prompt(vm: &VirtualMachine, prompt_name: &str) -> Option<PyStringRef> {
467-
vm.get_attribute(vm.sys_module.clone(), prompt_name)
468-
.and_then(|prompt| vm.to_str(&prompt))
469-
.ok()
470-
}
471-
472-
#[cfg(not(target_os = "redox"))]
473464
fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
474465
use rustyline::{error::ReadlineError, Editor};
475466

@@ -505,14 +496,13 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
505496
let mut continuing = false;
506497

507498
loop {
508-
let prompt = if continuing {
509-
get_prompt(vm, "ps2")
510-
} else {
511-
get_prompt(vm, "ps1")
512-
};
499+
let prompt_name = if continuing { "ps2" } else { "ps1" };
500+
let prompt = vm
501+
.get_attribute(vm.sys_module.clone(), prompt_name)
502+
.and_then(|prompt| vm.to_str(&prompt));
513503
let prompt = match prompt {
514-
Some(ref s) => s.as_str(),
515-
None => "",
504+
Ok(ref s) => s.as_str(),
505+
Err(_) => "",
516506
};
517507
let result = match repl.readline(prompt) {
518508
Ok(line) => {
@@ -577,39 +567,3 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
577567

578568
Ok(())
579569
}
580-
581-
#[cfg(target_os = "redox")]
582-
fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
583-
use std::io::{self, BufRead, Write};
584-
585-
println!(
586-
"Welcome to the magnificent Rust Python {} interpreter!",
587-
crate_version!()
588-
);
589-
590-
fn print_prompt(vm: &VirtualMachine) {
591-
let prompt = get_prompt(vm, "ps1");
592-
let prompt = match prompt {
593-
Some(ref s) => s.as_str(),
594-
None => "",
595-
};
596-
print!("{}", prompt);
597-
io::stdout().lock().flush().expect("flush failed");
598-
}
599-
600-
let stdin = io::stdin();
601-
602-
print_prompt(vm);
603-
for line in stdin.lock().lines() {
604-
let mut line = line.expect("line failed");
605-
line.push_str("\n");
606-
match shell_exec(vm, &line, scope.clone()) {
607-
ShellExecResult::Ok => {}
608-
ShellExecResult::Continue => println!("Unexpected EOF"),
609-
ShellExecResult::PyErr(exc) => print_exception(vm, &exc),
610-
}
611-
print_prompt(vm);
612-
}
613-
614-
Ok(())
615-
}

vm/Cargo.toml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ sha2 = "0.8"
2424
sha3 = "0.8"
2525
blake2 = "0.8"
2626

27-
num-complex = { version = "0.2", features = ["serde"] }
28-
num-bigint = { version = "0.2", features = ["serde"] }
29-
num-traits = "0.2.6"
30-
num-integer = "0.1.39"
31-
num-rational = "0.2.1"
32-
num-iter = "0.1"
27+
num-complex = { version = "0.2.2", features = ["serde"] }
28+
num-bigint = { version = "0.2.3", features = ["serde"] }
29+
num-traits = "0.2.8"
30+
num-integer = "0.1.41"
31+
num-rational = "0.2.2"
32+
num-iter = "0.1.39"
3333
rand = "0.5"
3434
log = "0.3"
3535
rustpython-derive = {path = "../derive", version = "0.1.0"}
@@ -43,7 +43,7 @@ regex = "1"
4343
rustc_version_runtime = "0.1.*"
4444
statrs = "0.10.0"
4545
caseless = "0.2.1"
46-
chrono = "=0.4.7"
46+
chrono = "=0.4.6"
4747
unicode-segmentation = "1.2.1"
4848
unicode-xid = "0.1.0"
4949
lazy_static = "^1.0.1"
@@ -83,6 +83,3 @@ num_cpus = "1.0"
8383

8484
[target."cfg(windows)".dependencies]
8585
kernel32-sys = "0.2.2"
86-
87-
[target.'cfg(target_arch = "wasm32")'.dependencies]
88-
wasm-bindgen = "0.2"

vm/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl PyFuncArgs {
131131
}
132132

133133
pub fn take_keyword(&mut self, name: &str) -> Option<PyObjectRef> {
134-
self.kwargs.remove(name)
134+
self.kwargs.swap_remove(name)
135135
}
136136

137137
pub fn remaining_keywords<'a>(

vm/src/stdlib/os.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,12 @@ fn getgroups() -> nix::Result<Vec<Gid>> {
293293
}
294294
}
295295

296-
#[cfg(any(target_os = "linux", target_os = "redox", target_os = "android"))]
296+
#[cfg(any(target_os = "linux", target_os = "android"))]
297+
use nix::unistd::getgroups;
298+
299+
#[cfg(target_os = "redox")]
297300
fn getgroups() -> nix::Result<Vec<Gid>> {
298-
nix::unistd::getgroups()
301+
unimplemented!("redox getgroups")
299302
}
300303

301304
#[cfg(unix)]
@@ -1229,7 +1232,15 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
12291232
"openpty" => ctx.new_rustfunc(os_openpty),
12301233
});
12311234

1232-
#[cfg(not(target_os = "macos"))]
1235+
// cfg taken from nix
1236+
#[cfg(any(
1237+
target_os = "dragonfly",
1238+
target_os = "freebsd",
1239+
all(
1240+
target_os = "linux",
1241+
not(any(target_env = "musl", target_arch = "mips", target_arch = "mips64"))
1242+
)
1243+
))]
12331244
extend_module!(vm, module, {
12341245
"SEEK_DATA" => ctx.new_int(Whence::SeekData as i8),
12351246
"SEEK_HOLE" => ctx.new_int(Whence::SeekHole as i8)

vm/src/stdlib/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn signal(signalnum: i32, handler: PyObjectRef, vm: &VirtualMachine) -> PyResult
5858
if old == SIG_ERR {
5959
return Err(vm.new_os_error("Failed to set signal".to_string()));
6060
}
61-
#[cfg(unix)]
61+
#[cfg(all(unix, not(target_os = "redox")))]
6262
{
6363
extern "C" {
6464
fn siginterrupt(sig: i32, flag: i32);

0 commit comments

Comments
 (0)