diff --git a/Cargo.toml b/Cargo.toml index 11f46deaf..517d34c07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,9 @@ path = "bzip2recover.rs" [dependencies] libc.workspace = true -libbz2-rs-sys = { workspace = true, features = ["stdio", "std", "rust-allocator"] } +# we need `std` here, because we test the log output of the binaries, and those only +# get printed when std is enabled. +libbz2-rs-sys = { workspace = true, features = ["stdio", "c-allocator"] } [dev-dependencies] tempfile = "3.13.0" diff --git a/bzip2.rs b/bzip2.rs index 9236417c7..de8017bbb 100644 --- a/bzip2.rs +++ b/bzip2.rs @@ -965,7 +965,6 @@ fn outOfMemory(config: &Config) -> ! { } fn configError() -> ! { - panic!(); const MSG: &str = concat!( "bzip2: I'm not configured correctly for this platform!\n", "\tI require Int32, Int16 and Char to have sizes\n", diff --git a/libbz2-rs-sys/src/lib.rs b/libbz2-rs-sys/src/lib.rs index 11fac3228..fda71bfcb 100644 --- a/libbz2-rs-sys/src/lib.rs +++ b/libbz2-rs-sys/src/lib.rs @@ -83,10 +83,31 @@ pub(crate) use libbz2_rs_sys_version; // --- debug logs +#[cfg(all(not(feature = "std"), feature = "stdio"))] +pub(crate) struct StderrWritter; + +#[cfg(all(not(feature = "std"), feature = "stdio"))] +impl core::fmt::Write for StderrWritter { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + use core::ffi::c_void; + use libc::write; + + unsafe { + write(2, s.as_ptr() as *const c_void, s.len()); + } + Ok(()) + } +} + macro_rules! debug_log { ($($arg:tt)*) => { #[cfg(feature = "std")] std::eprint!($($arg)*); + #[cfg(all(not(feature = "std"), feature = "stdio"))] + { + use core::fmt::Write; + write!($crate::StderrWritter, $($arg)*); + } }; } @@ -94,6 +115,11 @@ macro_rules! debug_logln { ($($arg:tt)*) => { #[cfg(feature = "std")] std::eprintln!($($arg)*); + #[cfg(all(not(feature = "std"), feature = "stdio"))] + { + use core::fmt::Write; + writeln!($crate::StderrWritter, $($arg)*); + } }; }