-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix nix for Dragonfly #684
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,10 @@ pub type type_of_cmsg_len = socklen_t; | |
#[cfg(target_os = "macos")] | ||
pub type type_of_cmsg_data = c_uint; | ||
|
||
#[cfg(not(target_os = "macos"))] | ||
#[cfg(target_os = "dragonfly")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is correct! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're right. I didn't notice the "u". |
||
pub type type_of_cmsg_data = c_int; | ||
|
||
#[cfg(not(any(target_os = "macos", target_os = "dragonfly")))] | ||
pub type type_of_cmsg_data = size_t; | ||
|
||
// Private because we don't expose any external functions that operate | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,27 +145,34 @@ mod status { | |
target_os = "netbsd"))] | ||
mod status { | ||
use sys::signal::Signal; | ||
use libc::c_int; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it necessary to change all of these types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, if you want to be pedantically correct. But it's got nothing to do with DragonFly. It you're going to change those types, please do it in a separate commit, not comingled with DragonFly specific changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @asomers here, please remove this changes from this PR. |
||
|
||
const WCOREFLAG: i32 = 0x80; | ||
const WSTOPPED: i32 = 0x7f; | ||
const WCOREFLAG: c_int = 0x80; | ||
const WSTOPPED: c_int = 0x7f; | ||
|
||
fn wstatus(status: i32) -> i32 { | ||
fn wstatus(status: c_int) -> c_int { | ||
status & 0x7F | ||
} | ||
|
||
pub fn stopped(status: i32) -> bool { | ||
pub fn stopped(status: c_int) -> bool { | ||
wstatus(status) == WSTOPPED | ||
} | ||
|
||
pub fn stop_signal(status: i32) -> Signal { | ||
pub fn stop_signal(status: c_int) -> Signal { | ||
Signal::from_c_int(status >> 8).unwrap() | ||
} | ||
|
||
pub fn signaled(status: i32) -> bool { | ||
#[cfg(target_os = "dragonfly")] | ||
pub fn signaled(status: c_int) -> bool { | ||
wstatus(status) != WSTOPPED && wstatus(status) != 0 | ||
} | ||
|
||
#[cfg(not(target_os = "dragonfly"))] | ||
pub fn signaled(status: c_int) -> bool { | ||
wstatus(status) != WSTOPPED && wstatus(status) != 0 && status != 0x13 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the magic number 0x13 mean? This sounds like a constant that should be in libc. |
||
} | ||
|
||
pub fn term_signal(status: i32) -> Signal { | ||
pub fn term_signal(status: c_int) -> Signal { | ||
Signal::from_c_int(wstatus(status)).unwrap() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need an extra crate just for this. The basic symbols should all be defined in libc, and nix's won src/errno.rs defines
errno_location
. Can you merge whatever you need into nix and libc so we don't depend on the extra crate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there is no other possibility!!! I talked with @alexcrichton to make the thread_local attribute attribute stable, and he actually suggested me to write a C extension like errno-dragonfly.
libc
does not expose the errno variable directly AFAIK.The problem is that in DragonFly, the errno variable is not a global, but a thread locale variable, so a simple "extern __errno" as used by the other OSes simply does not work. In libstd, errno can be accessed by using "#[thread_local]", as unstable features are allowed for libstd.
If you want to support DragonFly there really isn't any other option to go via C atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ... sad. I took a stab at this myself. It doesn't look as though we can use
#[thread_local]
unless we enable it for all builds, not just Dragonfly's. Still, what would you say to moving the C extension into Nix instead of making it its own crate? Cargo just seems like an awfully heavyweight way to manage such a tiny amount of code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a problem with this crate staying external, though I'd much rather rely on a crate that had proper semver (i.e. was 1.0+).