Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions crates/vm/src/stdlib/_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6643,7 +6643,8 @@ mod winconsoleio {
builtins::{PyBaseExceptionRef, PyUtf8StrRef},
common::{lock::PyMutex, wtf8::Wtf8Buf},
convert::{IntoPyException, ToPyException},
function::{ArgBytesLike, ArgMemoryBuffer},
exceptions::nul_char_error,
function::{ArgBytesLike, ArgMemoryBuffer, OptionalArg},
types::{Constructor, DefaultConstructor, Destructor, Initializer, Representable},
};
use crossbeam_utils::atomic::AtomicCell;
Expand Down Expand Up @@ -6717,8 +6718,8 @@ mod winconsoleio {
pub(super) struct WindowsConsoleIOArgs {
#[pyarg(positional)]
name: PyObjectRef,
#[pyarg(any, default)]
mode: Option<PyUtf8StrRef>,
#[pyarg(any, optional, py_default = "'r'")]
mode: OptionalArg<Option<PyUtf8StrRef>>,
#[pyarg(any, default = true)]
closefd: bool,
#[allow(dead_code)]
Expand All @@ -6730,6 +6731,19 @@ mod winconsoleio {
type Args = WindowsConsoleIOArgs;

fn init(zelf: &Py<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
let mode_str = match &args.mode {
OptionalArg::Present(Some(mode)) => mode.as_str(),
OptionalArg::Present(None) => {
return Err(vm.new_type_error(
"_WindowsConsoleIO() argument 'mode' must be str, not None",
));
}
OptionalArg::Missing => "r",
};
if mode_str.contains('\0') {
return Err(nul_char_error(vm));
}
Comment on lines +6743 to +6745

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there must be a helper for this


let nameobj = args.name;

if zelf.fd.load() >= 0 {
Expand Down Expand Up @@ -6760,8 +6774,6 @@ mod winconsoleio {
}

// Parse mode
let mode_str: &str = args.mode.as_deref().map_or("r", |s| s.as_str());

let mut rwa = false;
let mut readable = false;
let mut writable = false;
Expand Down
Loading