-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows 7: std::io::last_os_error is set after printing to stdout #53155
Comments
Additional info: I am using stable rust 1.28 |
Works for me on Windows 10:
Can't test Windows 7 :( sorry |
Does it occur more than once? (e.g. can you reproduce it?) |
Yes, this happens every time I execute the program |
("Das Handle ist ungültig" means "The handle is invalid" in English) |
Seems like it could be this call: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/stdio.rs#L43-L46 |
Windows system functions generally guarantee that they will set the last error when they fail, but offer no guarantees as to the state of the last error when they succeed (some may clear the error, some may leave it alone, some may change it). The only action that Rust could take here is for any libstd function that calls system functions to clear the last error when it returns success. |
@sfackler I'm using Maybe we should I understand this is not really a bug (if the function errors, we have a pipe, otherwise a terminal), but perhaps we can reduce the confusion if we reset the OS error in the former case. |
Personally I'd rather that Rust offer no guarantees about the result of There is a case to be made here about documenting this though. |
Triage:
I agree, though we should get @rust-lang/libs signoff before re-categorizing this bug. |
Same problem. As I see line break affects. Normal: let mut stdout = stdout();
stdout.write_fmt(format_args!("{}", unsafe { winapi::um::errhandlingapi::GetLastError() }));
stdout.write_fmt(format_args!("{}", unsafe { winapi::um::errhandlingapi::GetLastError() })); Normal: print!("{}", Error::last_os_error());
print!("{}", Error::last_os_error()); Bug: let mut stdout = stdout();
stdout.write_fmt(format_args!("{}\n", unsafe { winapi::um::errhandlingapi::GetLastError() }));
stdout.write_fmt(format_args!("{}", unsafe { winapi::um::errhandlingapi::GetLastError() })); Bug: println!("{}", Error::last_os_error());
println!("{}", Error::last_os_error()); Windows 10 |
This happens on Windows 7, cannot test on newer Windows.
Basically, something wrong happens with file handles when using the
println!
macro, not sure what exactly.Minimal repro:
Actual output:
Expected output:
Sorry for German localization in the error messages.
I noticed this because of some obscure behaviour in the windows API (a function returned != 0, but LastError wasn't set accordingly).
cc @retep998
cc retep998/winapi-rs#658
The text was updated successfully, but these errors were encountered: