Skip to content

Commit ec702d2

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#134822 - jieyouxu:rollup-5xuaq82, r=jieyouxu
Rollup of 8 pull requests Successful merges: - rust-lang#134606 (ptr::copy: fix docs for the overlapping case) - rust-lang#134622 (Windows: Use WriteFile to write to a UTF-8 console) - rust-lang#134759 (compiletest: Remove the `-test` suffix from normalize directives) - rust-lang#134787 (Spruce up the docs of several queries related to the type/trait system and const eval) - rust-lang#134806 (rustdoc: use shorter paths as preferred canonical paths) - rust-lang#134815 (Sort triples by name in platform_support.md) - rust-lang#134816 (tools: fix build failure caused by PR rust-lang#134420) - rust-lang#134819 (Fix mistake in windows file open) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c01618d + 22793b8 commit ec702d2

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

core/src/intrinsics/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4364,13 +4364,11 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
43644364
///
43654365
/// Behavior is undefined if any of the following conditions are violated:
43664366
///
4367-
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes, and must remain valid even
4368-
/// when `dst` is written for `count * size_of::<T>()` bytes. (This means if the memory ranges
4369-
/// overlap, the two pointers must not be subject to aliasing restrictions relative to each
4370-
/// other.)
4367+
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
43714368
///
43724369
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes, and must remain valid even
4373-
/// when `src` is read for `count * size_of::<T>()` bytes.
4370+
/// when `src` is read for `count * size_of::<T>()` bytes. (This means if the memory ranges
4371+
/// overlap, the `dst` pointer must not be invalidated by `src` reads.)
43744372
///
43754373
/// * Both `src` and `dst` must be properly aligned.
43764374
///

std/src/sys/pal/windows/c/bindings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ Windows.Win32.System.Console.ENABLE_VIRTUAL_TERMINAL_PROCESSING
24262426
Windows.Win32.System.Console.ENABLE_WINDOW_INPUT
24272427
Windows.Win32.System.Console.ENABLE_WRAP_AT_EOL_OUTPUT
24282428
Windows.Win32.System.Console.GetConsoleMode
2429+
Windows.Win32.System.Console.GetConsoleOutputCP
24292430
Windows.Win32.System.Console.GetStdHandle
24302431
Windows.Win32.System.Console.ReadConsoleW
24312432
Windows.Win32.System.Console.STD_ERROR_HANDLE

std/src/sys/pal/windows/c/windows_sys.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ windows_targets::link!("kernel32.dll" "system" fn FreeEnvironmentStringsW(penv :
3434
windows_targets::link!("kernel32.dll" "system" fn GetActiveProcessorCount(groupnumber : u16) -> u32);
3535
windows_targets::link!("kernel32.dll" "system" fn GetCommandLineW() -> PCWSTR);
3636
windows_targets::link!("kernel32.dll" "system" fn GetConsoleMode(hconsolehandle : HANDLE, lpmode : *mut CONSOLE_MODE) -> BOOL);
37+
windows_targets::link!("kernel32.dll" "system" fn GetConsoleOutputCP() -> u32);
3738
windows_targets::link!("kernel32.dll" "system" fn GetCurrentDirectoryW(nbufferlength : u32, lpbuffer : PWSTR) -> u32);
3839
windows_targets::link!("kernel32.dll" "system" fn GetCurrentProcess() -> HANDLE);
3940
windows_targets::link!("kernel32.dll" "system" fn GetCurrentProcessId() -> u32);
@@ -3333,6 +3334,7 @@ pub struct XSAVE_FORMAT {
33333334
pub XmmRegisters: [M128A; 8],
33343335
pub Reserved4: [u8; 224],
33353336
}
3337+
33363338
#[cfg(target_arch = "arm")]
33373339
#[repr(C)]
33383340
pub struct WSADATA {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl File {
323323
let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 };
324324
let result = c::SetFileInformationByHandle(
325325
handle.as_raw_handle(),
326-
c::FileEndOfFileInfo,
326+
c::FileAllocationInfo,
327327
(&raw const alloc).cast::<c_void>(),
328328
mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32,
329329
);

std/src/sys/pal/windows/stdio.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,43 @@ fn is_console(handle: c::HANDLE) -> bool {
8484
unsafe { c::GetConsoleMode(handle, &mut mode) != 0 }
8585
}
8686

87+
/// Returns true if the attached console's code page is currently UTF-8.
88+
#[cfg(not(target_vendor = "win7"))]
89+
fn is_utf8_console() -> bool {
90+
unsafe { c::GetConsoleOutputCP() == c::CP_UTF8 }
91+
}
92+
93+
#[cfg(target_vendor = "win7")]
94+
fn is_utf8_console() -> bool {
95+
// Windows 7 has a fun "feature" where WriteFile on a console handle will return
96+
// the number of UTF-16 code units written and not the number of bytes from the input string.
97+
// So we always claim the console isn't UTF-8 to trigger the WriteConsole fallback code.
98+
false
99+
}
100+
87101
fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> io::Result<usize> {
88102
if data.is_empty() {
89103
return Ok(0);
90104
}
91105

92106
let handle = get_handle(handle_id)?;
93-
if !is_console(handle) {
107+
if !is_console(handle) || is_utf8_console() {
94108
unsafe {
95109
let handle = Handle::from_raw_handle(handle);
96110
let ret = handle.write(data);
97111
let _ = handle.into_raw_handle(); // Don't close the handle
98112
return ret;
99113
}
114+
} else {
115+
write_console_utf16(data, incomplete_utf8, handle)
100116
}
117+
}
101118

119+
fn write_console_utf16(
120+
data: &[u8],
121+
incomplete_utf8: &mut IncompleteUtf8,
122+
handle: c::HANDLE,
123+
) -> io::Result<usize> {
102124
if incomplete_utf8.len > 0 {
103125
assert!(
104126
incomplete_utf8.len < 4,

0 commit comments

Comments
 (0)