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

Fix epoll bug in release mode on Rust 1.20+ #805

Merged
merged 2 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,9 @@ matrix:
rust: 1.13.0
os: osx

# Testing beta on main targets
# Make sure stable is always working too
- env: TARGET=x86_64-unknown-linux-gnu
rust: beta

allow_failures:
# We allow beta to fail here because a bug might crop up in rust that causes it. We will
# however be on the lookout for this and file those bugs with upstream.
- env: TARGET=x86_64-unknown-linux-gnu
rust: beta
rust: stable

before_install: set -e

Expand Down
24 changes: 10 additions & 14 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ impl EpollEvent {
}
}

impl<'a> Into<&'a mut EpollEvent> for Option<&'a mut EpollEvent> {
#[inline]
fn into(self) -> &'a mut EpollEvent {
match self {
Some(epoll_event) => epoll_event,
None => unsafe { &mut *ptr::null_mut::<EpollEvent>() }
}
}
}

#[inline]
pub fn epoll_create() -> Result<RawFd> {
let res = unsafe { libc::epoll_create(1024) };
Expand All @@ -91,13 +81,19 @@ pub fn epoll_create1(flags: EpollCreateFlags) -> Result<RawFd> {

#[inline]
pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result<()>
where T: Into<&'a mut EpollEvent>
where T: Into<Option<&'a mut EpollEvent>>
{
let event: &mut EpollEvent = event.into();
if event as *const EpollEvent == ptr::null() && op != EpollOp::EpollCtlDel {
let mut event: Option<&mut EpollEvent> = event.into();
if event.is_none() && op != EpollOp::EpollCtlDel {
Err(Error::Sys(Errno::EINVAL))
} else {
let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) };
let res = unsafe {
if let Some(ref mut event) = event {
libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event)
} else {
libc::epoll_ctl(epfd, op as c_int, fd, ptr::null_mut())
}
};
Errno::result(res).map(drop)
}
}
Expand Down