Skip to content

Commit

Permalink
Merge #1296
Browse files Browse the repository at this point in the history
1296: DragonFlyBSD: use __errno_location now provided by the libc crate r=asomers a=cmusser

Dragonfly recently (in Dfly 5.8) added an `__errno_location()` function to make it easy to access the thread-local `errno` variable. This has been exposed in rust-libc as of 0.2.77. This PR uses that functionality instead of the locally compiled C language shim, which the PR removes. One issue is backwards compatibilty. It requires 0.2.77 libc and DragonFly 5.8. Not sure how to gracefully handle older DragonFly versions, although I'm also not sure doing so is worth it.

Co-authored-by: Chuck Musser <[email protected]>
  • Loading branch information
bors[bot] and cmusser authored Oct 3, 2020
2 parents 7ed2820 + f5ee22d commit 7e46b95
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 33 deletions.
9 changes: 0 additions & 9 deletions build.rs

This file was deleted.

24 changes: 3 additions & 21 deletions src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cfg_if::cfg_if;
#[cfg(not(target_os = "dragonfly"))]
use libc::{c_int, c_void};
use std::{fmt, io, error};
use crate::{Error, Result};
Expand All @@ -13,32 +12,15 @@ cfg_if! {
unsafe fn errno_location() -> *mut c_int {
libc::__error()
}
} else if #[cfg(target_os = "dragonfly")] {
// DragonFly uses a thread-local errno variable, but #[thread_local] is
// feature-gated and not available in stable Rust as of this writing
// (Rust 1.21.0). We have to use a C extension to access it
// (src/errno_dragonfly.c).
//
// Tracking issue for `thread_local` stabilization:
//
// https://github.com/rust-lang/rust/issues/29594
//
// Once this becomes stable, we can remove build.rs,
// src/errno_dragonfly.c, and use:
//
// extern { #[thread_local] static errno: c_int; }
//
#[link(name="errno_dragonfly", kind="static")]
extern {
pub fn errno_location() -> *mut c_int;
}
} else if #[cfg(any(target_os = "android",
target_os = "netbsd",
target_os = "openbsd"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno()
}
} else if #[cfg(any(target_os = "linux", target_os = "redox"))] {
} else if #[cfg(any(target_os = "linux",
target_os = "redox",
target_os = "dragonfly"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
Expand Down
3 changes: 0 additions & 3 deletions src/errno_dragonfly.c

This file was deleted.

0 comments on commit 7e46b95

Please sign in to comment.