Skip to content

Commit c0f9379

Browse files
borsehuss
authored andcommitted
Auto merge of rust-lang#88587 - bdbai:fix/uwpio, r=joshtriplett
Fix WinUWP std compilation errors due to I/O safety I/O safety for Windows has landed in rust-lang#87329. However, it does not cover UWP specific parts and prevents all UWP targets from building. See YtFlow/Maple#18. This PR fixes these compile errors when building std for UWP targets.
1 parent a29557c commit c0f9379

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

library/std/src/sys/windows/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl File {
357357
let mut info: c::FILE_BASIC_INFO = mem::zeroed();
358358
let size = mem::size_of_val(&info);
359359
cvt(c::GetFileInformationByHandleEx(
360-
self.handle.raw(),
360+
self.handle.as_raw_handle(),
361361
c::FileBasicInfo,
362362
&mut info as *mut _ as *mut libc::c_void,
363363
size as c::DWORD,
@@ -385,7 +385,7 @@ impl File {
385385
let mut info: c::FILE_STANDARD_INFO = mem::zeroed();
386386
let size = mem::size_of_val(&info);
387387
cvt(c::GetFileInformationByHandleEx(
388-
self.handle.raw(),
388+
self.handle.as_raw_handle(),
389389
c::FileStandardInfo,
390390
&mut info as *mut _ as *mut libc::c_void,
391391
size as c::DWORD,

library/std/src/sys/windows/stdio_uwp.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::io;
44
use crate::mem::ManuallyDrop;
5+
use crate::os::windows::io::FromRawHandle;
56
use crate::sys::c;
67
use crate::sys::handle::Handle;
78

@@ -25,7 +26,8 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {
2526

2627
fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
2728
let handle = get_handle(handle_id)?;
28-
let handle = Handle::new(handle);
29+
// SAFETY: The handle returned from `get_handle` must be valid and non-null.
30+
let handle = unsafe { Handle::from_raw_handle(handle) };
2931
ManuallyDrop::new(handle).write(data)
3032
}
3133

@@ -38,7 +40,8 @@ impl Stdin {
3840
impl io::Read for Stdin {
3941
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
4042
let handle = get_handle(c::STD_INPUT_HANDLE)?;
41-
let handle = Handle::new(handle);
43+
// SAFETY: The handle returned from `get_handle` must be valid and non-null.
44+
let handle = unsafe { Handle::from_raw_handle(handle) };
4245
ManuallyDrop::new(handle).read(buf)
4346
}
4447
}

0 commit comments

Comments
 (0)