Skip to content

Commit

Permalink
Change KEvent to treat udata as an intptr_t instead of a uintptr_t.
Browse files Browse the repository at this point in the history
This matches NetBSD's C definitions.  Other operating systems define
it as void*, despite not really being a pointer, but none actually
define it as uintptr_t.  Better to be right on NetBSD and wrong
everywhere else than wrong everywhere.  Plus, it's what mio expects.
  • Loading branch information
asomers committed Nov 11, 2016
1 parent 853a7db commit 0ac31d2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ pub fn kqueue() -> Result<RawFd> {


// KEvent can't derive Send because on some operating systems, udata is defined
// as a void*. However, KEvent's public API always treats udata as a uintptr_t,
// as a void*. However, KEvent's public API always treats udata as an intptr_t,
// which is safe to Send.
unsafe impl Send for KEvent {
}

impl KEvent {
pub fn new(ident: uintptr_t, filter: EventFilter, flags: EventFlag,
fflags:FilterFlag, data: intptr_t, udata: uintptr_t) -> KEvent {
fflags:FilterFlag, data: intptr_t, udata: intptr_t) -> KEvent {
KEvent { kevent: libc::kevent {
ident: ident,
filter: filter as type_of_event_filter,
Expand Down Expand Up @@ -231,8 +231,8 @@ impl KEvent {
self.kevent.data
}

pub fn udata(&self) -> uintptr_t {
self.kevent.udata as uintptr_t
pub fn udata(&self) -> intptr_t {
self.kevent.udata as intptr_t
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ pub fn ev_set(ev: &mut KEvent,
filter: EventFilter,
flags: EventFlag,
fflags: FilterFlag,
udata: uintptr_t) {
udata: intptr_t) {

ev.kevent.ident = ident as uintptr_t;
ev.kevent.filter = filter as type_of_event_filter;
Expand All @@ -294,7 +294,7 @@ pub fn ev_set(ev: &mut KEvent,

#[test]
fn test_struct_kevent() {
let udata : uintptr_t = 12345;
let udata : intptr_t = 12345;

let expected = libc::kevent{ident: 0xdeadbeef,
filter: libc::EVFILT_READ,
Expand Down

0 comments on commit 0ac31d2

Please sign in to comment.