Skip to content

Commit

Permalink
Start fixing issues identified by clippy (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson authored Oct 4, 2024
1 parent b685cca commit 8b5bb30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ use std::time::Duration;

thread_local! {
static OS_IPC_CHANNELS_FOR_DESERIALIZATION: RefCell<Vec<OsOpaqueIpcChannel>> =
RefCell::new(Vec::new())
const { RefCell::new(Vec::new()) }
}
thread_local! {
static OS_IPC_SHARED_MEMORY_REGIONS_FOR_DESERIALIZATION:
RefCell<Vec<Option<OsIpcSharedMemory>>> = RefCell::new(Vec::new())
RefCell<Vec<Option<OsIpcSharedMemory>>> = const { RefCell::new(Vec::new()) }
}
thread_local! {
static OS_IPC_CHANNELS_FOR_SERIALIZATION: RefCell<Vec<OsIpcChannel>> = RefCell::new(Vec::new())
static OS_IPC_CHANNELS_FOR_SERIALIZATION: RefCell<Vec<OsIpcChannel>> = const { RefCell::new(Vec::new()) }
}
thread_local! {
static OS_IPC_SHARED_MEMORY_REGIONS_FOR_SERIALIZATION: RefCell<Vec<OsIpcSharedMemory>> =
RefCell::new(Vec::new())
const { RefCell::new(Vec::new()) }
}

#[derive(Debug)]
Expand Down
30 changes: 13 additions & 17 deletions src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use std::ptr;
use std::slice;
use std::sync::RwLock;
use std::time::Duration;
use std::usize;

mod mach_sys;

Expand All @@ -40,7 +39,7 @@ mod mach_sys;
const SMALL_MESSAGE_SIZE: usize = 4096;

/// A string to prepend to our bootstrap ports.
static BOOTSTRAP_PREFIX: &'static str = "org.rust-lang.ipc-channel.";
static BOOTSTRAP_PREFIX: &str = "org.rust-lang.ipc-channel.";

const BOOTSTRAP_NAME_IN_USE: kern_return_t = 1101;
const BOOTSTRAP_SUCCESS: kern_return_t = 0;
Expand Down Expand Up @@ -205,7 +204,7 @@ impl OsIpcReceiver {
mach_task_self(),
port,
MACH_PORT_LIMITS_INFO,
mem::transmute(&limits),
&limits as *const mach_port_limits_t as *mut i32,
1,
)
};
Expand Down Expand Up @@ -243,7 +242,7 @@ impl OsIpcReceiver {
debug_assert!(port != MACH_PORT_NULL);
let (right, acquired_right) =
mach_port_extract_right(port, MACH_MSG_TYPE_MAKE_SEND as u32)?;
debug_assert!(acquired_right == MACH_MSG_TYPE_PORT_SEND as u32);
debug_assert!(acquired_right == MACH_MSG_TYPE_PORT_SEND);
Ok(OsIpcSender::from_name(right))
}

Expand All @@ -263,7 +262,7 @@ impl OsIpcReceiver {

let (right, acquired_right) =
mach_port_extract_right(port, MACH_MSG_TYPE_MAKE_SEND as u32)?;
debug_assert!(acquired_right == MACH_MSG_TYPE_PORT_SEND as u32);
debug_assert!(acquired_right == MACH_MSG_TYPE_PORT_SEND);

let mut os_result;
let mut name;
Expand Down Expand Up @@ -396,7 +395,7 @@ impl<'a> SendData<'a> {

fn inline_data(&self) -> &[u8] {
match *self {
SendData::Inline(ref data) => data,
SendData::Inline(data) => data,
SendData::OutOfLine(_) => &[],
}
}
Expand Down Expand Up @@ -442,7 +441,7 @@ impl Clone for OsIpcSender {
impl OsIpcSender {
fn from_name(port: mach_port_t) -> OsIpcSender {
OsIpcSender {
port: port,
port,
nosync_marker: PhantomData,
}
}
Expand Down Expand Up @@ -534,7 +533,7 @@ impl OsIpcSender {
let padding_count = Message::payload_padding(padding_start as usize);
// Zero out padding
padding_start.write_bytes(0, padding_count);
let data_size_dest = padding_start.offset(padding_count as isize) as *mut usize;
let data_size_dest = padding_start.add(padding_count) as *mut usize;
*data_size_dest = data_size;

let data_dest = data_size_dest.offset(1) as *mut u8;
Expand Down Expand Up @@ -628,7 +627,7 @@ impl OsIpcReceiverSet {
pub fn new() -> Result<OsIpcReceiverSet, MachError> {
let port = mach_port_allocate(MACH_PORT_RIGHT_PORT_SET)?;
Ok(OsIpcReceiverSet {
port: port,
port,
ports: vec![],
})
}
Expand Down Expand Up @@ -796,7 +795,7 @@ fn select(
let payload = if has_inline_data {
let padding_start = has_inline_data_ptr.offset(1) as *mut u8;
let padding_count = Message::payload_padding(padding_start as usize);
let payload_size_ptr = padding_start.offset(padding_count as isize) as *mut usize;
let payload_size_ptr = padding_start.add(padding_count) as *mut usize;
let payload_size = *payload_size_ptr;
let max_payload_size = message as usize + ((*message).header.msgh_size as usize)
- (shared_memory_descriptor as usize);
Expand Down Expand Up @@ -831,7 +830,7 @@ pub struct OsIpcOneShotServer {

impl Drop for OsIpcOneShotServer {
fn drop(&mut self) {
let _ = OsIpcReceiver::unregister_global_name(mem::replace(&mut self.name, String::new()));
let _ = OsIpcReceiver::unregister_global_name(std::mem::take(&mut self.name));
deallocate_mach_port(self.registration_port);
}
}
Expand All @@ -842,7 +841,7 @@ impl OsIpcOneShotServer {
let (registration_port, name) = receiver.register_bootstrap_name()?;
Ok((
OsIpcOneShotServer {
receiver: receiver,
receiver,
name: name.clone(),
registration_port,
},
Expand Down Expand Up @@ -943,10 +942,7 @@ impl Deref for OsIpcSharedMemory {

impl OsIpcSharedMemory {
unsafe fn from_raw_parts(ptr: *mut u8, length: usize) -> OsIpcSharedMemory {
OsIpcSharedMemory {
ptr: ptr,
length: length,
}
OsIpcSharedMemory { ptr, length }
}

pub fn from_byte(byte: u8, length: usize) -> OsIpcSharedMemory {
Expand Down Expand Up @@ -978,7 +974,7 @@ unsafe fn allocate_vm_pages(length: usize) -> *mut u8 {
}

unsafe fn setup_receive_buffer(buffer: &mut [u8], port_name: mach_port_t) {
let message: *mut mach_msg_header_t = mem::transmute(&buffer[0]);
let message = buffer.as_mut_ptr() as *mut mach_msg_header_t;
(*message).msgh_local_port = port_name;
(*message).msgh_size = buffer.len() as u32
}
Expand Down
18 changes: 9 additions & 9 deletions src/platform/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn medium_data() {
received_channels,
received_shared_memory_regions
),
(&data[..], vec![], vec![])
(data, vec![], vec![])
);
}

Expand Down Expand Up @@ -206,7 +206,7 @@ fn check_big_data(size: u32) {
received_channels,
received_shared_memory_regions
),
(&data[..], vec![], vec![])
(data, vec![], vec![])
);
thread.join().unwrap();
}
Expand Down Expand Up @@ -241,7 +241,7 @@ fn big_data_with_sender_transfer() {
let data: Vec<u8> = (0..1024 * 1024).map(|i| (i % 251) as u8).collect();
let data: &[u8] = &data[..];
assert_eq!(received_data.len(), data.len());
assert_eq!(&received_data[..], &data[..]);
assert_eq!(&received_data[..], data);
assert_eq!(received_channels.len(), 1);
assert_eq!(received_shared_memory_regions.len(), 0);

Expand All @@ -257,7 +257,7 @@ fn big_data_with_sender_transfer() {
received_channels,
received_shared_memory_regions
),
(&data[..], vec![], vec![])
(data, vec![], vec![])
);
thread.join().unwrap();
}
Expand Down Expand Up @@ -464,7 +464,7 @@ fn concurrent_senders() {
received_channels,
received_shared_memory_regions
),
(&data[..], vec![], vec![])
(data, vec![], vec![])
);
}
assert!(rx.try_recv().is_err()); // There should be no further messages pending.
Expand Down Expand Up @@ -635,8 +635,8 @@ fn receiver_set_medium_data() {
.map(|offset| (offset % 127) as u8 | 0x80)
.collect();

tx0.send(&*data0, vec![], vec![]).unwrap();
tx1.send(&*data1, vec![], vec![]).unwrap();
tx0.send(&data0, vec![], vec![]).unwrap();
tx1.send(&data1, vec![], vec![]).unwrap();
let (mut received0, mut received1) = (false, false);
while !received0 || !received1 {
for result in rx_set.select().unwrap().into_iter() {
Expand Down Expand Up @@ -673,11 +673,11 @@ fn receiver_set_big_data() {
let (reference_data0, reference_data1) = (data0.clone(), data1.clone());

let thread0 = thread::spawn(move || {
tx0.send(&*data0, vec![], vec![]).unwrap();
tx0.send(&data0, vec![], vec![]).unwrap();
tx0 // Don't close just yet -- the receiver-side test code below doesn't expect that...
});
let thread1 = thread::spawn(move || {
tx1.send(&*data1, vec![], vec![]).unwrap();
tx1.send(&data1, vec![], vec![]).unwrap();
tx1
});

Expand Down
10 changes: 4 additions & 6 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use crate::ipc::IpcReceiver;
use crate::ipc::{self, IpcReceiverSet, IpcSender, IpcSharedMemory};
use crate::router::{RouterProxy, ROUTER};
use crossbeam_channel::{self, Sender};
#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))]
use libc;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::cell::RefCell;
#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))]
Expand All @@ -33,7 +31,7 @@ use std::process::{self, Command, Stdio};
target_os = "windows",
)))]
use std::ptr;
use std::sync::Arc;
use std::rc::Rc;
use std::thread;

#[cfg(not(any(
Expand Down Expand Up @@ -122,7 +120,7 @@ pub fn spawn_server(test_name: &str, server_args: &[(&str, &str)]) -> process::C
.args(
server_args
.iter()
.map(|&(ref name, ref val)| format!("channel_name-{}:{}", name, val)),
.map(|(name, val)| format!("channel_name-{}:{}", name, val)),
)
.stdin(Stdio::null())
.stdout(Stdio::null())
Expand Down Expand Up @@ -585,7 +583,7 @@ fn try_recv_timeout() {
fn multiple_paths_to_a_sender() {
let person = ("Patrick Walton".to_owned(), 29);
let (sub_tx, sub_rx) = ipc::channel().unwrap();
let person_and_sender = Arc::new((person.clone(), sub_tx));
let person_and_sender = Rc::new((person.clone(), sub_tx));
let send_data = vec![
person_and_sender.clone(),
person_and_sender.clone(),
Expand Down Expand Up @@ -644,7 +642,7 @@ fn test_so_linger() {
#[derive(Clone, Debug, Eq, PartialEq)]
struct HasWeirdSerializer(Option<String>);

thread_local! { static WEIRD_CHANNEL: RefCell<Option<IpcSender<HasWeirdSerializer>>> = RefCell::new(None) }
thread_local! { static WEIRD_CHANNEL: RefCell<Option<IpcSender<HasWeirdSerializer>>> = const { RefCell::new(None) } }

impl Serialize for HasWeirdSerializer {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down

0 comments on commit 8b5bb30

Please sign in to comment.