From d2828384f6ae0d0a8a23218d608507eb343c83bd Mon Sep 17 00:00:00 2001 From: Geoff Martin Date: Mon, 11 Sep 2023 10:37:50 +0100 Subject: [PATCH 1/2] Updating to bindgen 0.68. --- Cargo.toml | 2 +- examples/disco.rs | 2 +- src/qos.rs | 36 ++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0d963bd..8df3c8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0.154", features = ["derive"] } serde_json = "1.0.94" [build-dependencies] -bindgen = "0.60" +bindgen = "0.68" cmake = "0.1" [features] diff --git a/examples/disco.rs b/examples/disco.rs index 94418d7..b6c768d 100644 --- a/examples/disco.rs +++ b/examples/disco.rs @@ -45,7 +45,7 @@ unsafe extern "C" fn on_data(dr: dds_entity_t, arg: *mut std::os::raw::c_void) { dr, samples.as_mut_ptr() as *mut *mut libc::c_void, si.as_mut_ptr() as *mut dds_sample_info_t, - MAX_SAMPLES as u64, + MAX_SAMPLES, MAX_SAMPLES as u32, ); let si = si.assume_init(); diff --git a/src/qos.rs b/src/qos.rs index 2df755f..7c5a04b 100644 --- a/src/qos.rs +++ b/src/qos.rs @@ -522,7 +522,7 @@ pub struct EntityName { } unsafe fn user_data_from_qos_native(qos: *const dds_qos_t) -> Option> { - let mut sz: size_t = 0; + let mut sz: usize = 0; let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_userdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership @@ -544,13 +544,13 @@ unsafe fn user_data_to_qos_native(qos: *mut dds_qos_t, user_data: &Option Option> { - let mut sz: size_t = 0; + let mut sz: usize = 0; let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_topicdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership @@ -572,13 +572,13 @@ unsafe fn topic_data_to_qos_native(qos: *mut dds_qos_t, topic_data: &Option Option> { - let mut sz: size_t = 0; + let mut sz: usize = 0; let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_groupdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership @@ -600,7 +600,7 @@ unsafe fn group_data_to_qos_native(qos: *mut dds_qos_t, group_data: &Option Date: Mon, 11 Sep 2023 10:47:21 +0100 Subject: [PATCH 2/2] Addressing clippy issues. --- build.rs | 9 +++---- src/qos.rs | 70 ++++++++++++++++-------------------------------------- 2 files changed, 24 insertions(+), 55 deletions(-) diff --git a/build.rs b/build.rs index 3d17eff..e5dfcae 100644 --- a/build.rs +++ b/build.rs @@ -63,13 +63,12 @@ fn main() { #[cfg(not(any(target_os = "windows", target_os = "macos")))] println!("cargo:rustc-link-lib=stdc++"); - #[cfg(any(target_os = "macos"))] + #[cfg(target_os = "macos")] println!("cargo:rustc-link-lib=c++"); } #[cfg(not(feature = "iceoryx"))] { - cyclonedds = cyclonedds - .define("ENABLE_SHM", "NO"); + cyclonedds = cyclonedds.define("ENABLE_SHM", "NO"); } // Finish configuration of cyclonedds build @@ -148,9 +147,7 @@ fn main() { .blocklist_type("^(.*IMAGE_TLS_DIRECTORY.*)$"); // Generate bindings - let bindings = bindings - .generate() - .expect("Unable to generate bindings"); + let bindings = bindings.generate().expect("Unable to generate bindings"); bindings .write_to_file(out_dir.join("bindings.rs")) diff --git a/src/qos.rs b/src/qos.rs index 7c5a04b..4a295ba 100644 --- a/src/qos.rs +++ b/src/qos.rs @@ -526,11 +526,7 @@ unsafe fn user_data_from_qos_native(qos: *const dds_qos_t) -> Option> { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_userdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership - let vector = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz as usize, - sz as usize, - ); + let vector = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); Some(vector) } else { None @@ -541,11 +537,7 @@ unsafe fn user_data_to_qos_native(qos: *mut dds_qos_t, user_data: &Option Option> { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_topicdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership - let vector = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz as usize, - sz as usize, - ); + let vector = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); Some(vector) } else { None @@ -569,11 +557,7 @@ unsafe fn topic_data_to_qos_native(qos: *mut dds_qos_t, topic_data: &Option Option> { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); if dds_qget_groupdata(qos, &mut value, &mut sz) { // Cyclone DDS returns a copy of the value so okay to take ownership - let vector = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz as usize, - sz as usize, - ); + let vector = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); Some(vector) } else { None @@ -597,11 +577,7 @@ unsafe fn group_data_to_qos_native(qos: *mut dds_qos_t, group_data: &Option Option> { - +unsafe fn data_representation_from_qos_native( + qos: *const dds_qos_t, +) -> Option> { let mut n: u32 = 0; let mut values_ptr: *mut dds_data_representation_id_t = std::ptr::null_mut(); @@ -1223,7 +1200,10 @@ unsafe fn data_representation_from_qos_native(qos: *const dds_qos_t) -> Option>) { +unsafe fn data_representation_to_qos_native( + qos: *mut dds_qos_t, + data_representation: &Option>, +) { if let Some(values) = data_representation { dds_qset_data_representation(qos, values.len() as u32, values.as_ptr()); } @@ -1325,11 +1305,7 @@ fn test_user_data_to_native() { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); assert!(dds_qget_userdata(qos_native, &mut value, &mut sz)); - let output = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz, - sz, - ); + let output = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); assert!(output.len() == 5); assert_eq!(output, policy.unwrap()); @@ -1371,11 +1347,7 @@ fn test_topic_data_to_native() { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); assert!(dds_qget_topicdata(qos_native, &mut value, &mut sz)); - let output = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz, - sz, - ); + let output = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); assert!(output.len() == 5); assert_eq!(output, policy.unwrap()); @@ -1417,11 +1389,7 @@ fn test_group_data_to_native() { let mut value: *mut ::std::os::raw::c_void = std::ptr::null_mut(); assert!(dds_qget_groupdata(qos_native, &mut value, &mut sz)); - let output = Vec::from_raw_parts( - value as *mut ::std::os::raw::c_uchar, - sz, - sz, - ); + let output = Vec::from_raw_parts(value as *mut ::std::os::raw::c_uchar, sz, sz); assert!(output.len() == 5); assert_eq!(output, policy.unwrap()); @@ -2798,7 +2766,11 @@ fn test_data_representation_to_native() { let mut n: u32 = 0; let mut values_ptr: *mut dds_data_representation_id_t = std::ptr::null_mut(); - assert!(dds_qget_data_representation(qos_native, &mut n, &mut values_ptr)); + assert!(dds_qget_data_representation( + qos_native, + &mut n, + &mut values_ptr + )); assert_eq!(n, values.len() as u32); for k in 0..n {