-
Notifications
You must be signed in to change notification settings - Fork 675
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
Signal enum #362
Signal enum #362
Conversation
pub const SIGEMT: libc::c_int = 7; | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum Signal { | ||
SIGHUP = libc::SIGHUP as isize, |
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 would have prefered #[repr(libc::c_int)]
but that does not seem to be possible. Maybe that's worth an RFC for the language.
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 came across the same issue in #364 though I decided to go with #[repr(i32)]
since the type of the constants in libc crate (c_int
is i32
unconditionally), and cast to c_int
at use. Thinking about it a bit more, I'm not super happy about it, because if libc ever makes c_int
conditional, we'll have trouble.
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.
And yeah, I think it would be good if the language supported type aliases in #[repr]
attributes.
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 worte a draft for an RFC regarding this: https://github.com/fiveop/rfcs/blob/master/text/0000-type-aliases-in-enumeration-repr-attritubes.md
@kamalmarhubi I commented on yours. Now, it is your turn ;) |
} | ||
|
||
// TODO: NOT PUBLIC :/ | ||
pub type SigNum = libc::c_int; |
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 wonder if we could instead define From<T> for Signal
for various integral types? Our code and user code could then write Signal::from(9)
for example.
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.
Signal::from(9) fits to the signal_from method above.In that case, I agree. However, I do not want to provide users access to it (as mentioned above).
Not for this PR: one thing from looking more closely at this module than I have before: do the thread functions really belong as |
I worked on this PR again, after adapting code that uses the Since I have to write functions with C-ABI as signal handlers, which have to take I am now pretty happy with the state of the PR. Any more remarks? |
} | ||
|
||
|
||
pub type SigNum = libc::c_int; |
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.
one thing I'm wondering is what to do we get out of an extra indirection here? posix specifies they be int
:
The <signal.h> header shall define the following macros that are used to refer to the signals that occur in the system. Signals defined here begin with the letters SIG followed by an uppercase letter. The macros shall expand to positive integer constant expressions with type int and distinct values. The value 0 is reserved for use as the null signal (see kill()). Additional implementation-defined signals may occur in the system.
—http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
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.
It signals that we do not only want any int but one out of the range for signals.
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.
but a type alias doesn't do anything to help with that?
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.
oh as documentation somehow, I see. hmmmm...
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 admit, that one can argue, that it hides the fact that it's unsafe.
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'm now wondering if we should be using From
for this. From docs:
Note: this trait must not fail. If the conversion can fail, use a dedicated method which return an
Option<T>
or aResult<T, E>
.
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.
The TryFrom/TryInto RFC was accepted 2 days ago.
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 will provide our own implementation and add a comment as well as issue regarding the new traits, once we merge this.
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.
@utkarshkukreti amazing! I knew it was being worked on, hadn't realized it was already written and merged.
I changed how the iterator is created. |
I worked on this again. Two things changed:
|
Given this change, the motivation for having |
Also @fiveop thanks for being so patient through all the comments! I'm reasonably sure this is the most commented PR yet. (GitHub's sort doesn't seem to work properly, so am not completely sure.) |
☔ The latest upstream changes (presumably #361) made this pull request unmergeable. Please resolve the merge conflicts. |
I removed Any more concerns? |
@@ -8,7 +8,6 @@ | |||
// latest bitflags triggers a rustc bug with cross-crate macro expansions causing dead_code | |||
// warnings even though the macro expands into something with allow(dead_code) | |||
#![allow(dead_code)] | |||
#![deny(warnings)] |
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 there a reason this was removed in this PR?
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.
Probably, because it wouldn't compile otherwise on whatever was the current nightly then. I'll recheck it, when I look at it again.
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 worries, was just curious.
Ok I think I will promise not to make any more requests after these three I just made! |
I only see two messages? What's the third concern? |
|
||
pub const SIGIOT : Signal = SIGABRT; | ||
pub const SIGPOLL : Signal = SIGIO; | ||
pub const SIGUNUSED : Signal = SIGSYS; |
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.
are these aliases cross-platform?
Honestly no idea! Maybe I can't count past one correctly. Anyway, feel free to r=me once |
☔ The latest upstream changes (presumably #376) made this pull request unmergeable. Please resolve the merge conflicts. |
finally done? |
@homu r+ 🎉 |
📌 Commit 98063a7 has been approved by |
Signal enum This is work in progress. I post this pull request as a request for discussion. I mark the lines I have doubts or ideas about. Ignore the first commit. It is the same as PR #361, which I wanted to base this change off.
@homu r- |
Some failures on Apple? |
#[cfg(target_os = "macos")] | ||
SIGEMT = libc::SIGEMT, | ||
#[cfg(target_os = "macos")] | ||
SIGINFO = libc::SIGEMT, |
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.
@kamalmarhubi typo here?
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.
cc @fiveop
💔 Test failed - status |
this should be good to merge now as well (finally! :)) |
Although @kamalmarhubi did most of the reviewing before, I looked things over again and it looks good to me. @homu r+ |
📌 Commit 5c7b3c1 has been approved by |
⚡ Test exempted - status |
Signal enum This is work in progress. I post this pull request as a request for discussion. I mark the lines I have doubts or ideas about. Ignore the first commit. It is the same as PR #361, which I wanted to base this change off.
This is work in progress. I post this pull request as a request for discussion. I mark the lines I have doubts or ideas about.
Ignore the first commit. It is the same as PR #361, which I wanted to base this change off.