mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
direct call io_open for initialization
This commit is contained in:
1 parent
d54cfaf3f4
commit
91eb4d42e0
2 files changed
+8
-2
No files matched your search
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
use crate::pyobject::PyObjectRef;
|
||||
use crate::VirtualMachine;
|
||||
pub(crate) use _io::io_open as open;
|
||||
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = _io::make_module(vm);
|
||||
|
||||
+7
-2
@@ -320,9 +320,13 @@ impl VirtualMachine {
|
||||
// builtins.open to io.OpenWrapper, but this is easier, since it doesn't
|
||||
// require the Python stdlib to be present
|
||||
let io = import::import_builtin(self, "_io")?;
|
||||
let io_open = self.get_attribute(io, "open")?;
|
||||
let set_stdio = |name, fd, mode: &str| {
|
||||
let stdio = self.invoke(&io_open, (fd, mode))?;
|
||||
let stdio = crate::stdlib::io::open(
|
||||
self.ctx.new_int(fd),
|
||||
Some(mode),
|
||||
Default::default(),
|
||||
self,
|
||||
)?;
|
||||
self.set_attr(
|
||||
&self.sys_module,
|
||||
format!("__{}__", name), // e.g. __stdin__
|
||||
@@ -335,6 +339,7 @@ impl VirtualMachine {
|
||||
set_stdio("stdout", 1, "w")?;
|
||||
set_stdio("stderr", 2, "w")?;
|
||||
|
||||
let io_open = self.get_attribute(io, "open")?;
|
||||
self.set_attr(&self.builtins, "open", io_open)?;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user