Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a61eba

Browse files
committed
rustpython_vm::windows
1 parent58df09b commit4a61eba

File tree

3 files changed

+72
-62
lines changed

3 files changed

+72
-62
lines changed

‎vm/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pub mod utils;
7979
pubmod version;
8080
pubmod vm;
8181
pubmod warn;
82+
#[cfg(windows)]
83+
pubmod windows;
8284

8385
pubuseself::compiler::parser::source_code;
8486
pubuseself::convert::{TryFromBorrowedObject,TryFromObject};

‎vm/src/stdlib/winapi.rs‎

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ mod _winapi {
66
usecrate::{
77
builtins::PyStrRef,
88
common::windows::ToWideString,
9-
convert::{ToPyException,ToPyObject,ToPyResult},
9+
convert::{ToPyException,ToPyResult},
1010
function::{ArgMapping,ArgSequence,OptionalArg},
1111
stdlib::os::errno_err,
12+
windows::WindowsSysResult,
1213
PyObjectRef,PyResult,TryFromObject,VirtualMachine,
1314
};
1415
use std::ptr::{null, null_mut};
@@ -56,67 +57,6 @@ mod _winapi {
5657
UI::WindowsAndMessaging::SW_HIDE,
5758
};
5859

59-
traitWindowsSysResultValue{
60-
typeOk:ToPyObject;
61-
fnis_err(&self) ->bool;
62-
fninto_ok(self) ->Self::Ok;
63-
}
64-
65-
implWindowsSysResultValueforRAW_HANDLE{
66-
typeOk =HANDLE;
67-
fnis_err(&self) ->bool{
68-
*self == windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE
69-
}
70-
fninto_ok(self) ->Self::Ok{
71-
HANDLE(self)
72-
}
73-
}
74-
75-
implWindowsSysResultValueforBOOL{
76-
typeOk =();
77-
fnis_err(&self) ->bool{
78-
*self ==0
79-
}
80-
fninto_ok(self) ->Self::Ok{}
81-
}
82-
83-
structWindowsSysResult<T>(T);
84-
85-
impl<T:WindowsSysResultValue>WindowsSysResult<T>{
86-
fnis_err(&self) ->bool{
87-
self.0.is_err()
88-
}
89-
fninto_pyresult(self,vm:&VirtualMachine) ->PyResult<T::Ok>{
90-
ifself.is_err(){
91-
Err(errno_err(vm))
92-
}else{
93-
Ok(self.0.into_ok())
94-
}
95-
}
96-
}
97-
98-
impl<T:WindowsSysResultValue>ToPyResultforWindowsSysResult<T>{
99-
fnto_pyresult(self,vm:&VirtualMachine) ->PyResult{
100-
let ok =self.into_pyresult(vm)?;
101-
Ok(ok.to_pyobject(vm))
102-
}
103-
}
104-
105-
typeHandleInt =usize;// TODO: change to isize when fully ported to windows-rs
106-
107-
implTryFromObjectforHANDLE{
108-
fntry_from_object(vm:&VirtualMachine,obj:PyObjectRef) ->PyResult<Self>{
109-
let handle =HandleInt::try_from_object(vm, obj)?;
110-
Ok(HANDLE(handleasisize))
111-
}
112-
}
113-
114-
implToPyObjectforHANDLE{
115-
fnto_pyobject(self,vm:&VirtualMachine) ->PyObjectRef{
116-
(self.0asHandleInt).to_pyobject(vm)
117-
}
118-
}
119-
12060
#[pyfunction]
12161
fnCloseHandle(handle:HANDLE) ->WindowsSysResult<BOOL>{
12262
WindowsSysResult(unsafe{ windows_sys::Win32::Foundation::CloseHandle(handle.0)})

‎vm/src/windows.rs‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
usecrate::{
2+
convert::{ToPyObject,ToPyResult},
3+
stdlib::os::errno_err,
4+
PyObjectRef,PyResult,TryFromObject,VirtualMachine,
5+
};
6+
use windows::Win32::Foundation::HANDLE;
7+
use windows_sys::Win32::Foundation::{BOOL,HANDLEasRAW_HANDLE};
8+
9+
pub(crate)traitWindowsSysResultValue{
10+
typeOk:ToPyObject;
11+
fnis_err(&self) ->bool;
12+
fninto_ok(self) ->Self::Ok;
13+
}
14+
15+
implWindowsSysResultValueforRAW_HANDLE{
16+
typeOk =HANDLE;
17+
fnis_err(&self) ->bool{
18+
*self == windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE
19+
}
20+
fninto_ok(self) ->Self::Ok{
21+
HANDLE(self)
22+
}
23+
}
24+
25+
implWindowsSysResultValueforBOOL{
26+
typeOk =();
27+
fnis_err(&self) ->bool{
28+
*self ==0
29+
}
30+
fninto_ok(self) ->Self::Ok{}
31+
}
32+
33+
pub(crate)structWindowsSysResult<T>(pubT);
34+
35+
impl<T:WindowsSysResultValue>WindowsSysResult<T>{
36+
pubfnis_err(&self) ->bool{
37+
self.0.is_err()
38+
}
39+
pubfninto_pyresult(self,vm:&VirtualMachine) ->PyResult<T::Ok>{
40+
ifself.is_err(){
41+
Err(errno_err(vm))
42+
}else{
43+
Ok(self.0.into_ok())
44+
}
45+
}
46+
}
47+
48+
impl<T:WindowsSysResultValue>ToPyResultforWindowsSysResult<T>{
49+
fnto_pyresult(self,vm:&VirtualMachine) ->PyResult{
50+
let ok =self.into_pyresult(vm)?;
51+
Ok(ok.to_pyobject(vm))
52+
}
53+
}
54+
55+
typeHandleInt =usize;// TODO: change to isize when fully ported to windows-rs
56+
57+
implTryFromObjectforHANDLE{
58+
fntry_from_object(vm:&VirtualMachine,obj:PyObjectRef) ->PyResult<Self>{
59+
let handle =HandleInt::try_from_object(vm, obj)?;
60+
Ok(HANDLE(handleasisize))
61+
}
62+
}
63+
64+
implToPyObjectforHANDLE{
65+
fnto_pyobject(self,vm:&VirtualMachine) ->PyObjectRef{
66+
(self.0asHandleInt).to_pyobject(vm)
67+
}
68+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp