From 7a921aab648b08a348420c9b649d45fd1932886b Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Mon, 5 Aug 2024 17:02:37 +0200 Subject: [PATCH] generate panic messages only if explicitly asked (#569) * generate panic messages only if explicitly asked * doc comments restored --- build-resources/opaque-types/Cargo.toml | 1 + build-resources/opaque-types/src/lib.rs | 15 ++++++++++----- build.rs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/build-resources/opaque-types/Cargo.toml b/build-resources/opaque-types/Cargo.toml index 562a71381..2554a58bf 100644 --- a/build-resources/opaque-types/Cargo.toml +++ b/build-resources/opaque-types/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [features] shared-memory = ["zenoh/shared-memory", "dep:zenoh-ext", "zenoh-ext/shared-memory", "zenoh-protocol/shared-memory"] unstable = ["zenoh/unstable", "zenoh-ext/unstable", "dep:zenoh-ext"] +panic = [] # The whole purpose of this project is to generate set of compilation panic messages with calculated structure sizes. To do it the "panic" feature should be set. By default we just want to check if build is successful. default = ["zenoh/default"] [dependencies] diff --git a/build-resources/opaque-types/src/lib.rs b/build-resources/opaque-types/src/lib.rs index ba7aa95f7..b0370ceef 100644 --- a/build-resources/opaque-types/src/lib.rs +++ b/build-resources/opaque-types/src/lib.rs @@ -1,7 +1,6 @@ -#[cfg(all(feature = "shared-memory", feature = "unstable"))] +#![allow(unused_doc_comments)] use core::ffi::c_void; use std::{ - collections::HashMap, sync::{Arc, Condvar, Mutex, MutexGuard}, thread::JoinHandle, }; @@ -9,7 +8,7 @@ use std::{ use zenoh::{ bytes::{Encoding, ZBytes, ZBytesIterator, ZBytesReader, ZBytesWriter}, config::Config, - handlers::{DefaultHandler, RingChannelHandler}, + handlers::RingChannelHandler, key_expr::KeyExpr, pubsub::{Publisher, Subscriber}, query::{Query, Queryable, Reply, ReplyError}, @@ -44,6 +43,7 @@ macro_rules! get_opaque_type_data { const SIZE: usize = std::mem::size_of::<$src_type>(); const INFO_MESSAGE: &str = concatcp!("type: ", DST_NAME, ", align: ", ALIGN, ", size: ", SIZE); + #[cfg(feature = "panic")] panic!("{}", INFO_MESSAGE); }; }; @@ -56,9 +56,14 @@ get_opaque_type_data!(ZBytes, z_owned_bytes_t); /// A loaned serialized Zenoh data. get_opaque_type_data!(ZBytes, z_loaned_bytes_t); -type CSlice = (usize, usize, usize, usize); +pub struct CSlice { + _data: *const u8, + _len: usize, + _drop: Option, + _context: *mut c_void, +} + -/// A contiguous owned sequence of bytes allocated by Zenoh. get_opaque_type_data!(CSlice, z_owned_slice_t); /// A contiguous sequence of bytes owned by some other entity. get_opaque_type_data!(CSlice, z_view_slice_t); diff --git a/build.rs b/build.rs index 5a589e96c..008d964f6 100644 --- a/build.rs +++ b/build.rs @@ -104,7 +104,7 @@ fn produce_opaque_types_data() -> PathBuf { let stdio = Stdio::from(out_file); #[allow(unused_mut)] - let mut feature_args: Vec<&str> = vec![]; + let mut feature_args: Vec<&str> = vec!["-F", "panic"]; // enable output structure sizes in panic messages during build for (rust_feature, _c_feature) in RUST_TO_C_FEATURES.entries() { if test_feature(rust_feature) { feature_args.push("-F");