Skip to content

Commit

Permalink
Fix clippy lint warnings.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Walbran <[email protected]>
  • Loading branch information
qwandor committed Dec 1, 2023
1 parent 420803c commit 225ae11
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion grpc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {

fn figure_systemd_path(build_dir: &str) {
let path = format!("{build_dir}/CMakeCache.txt");
let f = BufReader::new(std::fs::File::open(&path).unwrap());
let f = BufReader::new(std::fs::File::open(path).unwrap());
let mut libdir: Option<String> = None;
let mut libname: Option<String> = None;
for l in f.lines() {
Expand Down
2 changes: 1 addition & 1 deletion interop/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Client {

pub async fn server_streaming(&self) -> grpcio::Result<()> {
print!("testing server streaming ... ");
let sizes = vec![31415, 9, 2653, 58979];
let sizes = [31415, 9, 2653, 58979];
let req = StreamingOutputCallRequest {
response_parameters: sizes
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<'a> From<&'a GrpcSlice> for GrpcByteBuffer {
/// Create a buffer from the given single slice.
///
/// A buffer, which length is 1, is allocated for the slice.
#[allow(clippy::cast_ref_to_mut)]
#[allow(invalid_reference_casting)]
fn from(s: &'a GrpcSlice) -> GrpcByteBuffer {
unsafe {
// hack: buffer_create accepts an mutable pointer to indicate it mutate
Expand Down
9 changes: 5 additions & 4 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ struct ChannelInner {
channel: *mut grpc_channel,
}

// SAFETY: `grpc_channel` is safe to send between threads, and `Environment` is already `Send`.
unsafe impl Send for ChannelInner {}
// SAFETY: `grpc_channel` can be used from multiple threads, and `Environment` is already `Sync`.
unsafe impl Sync for ChannelInner {}

impl ChannelInner {
// If try_to_connect is true, the channel will try to establish a connection, potentially
// changing the state.
Expand Down Expand Up @@ -622,10 +627,6 @@ pub struct Channel {
cq: CompletionQueue,
}

#[allow(clippy::non_send_fields_in_send_ty)]
unsafe impl Send for Channel {}
unsafe impl Sync for Channel {}

impl Channel {
/// Create a new channel. Avoid using this directly and use
/// [`ChannelBuilder`] to build a [`Channel`] instead.
Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt::{self, Debug, Formatter};
use std::future::Future;
use std::pin::Pin;
use std::ptr;
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
Expand Down Expand Up @@ -298,7 +299,7 @@ pub type BoxHandler = Box<dyn CloneableHandler>;
#[derive(Clone)]
pub struct RequestCallContext {
server: Arc<ServerCore>,
registry: Arc<UnsafeCell<HashMap<&'static [u8], BoxHandler>>>,
registry: Rc<UnsafeCell<HashMap<&'static [u8], BoxHandler>>>,
checkers: Vec<Box<dyn ServerChecker>>,
}

Expand Down Expand Up @@ -420,7 +421,7 @@ impl Server {
.collect();
let rc = RequestCallContext {
server: self.core.clone(),
registry: Arc::new(UnsafeCell::new(registry)),
registry: Rc::new(UnsafeCell::new(registry)),
checkers: self.checkers.clone(),
};
for _ in 0..self.core.slots_per_cq {
Expand Down

0 comments on commit 225ae11

Please sign in to comment.