Skip to content

Commit

Permalink
Update windows-sys requirement from 0.52.0 to 0.59.0 (#76)
Browse files Browse the repository at this point in the history
* Update windows-sys requirement from 0.52.0 to 0.59.0

Updates the requirements on [windows-sys](https://github.com/microsoft/windows-rs) to permit the latest version.
- [Release notes](https://github.com/microsoft/windows-rs/releases)
- [Commits](microsoft/windows-rs@0.52.0...0.59.0)

---
updated-dependencies:
- dependency-name: windows-sys
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix windows: Use `OwnedHandle` from stdlib

Signed-off-by: Jiahao XU <[email protected]>

* Bump msrv to 1.63 for use of `OwnedHandle`

Signed-off-by: Jiahao XU <[email protected]>

* Use macos-latest

now that macos-14 with M! is the default

Signed-off-by: Jiahao XU <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jiahao XU <[email protected]>
  • Loading branch information
dependabot[bot] and NobodyXu authored Jul 31, 2024
1 parent d79ad3a commit f1d21d3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@v4
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make-4.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-14]
os: [ubuntu-latest, macos-latest]
rust: [stable, beta, nightly]
defaults:
run:
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ on: [push, pull_request]

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
MSRV: 1.63

jobs:
test:
name: msrv
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain add 1.58 nightly --no-self-update
rustup default 1.58
rustup toolchain add $MSRV nightly --no-self-update
rustup default $MSRV
- name: Use minimal version and create Cargo.lock
run: |
./avoid-dev-deps.sh
Expand All @@ -34,9 +35,9 @@ jobs:

- name: Install Rust
run: |
rustup toolchain add 1.58 --no-self-update --target wasm32-wasi
rustup toolchain add $MSRV --no-self-update --target wasm32-wasi
rustup toolchain add nightly --no-self-update
rustup default 1.58
rustup default $MSRV
- name: Use minimal version and create Cargo.lock
run: |
./avoid-dev-deps.sh
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = """
An implementation of the GNU make jobserver for Rust
"""
edition = "2018"
rust-version = "1.58.0"
rust-version = "1.63.0"

# docs.rs-specific configuration, shamelessly copied from
# https://stackoverflow.com/a/61417700/8375400.
Expand Down Expand Up @@ -44,7 +44,7 @@ getrandom = { version = "0.2.7", features = ["std", "rdrand"] }
libc = "0.2.132"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.52.0", features = [
windows-sys = { version = "0.59.0", features = [
"Win32_System_WindowsProgramming",
"Win32_System_Threading",
"Win32_Foundation",
Expand Down
62 changes: 21 additions & 41 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use std::{
borrow::Cow, convert::TryInto, ffi::CString, fmt::Write, io, mem::MaybeUninit,
num::NonZeroIsize, ptr,
borrow::Cow,
convert::TryInto,
ffi::CString,
fmt::Write,
io,
mem::MaybeUninit,
num::NonZeroIsize,
os::windows::io::{AsRawHandle, HandleOrNull, OwnedHandle},
ptr,
};

use getrandom::getrandom;
Expand All @@ -24,7 +31,7 @@ type LONG = i32;

#[derive(Debug)]
pub struct Client {
sem: Handle,
sem: OwnedHandle,
name: Box<str>,
}

Expand Down Expand Up @@ -63,14 +70,16 @@ impl Client {

write!(&mut name, "{}\0", u128::from_ne_bytes(bytes)).unwrap();

let res = unsafe {
Handle::new_or_err(CreateSemaphoreA(
let res: io::Result<OwnedHandle> = unsafe {
HandleOrNull::from_raw_handle(CreateSemaphoreA(
ptr::null_mut(),
create_limit,
create_limit,
name.as_ptr(),
))
};
}
.try_into()
.map_err(|_| io::Error::last_os_error());

match res {
Ok(sem) => {
Expand Down Expand Up @@ -102,16 +111,16 @@ impl Client {
}

pub unsafe fn open(var: &[u8]) -> Option<Client> {
let name = String::from_utf8_lossy(var);

let sem = OpenSemaphoreA(
HandleOrNull::from_raw_handle(OpenSemaphoreA(
SYNCHRONIZE | SEMAPHORE_MODIFY_STATE,
FALSE,
CString::new(var).ok()?.as_bytes().as_ptr(),
);
Handle::new(sem).map(|sem| Client {
))
.try_into()
.ok()
.map(|sem| Client {
sem,
name: name.into(),
name: String::from_utf8_lossy(var).into(),
})
}

Expand Down Expand Up @@ -191,32 +200,3 @@ impl Client {
}
}
}

#[derive(Debug)]
#[repr(transparent)]
struct Handle(NonZeroIsize);

impl Handle {
unsafe fn new(handle: RawHandle) -> Option<Self> {
NonZeroIsize::new(handle).map(Self)
}

unsafe fn new_or_err(handle: RawHandle) -> Result<Self, io::Error> {
Self::new(handle).ok_or_else(io::Error::last_os_error)
}

fn as_raw_handle(&self) -> RawHandle {
self.0.get()
}
}

unsafe impl Sync for Handle {}
unsafe impl Send for Handle {}

impl Drop for Handle {
fn drop(&mut self) {
unsafe {
CloseHandle(self.as_raw_handle());
}
}
}

0 comments on commit f1d21d3

Please sign in to comment.