Skip to content

Commit 91eb4d4

Browse files
committed
direct call io_open for initialization
1 parent d54cfaf commit 91eb4d4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

vm/src/stdlib/io.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
use crate::pyobject::PyObjectRef;
55
use crate::VirtualMachine;
6+
pub(crate) use _io::io_open as open;
67

78
pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
89
let module = _io::make_module(vm);

vm/src/vm.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,13 @@ impl VirtualMachine {
320320
// builtins.open to io.OpenWrapper, but this is easier, since it doesn't
321321
// require the Python stdlib to be present
322322
let io = import::import_builtin(self, "_io")?;
323-
let io_open = self.get_attribute(io, "open")?;
324323
let set_stdio = |name, fd, mode: &str| {
325-
let stdio = self.invoke(&io_open, (fd, mode))?;
324+
let stdio = crate::stdlib::io::open(
325+
self.ctx.new_int(fd),
326+
Some(mode),
327+
Default::default(),
328+
self,
329+
)?;
326330
self.set_attr(
327331
&self.sys_module,
328332
format!("__{}__", name), // e.g. __stdin__
@@ -335,6 +339,7 @@ impl VirtualMachine {
335339
set_stdio("stdout", 1, "w")?;
336340
set_stdio("stderr", 2, "w")?;
337341

342+
let io_open = self.get_attribute(io, "open")?;
338343
self.set_attr(&self.builtins, "open", io_open)?;
339344
}
340345

0 commit comments

Comments
 (0)