Unix: scope sighandler_t to GNU/Linux platforms - #5445
Conversation
|
Where does the PR message template go? 🤔 |
743f5f6 to
2cfc13d
Compare
There was a problem hiding this comment.
There are still some tests failing. Could you also update the commit message and PR description to mention this is only on platforms that don't exist? Sounds a bit like unconditional removal as-is.
With
sighandler_tremoved on non-GNU targets, should I also clean up the existing skip rules such asskip_alias("sighandler_t")andrename_typeetc. inlibc-test/build/main.rsin this PR? (I am worried that I might break the tests. 🫣)
Yes please! The point is to clean up those tests :)
Basically, ideally, all mentions of sighandler_t should be deleted and then libc is updated as-needed to make things work. We might need a few skips still not nearly as many as are currently there.
| #[cfg(any( | ||
| target_vendor = "apple", | ||
| target_os = "freebsd", | ||
| target_os = "dragonfly", | ||
| target_os = "netbsd", | ||
| target_os = "openbsd" | ||
| )))] | ||
| pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; | ||
| ))] | ||
| pub fn signal(signum: c_int, handler: sig_t) -> sig_t; | ||
|
|
||
| #[cfg(any( | ||
| #[cfg(not(any( | ||
| target_os = "linux", | ||
| target_os = "l4re", | ||
| target_os = "android", | ||
| target_os = "emscripten", | ||
| target_os = "hurd", | ||
| target_vendor = "apple", | ||
| target_os = "freebsd", | ||
| target_os = "dragonfly", | ||
| target_os = "netbsd", | ||
| target_os = "openbsd" | ||
| ))] | ||
| pub fn signal(signum: c_int, handler: sig_t) -> sig_t; | ||
| )))] | ||
| pub fn signal( | ||
| signum: c_int, | ||
| handler: Option<unsafe extern "C" fn(c_int)>, | ||
| ) -> Option<unsafe extern "C" fn(c_int)>; |
There was a problem hiding this comment.
This cfg is complex. Delete signal from this file and add it back to each of the child modules, with the correct definition.
|
Reminder, once the PR becomes ready for a review, use |
sighandler_tBackground: Refer to `libc-test/build/main.rs`, sighandler_t` is a GNU extension provided by glibc on Linux and Hurd. Non-GNU Unix platforms (such as BSDs, Solaris, AIX, and Cygwin) do not define `sighandler_t` in their native C headers (BSDs define `sig_t` instead). Fixes: Scope `sighandler_t` to `linux_like` and `hurd`, removing it from non-GNU platforms.
Since `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` are changed to `size_t` for apple platform, `ctest` fails on Apple because its C headers define them as function pointers. Fixes: - Skip `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` in `test_apple`. (Follow what other BSDs have already done) - Remove the obsolete `rename_type` for `sighandler_t`.
dfcb972 to
36ad7e0
Compare
Since `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` were changed to `size_t` for FreeBSD, `ctest` failed because C headers define them as function pointer macros. Fixes: - Skip `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` in `test_freebsd`. - Remove obsolete `rename_type` for `sighandler_t`.
36ad7e0 to
b7b8c32
Compare
Move `signal()` from `src/unix/mod.rs` to child platforms repectively to reduce the codebase complexity
Since `c_int` is already re-exported in `crate::prelude::*`, explicitly qualifying it with `crate::` is redundant.
08ac48b to
5c0e174
Compare
Since `sighandler_t` was scoped to GNU/Linux platforms, several test configs and semver files became obsolete. - Remove `skip_alias` and `rename_type` for `sighandler_t` across non-GNU Unix targets in `libc-test/build/main.rs`. - Remove obsolete `signal` skips in Solarish, Neutrino, and AIX, where `signal` was using `sighandler_t`. => Now using function pointers. - Update `SIG_DFL`/`SIG_ERR`/`SIG_IGN` comments to clarify they are C function pointers mapped to Rust `size_t`. - Remove `sighandler_t` from `semver/aix.txt`, `semver/nto.txt`, and `semver/qnx.txt`.
5c0e174 to
039ddbe
Compare
|
@rustbot ready Note: Honestly, I didn't go through |
There was a problem hiding this comment.
Skimming this it looks plausable, but could you scope only to removing sighandler_t on unsupported platforms? Currently it does that but also changes the signatures to take Option<unsafe extern "C" fn(c_int)> while the actual 1:1 substitute is size_t. That is something we want and we can't remove all test skips until that happens, but it would be better in a separate PR.
@dybucc could you review this as well since you've been working in the area?
| cfg_if! { | ||
| if #[cfg(any( | ||
| target_os = "linux", | ||
| target_os = "l4re", | ||
| target_os = "android", | ||
| target_os = "emscripten", | ||
| target_os = "hurd" | ||
| ))] { | ||
| pub const SIG_DFL: sighandler_t = 0 as sighandler_t; | ||
| pub const SIG_IGN: sighandler_t = 1 as sighandler_t; | ||
| pub const SIG_ERR: sighandler_t = !0 as sighandler_t; | ||
| } else { | ||
| pub const SIG_DFL: size_t = 0; | ||
| pub const SIG_IGN: size_t = 1; | ||
| pub const SIG_ERR: size_t = !0; | ||
| } | ||
| } |
There was a problem hiding this comment.
These should be split across platfoms too
| pub type useconds_t = u32; | ||
| pub type key_t = c_int; | ||
| pub type id_t = c_uint; | ||
| pub type sighandler_t = size_t; |
There was a problem hiding this comment.
Is this actually available on all linux-like platforms? I.e. emscripten, linux, android, l4re
This comment has been minimized.
This comment has been minimized.
|
Actually could you make this PR just split the definitions up and deprecate Also, no AI when communicating with humans please. That includes commit messages and PR descriptions. (This needs a squash anyway) Sorry for the conflict, I cleaned up the |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I use AI as a drafting tool for my commit messages and PR templates because English is not my first language. However, every single word is reviewed, judged, and intentionally chosen by me. I never copy-paste AI output without double-checking. Every sentence in PRs or commit messages is I believe it can help with code review and git history tracing. Could you point out specifically where you feel it is over-expressed? E.g., which paragraphs you think are unnecessary I am open to any suggestions for improvement. |
This PR fixes part of #1273 1 and #1359.
Question:
With
sighandler_tremoved on non-GNU targets, should I also clean up the existing skip rules such asskip_alias("sighandler_t")andrename_typeetc. inlibc-test/build/main.rsin this PR? (I am worried that I might break the tests. 🫣)[EDIT 2026-09-03]
sighandler_tis a GNU extension provided by glibc on Linux and Hurd.Non-GNU Unix platforms 2 do not define
sighandler_tin their native C headers (BSDs definesig_tinstead).Previously,
sighandler_twas declared insrc/unix/mod.rsfor all Unix platforms,causing type mismatches and requiring workarounds in test configurations.
Changes
pub type sighandler_t = size_t;only to GNU/Linux-like platforms (linux_likeandhurd).sighandler_tfrom non-GNU platforms where it does not exist natively in C headers.SIG_DFL,SIG_IGN, andSIG_ERRinctest.Footnotes
https://github.com/rust-lang/libc/issues/1273#issuecomment-5436574721 ↩
BSDs, Solaris, AIX, and Cygwin ↩