Always set OSError.errno; have it be None instead of missing

This commit is contained in:
coolreader18
2019-12-04 23:20:59 -06:00
parent 5c5a7984ca
commit 4cf49efda1
2 changed files with 6 additions and 4 deletions

View File

@@ -169,6 +169,7 @@ const ERROR_CODES: &[(&str, i32)] = &[
e!(EINPROGRESS),
e!(ENXIO),
e!(ECANCELED),
e!(EWOULDBLOCK),
e!(cfg(not(windows)), EOWNERDEAD),
e!(cfg(not(windows)), ENOTRECOVERABLE),
e!(cfg(windows), WSAEAFNOSUPPORT),

View File

@@ -171,10 +171,11 @@ pub fn convert_io_error(vm: &VirtualMachine, err: io::Error) -> PyObjectRef {
},
};
let os_error = vm.new_exception(exc_type, err.to_string());
if let Some(errno) = err.raw_os_error() {
vm.set_attr(&os_error, "errno", vm.ctx.new_int(errno))
.unwrap();
}
let errno = match err.raw_os_error() {
Some(errno) => vm.new_int(errno),
None => vm.get_none(),
};
vm.set_attr(&os_error, "errno", errno).unwrap();
os_error
}