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

Some clippy fixes #122

Closed
wants to merge 4 commits into from
Closed
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 examples/rpc_math_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! - Using MQTT v5 properties
//! - Publishing RPC request messages
//! - Using asynchronous tokens
//! - Subscribing to reply topic
//! - Subscribing to reply topic
//

/*******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc_math_srvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! - Using MQTT v5 properties
//! - Receiving RPC request messages, and sending replies.
//! - Using asynchronous tokens
//! - Subscribing to request topic
//! - Subscribing to request topic
//

/*******************************************************************************
Expand Down
16 changes: 7 additions & 9 deletions paho-mqtt-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,22 @@ mod build {

// Link in the SSL libraries if configured for it.
if cfg!(feature = "ssl") {
let openssl_root_dir = openssl_root_dir();
if cfg!(windows) {
println!("cargo:rustc-link-lib=libssl");
println!("cargo:rustc-link-lib=libcrypto");
if let Some(openssl_root_dir) = openssl_root_dir() {
let openssl_root_dir = openssl_root_dir
.as_deref()
.or_else(|| cfg!(target_arch = "x86").then(||"C:\\OpenSSL-Win32"))
.or_else(|| cfg!(target_arch = "x86_64").then(||"C:\\OpenSSL-Win64"));
if let Some(openssl_root_dir) = openssl_root_dir {
println!("cargo:rustc-link-search={}\\lib", openssl_root_dir);
}
else {
#[cfg(target_arch = "x86")]
println!("cargo:rustc-link-search={}\\lib", "C:\\OpenSSL-Win32");

#[cfg(target_arch = "x86_64")]
println!("cargo:rustc-link-search={}\\lib", "C:\\OpenSSL-Win64");
};
}
else {
println!("cargo:rustc-link-lib=ssl");
println!("cargo:rustc-link-lib=crypto");
if let Some(openssl_root_dir) = openssl_root_dir() {
if let Some(openssl_root_dir) = openssl_root_dir {
println!("cargo:rustc-link-search={}/lib", openssl_root_dir);
}
}
Expand Down
59 changes: 25 additions & 34 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,20 +1155,16 @@ mod tests {
let data = cli.user_data();
assert!(data.is_some());

if let Some(lock) = data.unwrap().downcast_ref::<Mutex<Vec<&str>>>() {
let mut v = lock.lock().unwrap();
assert_eq!(3, v.len());
assert_eq!("zero", v[0]);
assert_eq!("one", v[1]);
assert_eq!("two", v[2]);

v.push("three");
assert_eq!(4, v.len());
assert_eq!("three", v[3]);
}
else {
assert!(false);
}
let lock = data.unwrap().downcast_ref::<Mutex<Vec<&str>>>().unwrap();
let mut v = lock.lock().unwrap();
assert_eq!(3, v.len());
assert_eq!("zero", v[0]);
assert_eq!("one", v[1]);
assert_eq!("two", v[2]);

v.push("three");
assert_eq!(4, v.len());
assert_eq!("three", v[3]);
}

#[test]
Expand All @@ -1185,28 +1181,23 @@ mod tests {
assert!(data.is_some());
let data = data.unwrap();

if let Some(lock) = data.downcast_ref::<RwLock<Vec<&str>>>() {
// Try reading
{
let v = lock.read().unwrap();
assert_eq!(3, v.len());
assert_eq!("zero", v[0]);
assert_eq!("one", v[1]);
assert_eq!("two", v[2]);
}

// Now try writing
{
let mut v = lock.write().unwrap();
v.push("three");
assert_eq!(4, v.len());
assert_eq!("three", v[3]);
}
}
else {
assert!(false);
let lock = data.downcast_ref::<RwLock<Vec<&str>>>().unwrap();
// Try reading
{
let v = lock.read().unwrap();
assert_eq!(3, v.len());
assert_eq!("zero", v[0]);
assert_eq!("one", v[1]);
assert_eq!("two", v[2]);
}

// Now try writing
{
let mut v = lock.write().unwrap();
v.push("three");
assert_eq!(4, v.len());
assert_eq!("three", v[3]);
}
}

// Determine that a client can be sent across threads.
Expand Down
25 changes: 12 additions & 13 deletions src/client_persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::{
ffi::{CString, CStr},
os::raw::{c_void, c_char, c_int},
};
use libc;

use crate::{
ffi,
Expand Down Expand Up @@ -131,9 +130,9 @@ impl UserPersistence
let client_id = CStr::from_ptr(client_id).to_str().unwrap();
let server_uri = CStr::from_ptr(server_uri).to_str().unwrap();

let persist: &mut Box<dyn ClientPersistence> = mem::transmute(context);
let persist = &mut *(context as *mut std::boxed::Box<dyn ClientPersistence>);

if let Ok(_) = persist.open(client_id, server_uri) {
if persist.open(client_id, server_uri).is_ok() {
*handle = context;
return PERSISTENCE_SUCCESS;
}
Expand All @@ -148,7 +147,7 @@ impl UserPersistence
return PERSISTENCE_ERROR;
}

let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);

match persist.close() {
Ok(_) => PERSISTENCE_SUCCESS,
Expand All @@ -170,7 +169,7 @@ impl UserPersistence
if bufcount == 0 {
return PERSISTENCE_SUCCESS;
}
let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);
let key = CStr::from_ptr(key).to_str().unwrap();

let mut bufs: Vec<&[u8]> = Vec::new();
Expand All @@ -197,7 +196,7 @@ impl UserPersistence
buffer.is_null() || buflen.is_null() {
return PERSISTENCE_ERROR;
}
let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);
let key = CStr::from_ptr(key).to_str().unwrap();

match persist.get(key) {
Expand All @@ -221,7 +220,7 @@ impl UserPersistence
if handle.is_null() || key.is_null() {
return PERSISTENCE_ERROR;
}
let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);
let key = CStr::from_ptr(key).to_str().unwrap();

match persist.remove(key) {
Expand All @@ -240,7 +239,7 @@ impl UserPersistence
return PERSISTENCE_ERROR;
}

let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);

*keys = ptr::null_mut();
*nkeys = 0;
Expand All @@ -251,14 +250,14 @@ impl UserPersistence
if n != 0 {
// TODO OPTIMIZE: This does a lot of copying
let ckeys = libc::malloc(n * mem::size_of::<usize>()) as *mut *mut c_char;
for i in 0..n {
let s = CString::new(k[i].clone()).unwrap();
for (i, s) in k.into_iter().enumerate() {
let s = CString::new(s).unwrap();
let sb = s.as_bytes_with_nul();
let sn = sb.len();
let cbuf = libc::malloc(sn) as *mut c_char;
ptr::copy(sb.as_ptr(), cbuf as *mut u8, sn);

*ckeys.offset(i as isize) = cbuf;
*ckeys.add(i) = cbuf;
}
*keys = ckeys;
*nkeys = n as c_int;
Expand All @@ -276,7 +275,7 @@ impl UserPersistence
if handle.is_null() {
return PERSISTENCE_ERROR;
}
let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);

match persist.clear() {
Ok(_) => PERSISTENCE_SUCCESS,
Expand All @@ -292,7 +291,7 @@ impl UserPersistence
if handle.is_null() || key.is_null() {
return PERSISTENCE_ERROR;
}
let persist: &mut Box<dyn ClientPersistence> = mem::transmute(handle);
let persist = &mut *(handle as *mut std::boxed::Box<dyn ClientPersistence>);
let key = CStr::from_ptr(key).to_str().unwrap();

if persist.contains_key(key) { 1 } else { 0 }
Expand Down
Loading