#[cfg(any(debug_assertions, feature = "debug"))]
#[allow(unused_macros)]
#[macro_use]
pub mod enabled {
use alloc::vec::Vec;
extern "C" {
fn sig(msg: *const u8); }
fn cstr(s: &str) -> Vec<u8> {
let mut bytes = Vec::with_capacity(s.len() + 1); bytes.extend_from_slice(s.as_bytes()); bytes.push(0); bytes
}
pub(crate) fn signal(message: &str) {
let c_string = cstr(message); unsafe {
sig(c_string.as_ptr()); }
}
macro_rules! eprintln {
($($arg:tt)*) => {{
let formatted = alloc::format!($($arg)*);
$crate::ffi::debug::enabled::signal(&formatted);
}};
}
macro_rules! dbg {
() => {
eprintln!("[{}:{}:{}]", file!(), line!(), column!())
};
($val:expr $(,)?) => {
match $val {
tmp => {
eprintln!("[{}:{}:{}] {} = {:#?}",
file!(), line!(), column!(), stringify!($val), &tmp);
tmp
}
}
};
($($val:expr),+ $(,)?) => {
($(dbg!($val)),+,)
};
}
}
#[cfg(not(any(debug_assertions, feature = "debug")))]
#[allow(unused_macros)]
#[macro_use]
pub mod disabled {
macro_rules! dbg {
($val:expr) => {
$val
};
($($arg:tt)*) => {};
}
macro_rules! eprintln {
($($arg:tt)*) => {};
}
}