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

Updated bindgen to 0,68 #17

Merged
merged 2 commits into from
Sep 11, 2023
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.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 3 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion examples/disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
88 changes: 30 additions & 58 deletions src/qos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,11 @@ pub struct EntityName {
}

unsafe fn user_data_from_qos_native(qos: *const dds_qos_t) -> Option<Vec<u8>> {
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
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
Expand All @@ -541,24 +537,16 @@ unsafe fn user_data_to_qos_native(qos: *mut dds_qos_t, user_data: &Option<Vec<u8
if let Some(user_data) = user_data {
// Cyclone DDS makes a copy of the data
let ptr = user_data.as_ptr();
dds_qset_userdata(
qos,
ptr as *const ::std::os::raw::c_void,
user_data.len() as size_t,
);
dds_qset_userdata(qos, ptr as *const ::std::os::raw::c_void, user_data.len());
}
}

unsafe fn topic_data_from_qos_native(qos: *const dds_qos_t) -> Option<Vec<u8>> {
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
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
Expand All @@ -569,24 +557,16 @@ unsafe fn topic_data_to_qos_native(qos: *mut dds_qos_t, topic_data: &Option<Vec<
if let Some(topic_data) = topic_data {
// Cyclone DDS makes a copy of the data
let ptr = topic_data.as_ptr();
dds_qset_topicdata(
qos,
ptr as *const ::std::os::raw::c_void,
topic_data.len() as size_t,
);
dds_qset_topicdata(qos, ptr as *const ::std::os::raw::c_void, topic_data.len());
}
}

unsafe fn group_data_from_qos_native(qos: *const dds_qos_t) -> Option<Vec<u8>> {
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
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
Expand All @@ -597,11 +577,7 @@ unsafe fn group_data_to_qos_native(qos: *mut dds_qos_t, group_data: &Option<Vec<
if let Some(group_data) = group_data {
// Cyclone DDS makes a copy of the data
let ptr = group_data.as_ptr();
dds_qset_groupdata(
qos,
ptr as *const ::std::os::raw::c_void,
group_data.len() as size_t,
);
dds_qset_groupdata(qos, ptr as *const ::std::os::raw::c_void, group_data.len());
}
}

Expand Down Expand Up @@ -1204,8 +1180,9 @@ unsafe fn entity_name_to_qos_native(qos: *mut dds_qos_t, entity_name: &Option<En
}
}

unsafe fn data_representation_from_qos_native(qos: *const dds_qos_t) -> Option<Vec<dds_data_representation_id_t>> {

unsafe fn data_representation_from_qos_native(
qos: *const dds_qos_t,
) -> Option<Vec<dds_data_representation_id_t>> {
let mut n: u32 = 0;
let mut values_ptr: *mut dds_data_representation_id_t = std::ptr::null_mut();

Expand All @@ -1223,7 +1200,10 @@ unsafe fn data_representation_from_qos_native(qos: *const dds_qos_t) -> Option<V
}
}

unsafe fn data_representation_to_qos_native(qos: *mut dds_qos_t, data_representation: &Option<Vec<dds_data_representation_id_t>>) {
unsafe fn data_representation_to_qos_native(
qos: *mut dds_qos_t,
data_representation: &Option<Vec<dds_data_representation_id_t>>,
) {
if let Some(values) = data_representation {
dds_qset_data_representation(qos, values.len() as u32, values.as_ptr());
}
Expand Down Expand Up @@ -1321,15 +1301,11 @@ fn test_user_data_to_native() {
let policy = Some(create_u8_vec_for_tests());
user_data_to_qos_native(qos_native, &policy);

let mut sz: size_t = 0;
let mut sz: usize = 0;
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 as usize,
sz as usize,
);
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());

Expand All @@ -1347,7 +1323,7 @@ fn test_user_data_from_native() {
dds_qset_userdata(
qos_native,
ptr as *const ::std::os::raw::c_void,
test_vec.len() as size_t,
test_vec.len(),
);

let policy = user_data_from_qos_native(qos_native);
Expand All @@ -1367,15 +1343,11 @@ fn test_topic_data_to_native() {
let policy = Some(create_u8_vec_for_tests());
topic_data_to_qos_native(qos_native, &policy);

let mut sz: size_t = 0;
let mut sz: usize = 0;
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 as usize,
sz as usize,
);
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());

Expand All @@ -1393,7 +1365,7 @@ fn test_topic_data_from_native() {
dds_qset_topicdata(
qos_native,
ptr as *const ::std::os::raw::c_void,
test_vec.len() as size_t,
test_vec.len(),
);

let policy = topic_data_from_qos_native(qos_native);
Expand All @@ -1413,15 +1385,11 @@ fn test_group_data_to_native() {
let policy = Some(create_u8_vec_for_tests());
group_data_to_qos_native(qos_native, &policy);

let mut sz: size_t = 0;
let mut sz: usize = 0;
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 as usize,
sz as usize,
);
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());

Expand All @@ -1439,7 +1407,7 @@ fn test_group_data_from_native() {
dds_qset_groupdata(
qos_native,
ptr as *const ::std::os::raw::c_void,
test_vec.len() as size_t,
test_vec.len(),
);

let policy = group_data_from_qos_native(qos_native);
Expand Down Expand Up @@ -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 {
Expand Down
Loading