1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-17 17:57:28 +03:00

pty: fix weird cross-compile issue

For some reason, winapi's HANDLE type isn't compatible with the core
rust ffi HANDLE type when cross compiling.

This commit adds some casts.

```
cd pty
cargo build --release --target x86_64-pc-windows-msvc
```

refs: #1389
This commit is contained in:
Wez Furlong 2021-12-12 09:45:21 -07:00
parent ada35ff3db
commit 019de77fcf
3 changed files with 14 additions and 13 deletions

View File

@ -233,7 +233,8 @@ impl ChildKiller for ProcessSignaller {
fn kill(&mut self) -> IoResult<()> {
if let Some(handle) = &self.handle {
unsafe {
if winapi::um::processthreadsapi::TerminateProcess(handle.as_raw_handle(), 127) == 0
if winapi::um::processthreadsapi::TerminateProcess(handle.as_raw_handle() as _, 127)
== 0
{
return Err(std::io::Error::last_os_error());
}

View File

@ -26,7 +26,7 @@ impl WinChild {
fn is_complete(&mut self) -> IoResult<Option<ExitStatus>> {
let mut status: DWORD = 0;
let proc = self.proc.lock().unwrap().try_clone().unwrap();
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) };
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) };
if res != 0 {
if status == STILL_ACTIVE {
Ok(None)
@ -40,7 +40,7 @@ impl WinChild {
fn do_kill(&mut self) -> IoResult<()> {
let proc = self.proc.lock().unwrap().try_clone().unwrap();
let res = unsafe { TerminateProcess(proc.as_raw_handle(), 1) };
let res = unsafe { TerminateProcess(proc.as_raw_handle() as _, 1) };
let err = IoError::last_os_error();
if res != 0 {
Err(err)
@ -69,7 +69,7 @@ pub struct WinChildKiller {
impl ChildKiller for WinChildKiller {
fn kill(&mut self) -> IoResult<()> {
let res = unsafe { TerminateProcess(self.proc.as_raw_handle(), 1) };
let res = unsafe { TerminateProcess(self.proc.as_raw_handle() as _, 1) };
let err = IoError::last_os_error();
if res != 0 {
Err(err)
@ -95,10 +95,10 @@ impl Child for WinChild {
}
let proc = self.proc.lock().unwrap().try_clone().unwrap();
unsafe {
WaitForSingleObject(proc.as_raw_handle(), INFINITE);
WaitForSingleObject(proc.as_raw_handle() as _, INFINITE);
}
let mut status: DWORD = 0;
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) };
let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) };
if res != 0 {
Ok(ExitStatus::with_exit_code(status))
} else {
@ -107,7 +107,7 @@ impl Child for WinChild {
}
fn process_id(&self) -> Option<u32> {
let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle()) };
let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle() as _) };
if res == 0 {
None
} else {
@ -138,7 +138,7 @@ impl std::future::Future for WinChild {
let waker = cx.waker().clone();
std::thread::spawn(move || {
unsafe {
WaitForSingleObject(handle.0, INFINITE);
WaitForSingleObject(handle.0 as _, INFINITE);
}
waker.wake();
});

View File

@ -10,7 +10,6 @@ use std::io::Error as IoError;
use std::mem;
use std::os::windows::ffi::OsStringExt;
use std::os::windows::io::{AsRawHandle, FromRawHandle};
use std::os::windows::raw::HANDLE;
use std::path::Path;
use std::ptr;
use std::sync::Mutex;
@ -22,6 +21,7 @@ use winapi::um::winbase::{
CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW,
};
use winapi::um::wincon::COORD;
use winapi::um::winnt::HANDLE;
pub type HPCON = HANDLE;
@ -80,8 +80,8 @@ impl PsuedoCon {
let result = unsafe {
(CONPTY.CreatePseudoConsole)(
size,
input.as_raw_handle(),
output.as_raw_handle(),
input.as_raw_handle() as _,
output.as_raw_handle() as _,
PSEUDOCONSOLE_RESIZE_QUIRK | PSEUDOCONSOLE_WIN32_INPUT_MODE,
&mut con,
)
@ -161,8 +161,8 @@ impl PsuedoCon {
// Make sure we close out the thread handle so we don't leak it;
// we do this simply by making it owned
let _main_thread = unsafe { OwnedHandle::from_raw_handle(pi.hThread) };
let proc = unsafe { OwnedHandle::from_raw_handle(pi.hProcess) };
let _main_thread = unsafe { OwnedHandle::from_raw_handle(pi.hThread as _) };
let proc = unsafe { OwnedHandle::from_raw_handle(pi.hProcess as _) };
Ok(WinChild {
proc: Mutex::new(proc),