Windows-rs update (#657)

* upd

* more
This commit is contained in:
Dongjia Zhang 2022-05-29 20:04:21 +09:00 committed by GitHub
parent bfe69aea09
commit dd78210335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 26 deletions

View File

@ -99,10 +99,10 @@ lock_api = "0.4.3"
regex = "1.4.5"
[target.'cfg(windows)'.dependencies]
windows = { version = "0.29.0", features = ["std", "Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security"] }
windows = { version = "0.37.0", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security"] }
[target.'cfg(windows)'.build-dependencies]
windows = "0.29.0"
windows = "0.37.0"
#[profile.release]
#lto = true

View File

@ -1165,7 +1165,8 @@ pub mod win32_shmem {
const INVALID_HANDLE_VALUE: isize = -1;
use windows::{
Win32::Foundation::{CloseHandle, BOOL, HANDLE, PSTR},
core::PCSTR,
Win32::Foundation::{CloseHandle, BOOL, HANDLE},
Win32::System::Memory::{
CreateFileMappingA, MapViewOfFile, OpenFileMappingA, UnmapViewOfFile,
FILE_MAP_ALL_ACCESS, PAGE_READWRITE,
@ -1205,14 +1206,9 @@ pub mod win32_shmem {
PAGE_READWRITE,
0,
map_size as u32,
PSTR(map_str_bytes.as_mut_ptr()),
);
if handle == HANDLE(0) {
return Err(Error::unknown(format!(
"Cannot create shared memory {}",
String::from_utf8_lossy(map_str_bytes)
)));
}
PCSTR(map_str_bytes.as_mut_ptr()),
)?;
let map = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8;
if map.is_null() {
return Err(Error::unknown(format!(
@ -1235,16 +1231,11 @@ pub mod win32_shmem {
let map_str_bytes = id.id;
// Unlike MapViewOfFile this one needs u32
let handle = OpenFileMappingA(
FILE_MAP_ALL_ACCESS,
FILE_MAP_ALL_ACCESS.0,
BOOL(0),
PSTR(map_str_bytes.as_ptr() as *mut _),
);
if handle == HANDLE(0) {
return Err(Error::unknown(format!(
"Cannot open shared memory {}",
String::from_utf8_lossy(&map_str_bytes)
)));
}
PCSTR(map_str_bytes.as_ptr() as *mut _),
)?;
let map = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8;
if map.is_null() {
return Err(Error::unknown(format!(

View File

@ -1096,12 +1096,6 @@ mod windows_exception_handler {
compiler_fence(Ordering::SeqCst);
ExitProcess(1);
LeaveCriticalSection(
(data.critical as *mut RTL_CRITICAL_SECTION)
.as_mut()
.unwrap(),
);
}
}
compiler_fence(Ordering::SeqCst);

View File

@ -374,6 +374,13 @@ impl From<TryFromSliceError> for Error {
}
}
#[cfg(windows)]
impl From<windows::core::Error> for Error {
fn from(err: windows::core::Error) -> Self {
Self::unknown(format!("Windows API error: {:?}", err))
}
}
#[cfg(feature = "python")]
impl From<pyo3::PyErr> for Error {
fn from(err: pyo3::PyErr) -> Self {