Skip to content

Commit db41e0b

Browse files
bors[bot]asomers
andauthored
Merge #1716
1716: Future-proof the kevent ABI r=rtzoeller a=asomers FreeBSD 12 changes struct kevent. For now, libc always binds to the 11-compat ABI. But that will change some day. Adjust Nix's code to build with either struct definition. Co-authored-by: Alan Somers <[email protected]>
2 parents 68f3631 + b4fb5ee commit db41e0b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/sys/event.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use libc::{timespec, time_t, c_int, c_long, intptr_t, uintptr_t};
77
#[cfg(target_os = "netbsd")]
88
use libc::{timespec, time_t, c_long, intptr_t, uintptr_t, size_t};
99
use std::convert::TryInto;
10+
use std::mem;
1011
use std::os::unix::io::RawFd;
1112
use std::ptr;
1213

@@ -21,13 +22,8 @@ pub struct KEvent {
2122
target_os = "ios", target_os = "macos",
2223
target_os = "openbsd"))]
2324
type type_of_udata = *mut libc::c_void;
24-
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
25-
target_os = "ios", target_os = "macos"))]
26-
type type_of_data = intptr_t;
2725
#[cfg(any(target_os = "netbsd"))]
2826
type type_of_udata = intptr_t;
29-
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
30-
type type_of_data = i64;
3127

3228
#[cfg(target_os = "netbsd")]
3329
type type_of_event_filter = u32;
@@ -217,15 +213,18 @@ unsafe impl Send for KEvent {
217213
}
218214

219215
impl KEvent {
216+
#[allow(clippy::needless_update)] // Not needless on all platforms.
220217
pub fn new(ident: uintptr_t, filter: EventFilter, flags: EventFlag,
221218
fflags:FilterFlag, data: intptr_t, udata: intptr_t) -> KEvent {
222219
KEvent { kevent: libc::kevent {
223220
ident,
224221
filter: filter as type_of_event_filter,
225222
flags: flags.bits(),
226223
fflags: fflags.bits(),
227-
data: data as type_of_data,
228-
udata: udata as type_of_udata
224+
// data can be either i64 or intptr_t, depending on platform
225+
data: data as _,
226+
udata: udata as type_of_udata,
227+
.. unsafe { mem::zeroed() }
229228
} }
230229
}
231230

@@ -328,7 +327,7 @@ fn test_struct_kevent() {
328327
assert_eq!(libc::EVFILT_READ, filter);
329328
assert_eq!(libc::EV_ONESHOT | libc::EV_ADD, actual.flags().bits());
330329
assert_eq!(libc::NOTE_CHILD | libc::NOTE_EXIT, actual.fflags().bits());
331-
assert_eq!(0x1337, actual.data() as type_of_data);
330+
assert_eq!(0x1337, actual.data());
332331
assert_eq!(udata as type_of_udata, actual.udata() as type_of_udata);
333332
assert_eq!(mem::size_of::<libc::kevent>(), mem::size_of::<KEvent>());
334333
}

0 commit comments

Comments
 (0)