-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Creating proper type for sighandler_t using anonymous union on Unix #2107
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Working on fixing the test suite errors. |
All checks are passing now. |
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.
Thanks for the PR!
But this should be a breaking change and I'd hold off unless it's a serious issue.
src/unix/mod.rs
Outdated
cfg_if! { | ||
if #[cfg(feature = "extra_traits")] { | ||
impl PartialEq for __c_anonymous_sigaction_handler { | ||
fn eq(&self, other: &__c_anonymous_sigaction_handler) -> bool { | ||
unsafe { self.default == other.default } | ||
} | ||
} | ||
impl Eq for __c_anonymous_sigaction_handler {} | ||
impl ::fmt::Debug for __c_anonymous_sigaction_handler { | ||
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { | ||
f.debug_struct("sigaction_t") | ||
.field("value", unsafe { &self.default } ) | ||
.finish() | ||
} | ||
} | ||
impl ::hash::Hash for __c_anonymous_sigaction_handler { | ||
fn hash<H: ::hash::Hasher>(&self, state: &mut H) { | ||
unsafe { self.default.hash(state) }; | ||
} | ||
} | ||
} | ||
} |
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.
Could you move this before the consts declaration?
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.
Yep! Moved in 6913b31. Let me know if that's where you meant.
@@ -27,7 +27,7 @@ pub type uid_t = u32; | |||
pub type gid_t = u32; | |||
pub type in_addr_t = u32; | |||
pub type in_port_t = u16; | |||
pub type sighandler_t = ::size_t; | |||
pub type sighandler_t = __c_anonymous_sigaction_handler; |
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.
Is the current type wrong on all the UNIX platforms?
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 believe so. Here's what I can dig up so far:
BSD/XNU uses one of the function pointer variants void (*sig_t)(int)
, and calls it sig_t
:
https://github.com/apple/darwin-xnu/blob/main/bsd/sys/signal.h#L500
https://github.com/NetBSD/src/blob/trunk/sys/sys/signal.h#L172
Haiku has both function pointer variants:
Hermit has the void (*signal_handler_t)(int)
:
Redox as well:
Also cc @Amanieu as I'm unfamiliar with this. |
The new version is more correct but I'm afraid it will be a significant breaking change so we should hold off on it until the next major release. |
☔ The latest upstream changes (presumably #3038) made this pull request unmergeable. Please resolve the merge conflicts. |
@landhb , breaking release of libc will be released soon. So, consider to continue this work |
Sorry for the delay @tgross35 @safinaskar I'll take a look and rebase on |
Resolves #1359
This PR allows you to use the sigaction struct on Unix properly. For instance you'll be able to create a new sigaction struct passing all three types of handlers, below demonstrates both the creation of a handler of type
void (*sa_handler)(int)
and forSIG_IGN
which is a constsize_t
: