Skip to content
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

Merged
merged 1 commit into from
Jun 27, 2016
Merged

Signal enum #362

merged 1 commit into from
Jun 27, 2016

Conversation

fiveop
Copy link
Contributor

@fiveop fiveop commented Apr 25, 2016

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.

pub const SIGEMT: libc::c_int = 7;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Signal {
SIGHUP = libc::SIGHUP as isize,
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fiveop
Copy link
Contributor Author

fiveop commented Apr 30, 2016

@kamalmarhubi I commented on yours. Now, it is your turn ;)

}

// TODO: NOT PUBLIC :/
pub type SigNum = libc::c_int;
Copy link
Member

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.

Copy link
Contributor Author

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).

@kamalmarhubi
Copy link
Member

Not for this PR: one thing from looking more closely at this module than I have before: do the thread functions really belong as impl SigSet? I think they would more belong on the thread object via some extensions trait.

@fiveop
Copy link
Contributor Author

fiveop commented May 5, 2016

I worked on this PR again, after adapting code that uses the sys::signal module.

Since I have to write functions with C-ABI as signal handlers, which have to take SigNum instead of Signal because of type safety, I noticed that it does make sense to export the conversion function from SigNum to Signal, so the From trait fits the bill perfectly.

I am now pretty happy with the state of the PR. Any more remarks?

}


pub type SigNum = libc::c_int;
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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...

Copy link
Contributor Author

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.

Copy link
Member

@kamalmarhubi kamalmarhubi May 6, 2016

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 a Result<T, E>.

http://doc.rust-lang.org/std/convert/trait.From.html

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@fiveop
Copy link
Contributor Author

fiveop commented May 5, 2016

I changed how the iterator is created.

@fiveop
Copy link
Contributor Author

fiveop commented May 6, 2016

I worked on this again. Two things changed:

  • The From implementation was replaced by the signal_from function because From may not fail. A comment regarding the comming trait TryFrom was added.
  • Signal::iterator now returns our own Iterator struct, so that changes in implementation won't break the interface.

@kamalmarhubi
Copy link
Member

  • The From implementation was replaced by the signal_from function because From may not fail. A comment regarding the comming trait TryFrom was added.

Given this change, the motivation for having SigNum in our public API seems a bit weaker. Do you think we can remove it now?

@kamalmarhubi
Copy link
Member

kamalmarhubi commented May 6, 2016

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.)

@homu
Copy link
Contributor

homu commented May 6, 2016

☔ The latest upstream changes (presumably #361) made this pull request unmergeable. Please resolve the merge conflicts.

@fiveop
Copy link
Contributor Author

fiveop commented May 7, 2016

I removed SigNum. With signal_from failing properly it makes sense.

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)]
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@kamalmarhubi
Copy link
Member

Ok I think I will promise not to make any more requests after these three I just made!

@fiveop
Copy link
Contributor Author

fiveop commented Jun 3, 2016

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;
Copy link
Member

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?

@kamalmarhubi
Copy link
Member

@fiveop

I only see two messages? What's the third concern?

Honestly no idea! Maybe I can't count past one correctly. Anyway, feel free to r=me once signal_from changes. Thanks so much for doing this!

@homu
Copy link
Contributor

homu commented Jun 11, 2016

☔ The latest upstream changes (presumably #376) made this pull request unmergeable. Please resolve the merge conflicts.

@fiveop
Copy link
Contributor Author

fiveop commented Jun 11, 2016

finally done?

@kamalmarhubi
Copy link
Member

@homu r+

🎉

@homu
Copy link
Contributor

homu commented Jun 12, 2016

📌 Commit 98063a7 has been approved by kamalmarhubi

homu added a commit that referenced this pull request Jun 12, 2016
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
Copy link
Contributor

homu commented Jun 12, 2016

⌛ Testing commit 98063a7 with merge c418266...

@kamalmarhubi
Copy link
Member

@homu r-

@kamalmarhubi
Copy link
Member

Some failures on Apple?

#[cfg(target_os = "macos")]
SIGEMT = libc::SIGEMT,
#[cfg(target_os = "macos")]
SIGINFO = libc::SIGEMT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamalmarhubi typo here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @fiveop

@homu
Copy link
Contributor

homu commented Jun 12, 2016

💔 Test failed - status

@fiveop
Copy link
Contributor Author

fiveop commented Jun 26, 2016

this should be good to merge now as well (finally! :))

@posborne
Copy link
Member

Although @kamalmarhubi did most of the reviewing before, I looked things over again and it looks good to me. @homu r+

@homu
Copy link
Contributor

homu commented Jun 27, 2016

📌 Commit 5c7b3c1 has been approved by posborne

@homu
Copy link
Contributor

homu commented Jun 27, 2016

⚡ Test exempted - status

@homu homu merged commit 5c7b3c1 into nix-rust:master Jun 27, 2016
homu added a commit that referenced this pull request Jun 27, 2016
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.
@fiveop fiveop deleted the signal_enum branch June 29, 2016 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants