Skip to content

Commit

Permalink
generate panic messages only if explicitly asked (#569)
Browse files Browse the repository at this point in the history
* generate panic messages only if explicitly asked

* doc comments restored
  • Loading branch information
milyin authored Aug 5, 2024
1 parent f36da63 commit 7a921aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions build-resources/opaque-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 10 additions & 5 deletions build-resources/opaque-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#[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,
};

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},
Expand Down Expand Up @@ -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);
};
};
Expand All @@ -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<extern "C" fn(data: *mut c_void, context: *mut c_void)>,
_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);
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 7a921aa

Please sign in to comment.