From 05c1e92787d134c53a38c5eea7100caa7441fccd Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 18:47:55 +0000 Subject: [PATCH 1/3] Correct definition of CONSOLE_SCREEN_BUFFER_INFO --- src/libterm/win.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 14ea68d378878..f5c60ee352276 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -20,19 +20,36 @@ pub struct WinConsole { background: color::Color, } +type SHORT = i16; type WORD = u16; type DWORD = u32; type BOOL = i32; type HANDLE = *mut u8; +#[allow(non_snake_case)] +#[repr(C)] +struct SMALL_RECT { + Left: SHORT, + Top: SHORT, + Right: SHORT, + Bottom: SHORT, +} + +#[allow(non_snake_case)] +#[repr(C)] +struct COORD { + X: SHORT, + Y: SHORT, +} + #[allow(non_snake_case)] #[repr(C)] struct CONSOLE_SCREEN_BUFFER_INFO { - dwSize: [libc::c_short; 2], - dwCursorPosition: [libc::c_short; 2], + dwSize: COORD, + dwCursorPosition: COORD, wAttributes: WORD, - srWindow: [libc::c_short; 4], - dwMaximumWindowSize: [libc::c_short; 2], + srWindow: SMALL_RECT, + dwMaximumWindowSize: COORD, } #[allow(non_snake_case)] From 42c3d3714508c9ab51e5c83dd78a37dbc5e2890c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 18:59:56 +0000 Subject: [PATCH 2/3] Remove use of mem::uninitialized in libterm crate --- src/libterm/win.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libterm/win.rs b/src/libterm/win.rs index f5c60ee352276..e5911de8396c1 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -2,8 +2,6 @@ // FIXME (#13400): this is only a tiny fraction of the Windows console api -extern crate libc; - use std::io; use std::io::prelude::*; @@ -122,12 +120,17 @@ impl WinConsole { /// Returns `None` whenever the terminal cannot be created for some reason. pub fn new(out: T) -> io::Result> { + use std::mem::MaybeUninit; + let fg; let bg; unsafe { - #[allow(deprecated)] - let mut buffer_info = ::std::mem::uninitialized(); - if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 { + let mut buffer_info = MaybeUninit::::uninit(); + if GetConsoleScreenBufferInfo( + GetStdHandle(-11i32 as DWORD), + buffer_info.as_mut_ptr() + ) != 0 { + let buffer_info = buffer_info.assume_init() ; fg = bits_to_color(buffer_info.wAttributes); bg = bits_to_color(buffer_info.wAttributes >> 4); } else { From 7646d4935b50c02f97545705af46ab46116db91d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 19:26:25 +0000 Subject: [PATCH 3/3] Remove use of mem::uninitialized in code_gen crate --- src/librustc_codegen_llvm/common.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 9fdc93c3ff0f3..3b2701b893bb1 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -170,8 +170,7 @@ impl CodegenCx<'ll, 'tcx> { pub fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> { unsafe { if self.is_const_real(v) { - #[allow(deprecated)] - let mut loses_info: llvm::Bool = ::std::mem::uninitialized(); + let mut loses_info: llvm::Bool = 0; let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info); let loses_info = if loses_info == 1 { true } else { false }; Some((r, loses_info))