From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/sharded-slab/src/macros.rs | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 vendor/sharded-slab/src/macros.rs (limited to 'vendor/sharded-slab/src/macros.rs') diff --git a/vendor/sharded-slab/src/macros.rs b/vendor/sharded-slab/src/macros.rs new file mode 100644 index 000000000..e431f64f1 --- /dev/null +++ b/vendor/sharded-slab/src/macros.rs @@ -0,0 +1,67 @@ +macro_rules! test_println { + ($($arg:tt)*) => { + if cfg!(test) && cfg!(slab_print) { + if std::thread::panicking() { + // getting the thread ID while panicking doesn't seem to play super nicely with loom's + // mock lazy_static... + println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*)) + } else { + println!("[{:?} {:>17}:{:<3}] {}", crate::Tid::::current(), file!(), line!(), format_args!($($arg)*)) + } + } + } +} + +#[cfg(all(test, loom))] +macro_rules! test_dbg { + ($e:expr) => { + match $e { + e => { + test_println!("{} = {:?}", stringify!($e), &e); + e + } + } + }; +} + +macro_rules! panic_in_drop { + ($($arg:tt)*) => { + if !std::thread::panicking() { + panic!($($arg)*) + } else { + let thread = std::thread::current(); + eprintln!( + "thread '{thread}' attempted to panic at '{msg}', {file}:{line}:{col}\n\ + note: we were already unwinding due to a previous panic.", + thread = thread.name().unwrap_or(""), + msg = format_args!($($arg)*), + file = file!(), + line = line!(), + col = column!(), + ); + } + } +} + +macro_rules! debug_assert_eq_in_drop { + ($this:expr, $that:expr) => { + debug_assert_eq_in_drop!(@inner $this, $that, "") + }; + ($this:expr, $that:expr, $($arg:tt)+) => { + debug_assert_eq_in_drop!(@inner $this, $that, format_args!(": {}", format_args!($($arg)+))) + }; + (@inner $this:expr, $that:expr, $msg:expr) => { + if cfg!(debug_assertions) { + if $this != $that { + panic_in_drop!( + "assertion failed ({} == {})\n left: `{:?}`,\n right: `{:?}`{}", + stringify!($this), + stringify!($that), + $this, + $that, + $msg, + ) + } + } + } +} -- cgit v1.2.3