Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Xlib {
}

/// Load the Xlib library at runtime.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
#[cfg(not(feature = "dlopen"))]
pub(crate) fn load() -> Result<Self, std::io::Error> {
#[link(name = "X11", kind = "dylib")]
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Xlib {
}

/// Load the Xlib library at runtime.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
#[cfg(feature = "dlopen")]
pub(crate) fn load() -> Result<Self, libloading::Error> {
let xlib_library = unsafe { load_library(XLIB_LIBDIR, &["libX11.so.6", "libX11.so"]) }?;
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Xlib {
}

#[cfg(feature = "dlopen")]
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
unsafe fn load_library(
prefix: Option<&str>,
names: &[&str],
Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
//! [`libloading`]: https://crates.io/crates/libloading

#![allow(unused_unsafe)]
#![cfg_attr(coverage, feature(no_coverage))]
#![cfg_attr(coverage, feature(coverage_attribute))]

mod ffi;

Expand All @@ -135,7 +135,7 @@ use std::sync::{Mutex, MutexGuard, Once, PoisonError};
macro_rules! lock {
($e:expr) => {{
// Make sure this isn't flagged with coverage.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
fn unwrapper<T>(guard: PoisonError<MutexGuard<'_, T>>) -> MutexGuard<'_, T> {
guard.into_inner()
}
Expand All @@ -146,7 +146,7 @@ macro_rules! lock {

ctor_lite::ctor! {
unsafe static XLIB: io::Result<ffi::Xlib> = {
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
unsafe fn load_xlib_with_error_hook() -> io::Result<ffi::Xlib> {
// Here's a puzzle: how do you *safely* add an error hook to Xlib? Like signal handling, there
// is a single global error hook. Therefore, we need to make sure that we economize on the
Expand All @@ -163,14 +163,14 @@ ctor_lite::ctor! {
// sets the error hook to a dummy function, reads the resulting error hook into a static
// variable, and then resets the error hook to the default function. This allows us to read
// the default error hook and compare it to the one that we're setting.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
fn error(e: impl std::error::Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, format!("failed to load Xlib: {}", e))
}
let xlib = ffi::Xlib::load().map_err(error)?;

// Dummy function we use to set the error hook.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
unsafe extern "C" fn dummy(
_display: *mut ffi::Display,
_error: *mut ffi::XErrorEvent,
Expand Down Expand Up @@ -199,7 +199,7 @@ ctor_lite::ctor! {
#[inline]
fn get_xlib(sym: &io::Result<ffi::Xlib>) -> io::Result<&ffi::Xlib> {
// Eat coverage on the error branch.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
fn error(e: &io::Error) -> io::Error {
io::Error::new(e.kind(), e.to_string())
}
Expand All @@ -224,7 +224,7 @@ unsafe extern "C" fn error_handler(
// Abort the program if the error hook panics.
struct AbortOnPanic;
impl Drop for AbortOnPanic {
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
#[cold]
#[inline(never)]
fn drop(&mut self) {
Expand Down Expand Up @@ -501,7 +501,7 @@ enum Slot {

impl HandlerList {
/// Create a new handler list.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
const fn new() -> Self {
Self {
slots: vec![],
Expand All @@ -516,7 +516,7 @@ impl HandlerList {
/// Returns the index of the handler.
fn insert(&mut self, handler: ErrorHook) -> usize {
// Eat the coverage for the unreachable branch.
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
#[inline(always)]
fn unwrapper(slot: &Slot) -> usize {
match slot {
Expand Down Expand Up @@ -570,7 +570,7 @@ struct ErrorHookSlot(Cell<Option<ffi::XErrorHook>>);
unsafe impl Sync for ErrorHookSlot {}

impl ErrorHookSlot {
#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
const fn new() -> Self {
Self(Cell::new(None))
}
Expand All @@ -579,7 +579,7 @@ impl ErrorHookSlot {
self.0.get()
}

#[cfg_attr(coverage, no_coverage)]
#[cfg_attr(coverage, coverage(off))]
unsafe fn set(&self, hook: ffi::XErrorHook) {
self.0.set(Some(hook));
}
Expand Down