Skip to content

Commit 00571ba

Browse files
committed
Keep HANDLE usize
1 parent d5938ff commit 00571ba

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

vm/src/stdlib/winapi.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ mod _winapi {
8383
}
8484
}
8585

86+
type HandleInt = usize; // TODO: change to isize when fully ported to windows-rs
87+
8688
impl TryFromObject for HANDLE {
8789
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
88-
let handle = isize::try_from_object(vm, obj)?;
89-
Ok(HANDLE(handle))
90+
let handle = HandleInt::try_from_object(vm, obj)?;
91+
Ok(HANDLE(handle as isize))
9092
}
9193
}
9294

@@ -97,25 +99,31 @@ mod _winapi {
9799
}
98100
}
99101

102+
impl ToPyObject for HANDLE {
103+
fn to_pyobject(&self, vm: &VirtualMachine) -> PyObjectRef {
104+
(self.0 as HandleInt).to_pyobject(vm)
105+
}
106+
}
107+
100108
#[pyfunction]
101109
fn CloseHandle(handle: HANDLE) -> windows::core::Result<()> {
102110
unsafe { Win32::Foundation::CloseHandle(handle) }
103111
}
104112

105113
#[pyfunction]
106-
fn GetStdHandle(std_handle: STD_HANDLE) -> windows::core::Result<isize> {
107-
Ok(unsafe { Win32::System::Console::GetStdHandle(std_handle) }?.0)
114+
fn GetStdHandle(std_handle: STD_HANDLE) -> windows::core::Result<HANDLE> {
115+
Ok(unsafe { Win32::System::Console::GetStdHandle(std_handle) }?)
108116
}
109117

110118
#[pyfunction]
111-
fn CreatePipe(_pipe_attrs: PyObjectRef, size: u32) -> windows::core::Result<(isize, isize)> {
119+
fn CreatePipe(_pipe_attrs: PyObjectRef, size: u32) -> windows::core::Result<(HANDLE, HANDLE)> {
112120
let (read, write) = unsafe {
113121
let mut read = std::mem::MaybeUninit::<HANDLE>::uninit();
114122
let mut write = std::mem::MaybeUninit::<HANDLE>::uninit();
115123
Win32::System::Pipes::CreatePipe(read.as_mut_ptr(), write.as_mut_ptr(), None, size)?;
116124
(read.assume_init(), write.assume_init())
117125
};
118-
Ok((read.0, write.0))
126+
Ok((read, write))
119127
}
120128

121129
#[pyfunction]
@@ -125,7 +133,7 @@ mod _winapi {
125133
access: u32,
126134
inherit: i32,
127135
options: OptionalArg<u32>,
128-
) -> windows::core::Result<isize> {
136+
) -> windows::core::Result<HANDLE> {
129137
let target = unsafe {
130138
let mut target = std::mem::MaybeUninit::<HANDLE>::uninit();
131139
Win32::Foundation::DuplicateHandle(
@@ -139,12 +147,12 @@ mod _winapi {
139147
)?;
140148
target.assume_init()
141149
};
142-
Ok(target.0)
150+
Ok(target)
143151
}
144152

145153
#[pyfunction]
146-
fn GetCurrentProcess() -> isize {
147-
unsafe { Win32::System::Threading::GetCurrentProcess() }.0
154+
fn GetCurrentProcess() -> HANDLE {
155+
unsafe { Win32::System::Threading::GetCurrentProcess() }
148156
}
149157

150158
#[pyfunction]
@@ -183,7 +191,7 @@ mod _winapi {
183191
fn CreateProcess(
184192
args: CreateProcessArgs,
185193
vm: &VirtualMachine,
186-
) -> PyResult<(isize, isize, u32, u32)> {
194+
) -> PyResult<(HANDLE, HANDLE, u32, u32)> {
187195
let mut si = winbase::STARTUPINFOEXW::default();
188196
si.StartupInfo.cb = std::mem::size_of_val(&si) as _;
189197

@@ -263,8 +271,8 @@ mod _winapi {
263271
};
264272

265273
Ok((
266-
procinfo.hProcess.0,
267-
procinfo.hThread.0,
274+
procinfo.hProcess,
275+
procinfo.hThread,
268276
procinfo.dwProcessId,
269277
procinfo.dwThreadId,
270278
))

0 commit comments

Comments
 (0)