Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings from rustc and clippy #77

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jobserver"
version = "0.1.28"
version = "0.1.29"
authors = ["Alex Crichton <[email protected]>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/alexcrichton/jobserver-rs"
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,6 @@ impl HelperState {
lock.consumer_done = true;
self.cvar.notify_one();
}

fn producer_done(&self) -> bool {
self.lock().producer_done
}
}

/// Finds and returns the value of `--jobserver-auth=<VALUE>` in the given
Expand Down
17 changes: 9 additions & 8 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Client {
{
let read = self.read().as_raw_fd();
loop {
match non_blocking_read(read, &mut buf) {
match non_blocking_read(read, &buf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an error in programming: non_blocking_read definitely needs mutable reference to buffer.

cc @weihanglo Can you fix this in your PR (opening another PR would just create merge conflicts with yours)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to open a PR, since they fix different issues. Fine with resolving PR conflicts for that reason.

Ok(1) => return Ok(Some(Acquired { byte: buf[0] })),
Ok(_) => {
return Err(io::Error::new(
Expand Down Expand Up @@ -437,7 +437,7 @@ pub(crate) fn spawn_helper(
}));
}
Err(e) => break f(Err(e)),
Ok(None) if helper.producer_done() => break,
Ok(None) if helper.lock().producer_done => break,
Ok(None) => {}
}
});
Expand Down Expand Up @@ -625,12 +625,7 @@ mod test {

use crate::{test::run_named_fifo_try_acquire_tests, Client};

use std::{
fs::File,
io::{self, Write},
os::unix::io::AsRawFd,
sync::Arc,
};
use std::sync::Arc;

fn from_imp_client(imp: ClientImp) -> Client {
Client {
Expand All @@ -657,6 +652,12 @@ mod test {
#[cfg(not(target_os = "linux"))]
#[test]
fn test_try_acquire_annoymous_pipe_linux_specific_optimization() {
use std::{
fs::File,
io::{self, Write},
os::unix::io::AsRawFd,
};

let (read, write) = nix::unistd::pipe().unwrap();
let read = File::from(read);
let mut write = File::from(write);
Expand Down
13 changes: 7 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pub struct Client {
#[derive(Debug)]
pub struct Acquired;

#[allow(clippy::upper_case_acronyms)]
type BOOL = i32;
#[allow(clippy::upper_case_acronyms)]
type DWORD = u32;
#[allow(clippy::upper_case_acronyms)]
type HANDLE = *mut u8;
#[allow(clippy::upper_case_acronyms)]
type LONG = i32;

const ERROR_ALREADY_EXISTS: DWORD = 183;
Expand Down Expand Up @@ -71,7 +75,7 @@ extern "system" {
// randomness.
fn getrandom(dest: &mut [u8]) -> io::Result<()> {
// Prevent overflow of u32
for chunk in dest.chunks_mut(u32::max_value() as usize) {
for chunk in dest.chunks_mut(u32::MAX as usize) {
let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr(), chunk.len() as u32) };
if ret == 0 {
return Err(io::Error::new(
Expand Down Expand Up @@ -115,10 +119,7 @@ impl Client {
continue;
}
name.pop(); // chop off the trailing nul
let client = Client {
sem: handle,
name: name,
};
let client = Client { sem: handle, name };
if create_limit != limit {
client.acquire()?;
}
Expand Down Expand Up @@ -259,7 +260,7 @@ pub(crate) fn spawn_helper(
state.for_each_request(|_| {
const WAIT_OBJECT_1: u32 = WAIT_OBJECT_0 + 1;
match unsafe { WaitForMultipleObjects(2, objects.as_ptr(), FALSE, INFINITE) } {
WAIT_OBJECT_0 => return,
WAIT_OBJECT_0 => {}
WAIT_OBJECT_1 => f(Ok(crate::Acquired {
client: client.inner.clone(),
data: Acquired,
Expand Down
1 change: 0 additions & 1 deletion tests/helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use jobserver::Client;
use std::sync::atomic::*;
use std::sync::mpsc;
use std::sync::*;

macro_rules! t {
Expand Down