Skip to content

Commit 5a7d5b1

Browse files
author
Bryant Mairs
committed
Fix kevent for netbsd filter datatype
The datatype for kevent.filter is u32 on NetBSD and i16 on all other supported platforms. This was recently fixed in upstream libc, breaking this API, so this fixes it. This change also modernizes the code a bit to unify the EventFilter datatype across platforms and switch to the libc_enum! macro.
1 parent 7221a1c commit 5a7d5b1

File tree

1 file changed

+32
-43
lines changed

1 file changed

+32
-43
lines changed

src/sys/event.rs

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,40 @@ type type_of_udata = intptr_t;
3030
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
3131
type type_of_data = libc::int64_t;
3232

33+
#[cfg(target_os = "netbsd")]
34+
type type_of_event_filter = u32;
3335
#[cfg(not(target_os = "netbsd"))]
3436
type type_of_event_filter = i16;
35-
#[cfg(not(target_os = "netbsd"))]
36-
#[repr(i16)]
37-
#[derive(Clone, Copy, Debug, PartialEq)]
38-
pub enum EventFilter {
39-
EVFILT_AIO = libc::EVFILT_AIO,
40-
#[cfg(target_os = "dragonfly")]
41-
EVFILT_EXCEPT = libc::EVFILT_EXCEPT,
42-
#[cfg(any(target_os = "macos", target_os = "ios",
43-
target_os = "dragonfly",
44-
target_os = "freebsd"))]
45-
EVFILT_FS = libc::EVFILT_FS,
46-
#[cfg(target_os = "freebsd")]
47-
EVFILT_LIO = libc::EVFILT_LIO,
48-
#[cfg(any(target_os = "macos", target_os = "ios"))]
49-
EVFILT_MACHPORT = libc::EVFILT_MACHPORT,
50-
EVFILT_PROC = libc::EVFILT_PROC,
51-
EVFILT_READ = libc::EVFILT_READ,
52-
EVFILT_SIGNAL = libc::EVFILT_SIGNAL,
53-
EVFILT_TIMER = libc::EVFILT_TIMER,
54-
#[cfg(any(target_os = "macos",
55-
target_os = "ios",
56-
target_os = "dragonfly",
57-
target_os = "freebsd"))]
58-
EVFILT_USER = libc::EVFILT_USER,
59-
#[cfg(any(target_os = "macos", target_os = "ios"))]
60-
EVFILT_VM = libc::EVFILT_VM,
61-
EVFILT_VNODE = libc::EVFILT_VNODE,
62-
EVFILT_WRITE = libc::EVFILT_WRITE,
63-
}
64-
65-
#[cfg(target_os = "netbsd")]
66-
type type_of_event_filter = libc::uint32_t;
67-
#[cfg(target_os = "netbsd")]
68-
#[repr(i32)]
69-
#[derive(Clone, Copy, Debug, PartialEq)]
70-
pub enum EventFilter {
71-
EVFILT_READ = libc::EVFILT_READ,
72-
EVFILT_WRITE = libc::EVFILT_WRITE,
73-
EVFILT_AIO = libc::EVFILT_AIO,
74-
EVFILT_VNODE = libc::EVFILT_VNODE,
75-
EVFILT_PROC = libc::EVFILT_PROC,
76-
EVFILT_SIGNAL = libc::EVFILT_SIGNAL,
77-
EVFILT_TIMER = libc::EVFILT_TIMER,
37+
libc_enum!{
38+
#[cfg_attr(target_os = "netbsd", repr(u32))]
39+
#[cfg_attr(not(target_os = "netbsd"), repr(i16))]
40+
pub enum EventFilter {
41+
EVFILT_AIO,
42+
#[cfg(target_os = "dragonfly")]
43+
EVFILT_EXCEPT,
44+
#[cfg(any(target_os = "dragonfly",
45+
target_os = "freebsd",
46+
target_os = "ios",
47+
target_os = "macos"))]
48+
EVFILT_FS,
49+
#[cfg(target_os = "freebsd")]
50+
EVFILT_LIO,
51+
#[cfg(any(target_os = "ios", target_os = "macos"))]
52+
EVFILT_MACHPORT,
53+
EVFILT_PROC,
54+
EVFILT_READ,
55+
EVFILT_SIGNAL,
56+
EVFILT_TIMER,
57+
#[cfg(any(target_os = "dragonfly",
58+
target_os = "freebsd",
59+
target_os = "ios",
60+
target_os = "macos"))]
61+
EVFILT_USER,
62+
#[cfg(any(target_os = "ios", target_os = "macos"))]
63+
EVFILT_VM,
64+
EVFILT_VNODE,
65+
EVFILT_WRITE,
66+
}
7867
}
7968

8069
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",

0 commit comments

Comments
 (0)