-
Notifications
You must be signed in to change notification settings - Fork 1k
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 kqueue filter consts type on NetBSD [WAS: Provide EV_SET] #787
Conversation
930b50d
to
f7c3e97
Compare
Thanks for the PR! Right now though this crate does not provide functions like this, this'd be an implementation detail in a downstream crate. |
Ok, understandable. Are macros out of question too? (Ie. maybe provide an |
Nah macros should be fine to add, there's already a number here |
Allrighty then, I'll refactor the code... |
Oh so actually you may want to look for invocations of the |
Ok, take three using |
src/unix/bsd/apple/mod.rs
Outdated
pub type kevent_nevents = ::c_int; | ||
pub type kevent_filter = ::int16_t; | ||
pub type kevent_flags = ::uint16_t; | ||
pub type kevent_fflags = ::uint32_t; |
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.
Hm if these don't actually exist, how come we're defining them?
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.
Well, the idea is that, for example, kevent_nevents
is "the type that the kevent
function uses for the nevents
param on this BSD variant" (it varies). So that in user code I can cast a variable as kevent_nevents
without having to worry about which particular BSD I'm currently on. Same for the other kevent_*
types.
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 makes sense, yes, but it's not what libc does. We don't add things that aren't in headers.
src/unix/bsd/apple/mod.rs
Outdated
@@ -1969,6 +1973,18 @@ f! { | |||
pub fn WIFSTOPPED(status: ::c_int) -> bool { | |||
_WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13 | |||
} | |||
|
|||
pub fn EV_SET(ident: ::uintptr_t, filter: kevent_filter, flags: kevent_flags, |
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.
These macros aren't like their C counterparts where they take a kevent
as the first argument?
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, yes, I wrote it this way so that you don't need to first create an uninitialized kevent
struct. But I don't have a strong opinion on 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.
I think we should stick to the C macros as much as possible
I'll fix those long lines... |
Ok, so, since platform abstractions aren't allowed, I guess I'll just make this into the netbsd const fixes. The only other way of making |
Ok, sounds like |
Sorry for the delay. So I just reduced this to the fix for NetBSD. (Waiting for CI now.) |
@bors: r+ |
📌 Commit a0e683e has been approved by |
Fix kqueue filter consts type on NetBSD [WAS: Provide EV_SET] Using BSD kqueue's `kevent` structure is tedious, because some BSD variants define the structure slightly differently. This forces user's code to differentiate between BSD variants and initialize `kevent` accordingly, which is annoying and error-prone. For an example, refer to [MIO](https://github.com/carllerche/mio/blob/master/src/sys/unix/kqueue.rs#L38). This is an attempt to fix it - provide a ctor function with the same signature across BSD variants. Is an `impl` piece for a C structure allowed in libc? **edit:** I noticed the `kevent` function has a similar problem, maybe I should include a fix for that too... **edit:** ^ Done
☀️ Test successful - status-appveyor, status-travis |
Using BSD kqueue's
kevent
structure is tedious, because some BSD variants define the structure slightly differently. This forces user's code to differentiate between BSD variants and initializekevent
accordingly, which is annoying and error-prone.For an example, refer to MIO.
This is an attempt to fix it - provide a ctor function with the same signature across BSD variants.
Is an
impl
piece for a C structure allowed in libc?edit: I noticed the
kevent
function has a similar problem, maybe I should include a fix for that too...edit: ^ Done