diff options
| author | bors <bors@rust-lang.org> | 2021-09-23 06:18:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-23 06:18:07 +0000 |
| commit | 15d9ba0133ce0b35348e1c8367afe00aec841ffa (patch) | |
| tree | d94106466c291c3381313d7db1b3a2a4ad09bbf9 /library/std/src | |
| parent | 67365d64bcdfeae1334bf2ff49587c27d1c973f0 (diff) | |
| parent | 4e01157969eb5726f08fa31a898108654d813fdd (diff) | |
| download | rust-15d9ba0133ce0b35348e1c8367afe00aec841ffa.tar.gz rust-15d9ba0133ce0b35348e1c8367afe00aec841ffa.zip | |
Auto merge of #88587 - bdbai:fix/uwpio, r=joshtriplett
Fix WinUWP std compilation errors due to I/O safety I/O safety for Windows has landed in #87329. However, it does not cover UWP specific parts and prevents all UWP targets from building. See https://github.com/YtFlow/Maple/issues/18. This PR fixes these compile errors when building std for UWP targets.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/windows/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/windows/stdio_uwp.rs | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index 0c1a50e231c..cc137771bb8 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -357,7 +357,7 @@ impl File { let mut info: c::FILE_BASIC_INFO = mem::zeroed(); let size = mem::size_of_val(&info); cvt(c::GetFileInformationByHandleEx( - self.handle.raw(), + self.handle.as_raw_handle(), c::FileBasicInfo, &mut info as *mut _ as *mut libc::c_void, size as c::DWORD, @@ -385,7 +385,7 @@ impl File { let mut info: c::FILE_STANDARD_INFO = mem::zeroed(); let size = mem::size_of_val(&info); cvt(c::GetFileInformationByHandleEx( - self.handle.raw(), + self.handle.as_raw_handle(), c::FileStandardInfo, &mut info as *mut _ as *mut libc::c_void, size as c::DWORD, diff --git a/library/std/src/sys/windows/stdio_uwp.rs b/library/std/src/sys/windows/stdio_uwp.rs index 872511af862..32550f796ec 100644 --- a/library/std/src/sys/windows/stdio_uwp.rs +++ b/library/std/src/sys/windows/stdio_uwp.rs @@ -2,6 +2,7 @@ use crate::io; use crate::mem::ManuallyDrop; +use crate::os::windows::io::FromRawHandle; use crate::sys::c; use crate::sys::handle::Handle; @@ -25,7 +26,8 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> { fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> { let handle = get_handle(handle_id)?; - let handle = Handle::new(handle); + // SAFETY: The handle returned from `get_handle` must be valid and non-null. + let handle = unsafe { Handle::from_raw_handle(handle) }; ManuallyDrop::new(handle).write(data) } @@ -38,7 +40,8 @@ impl Stdin { impl io::Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { let handle = get_handle(c::STD_INPUT_HANDLE)?; - let handle = Handle::new(handle); + // SAFETY: The handle returned from `get_handle` must be valid and non-null. + let handle = unsafe { Handle::from_raw_handle(handle) }; ManuallyDrop::new(handle).read(buf) } } |
