From 611af74e5fbae234599bbfb9a379671cdd8cf40e Mon Sep 17 00:00:00 2001 From: Roma Sokolov Date: Wed, 19 Nov 2014 15:11:34 +0300 Subject: [PATCH] Use namespaced enum variants. As per this pull request https://github.com/rust-lang/rust/pull/18973, enum variants require fully qualified path to access them. This commit introduces boring changes to make nix-rust compiles againts new rust. --- src/errno.rs | 9 +++++---- src/fcntl.rs | 2 ++ src/sys/socket.rs | 19 +++++++++++++++---- src/sys/wait.rs | 2 ++ src/unistd.rs | 10 +++++++--- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/errno.rs b/src/errno.rs index e3ecee88eb..4e0ee53254 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -4,6 +4,7 @@ use std::num::from_uint; use libc::c_int; pub use self::consts::*; +pub use self::consts::Errno::*; pub type SysResult = Result; @@ -676,9 +677,9 @@ mod consts { EQFULL = 106, } - pub const ELAST: Errno = EQFULL; - pub const EWOULDBLOCK: Errno = EAGAIN; - pub const EDEADLOCK: Errno = EDEADLK; + pub const ELAST: Errno = Errno::EQFULL; + pub const EWOULDBLOCK: Errno = Errno::EAGAIN; + pub const EDEADLOCK: Errno = Errno::EDEADLK; - pub const EL2NSYNC: Errno = UnknownErrno; + pub const EL2NSYNC: Errno = Errno::UnknownErrno; } diff --git a/src/fcntl.rs b/src/fcntl.rs index 990e2bd465..49278f716f 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -100,6 +100,8 @@ pub enum FcntlArg<'a> { // TODO: Figure out how to handle value fcntl returns pub fn fcntl(fd: Fd, arg: FcntlArg) -> SysResult<()> { + use self::FcntlArg::*; + let res = unsafe { match arg { F_SETFD(flag) => ffi::fcntl(fd, ffi::F_SETFD, flag.bits()), diff --git a/src/sys/socket.rs b/src/sys/socket.rs index 36d181b58f..8ce0e842ce 100644 --- a/src/sys/socket.rs +++ b/src/sys/socket.rs @@ -1,7 +1,7 @@ use std::{mem, ptr, fmt}; -use std::num::Int; use libc::{c_void, c_int, socklen_t, size_t, ssize_t}; -use fcntl::{Fd, fcntl, F_SETFL, F_SETFD, FD_CLOEXEC, O_NONBLOCK}; +use fcntl::{Fd, fcntl, FD_CLOEXEC, O_NONBLOCK}; +use fcntl::FcntlArg::{F_SETFD, F_SETFL}; use errno::{SysResult, SysError, from_ffi}; use features; @@ -257,6 +257,8 @@ pub fn listen(sockfd: Fd, backlog: uint) -> SysResult<()> { } pub fn bind(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { + use self::SockAddr::*; + let res = unsafe { match *addr { SockIpV4(ref addr) => ffi::bind(sockfd, mem::transmute(addr), mem::size_of::() as socklen_t), @@ -330,6 +332,8 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> SysResult { } pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { + use self::SockAddr::*; + let res = unsafe { match *addr { SockIpV4(ref addr) => ffi::connect(sockfd, mem::transmute(addr), mem::size_of::() as socklen_t), @@ -344,7 +348,8 @@ pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { mod sa_helpers { use std::mem; use libc::{sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un}; - use super::{SockAddr, SockIpV6, SockIpV4, SockUnix}; + use super::SockAddr; + use super::SockAddr::*; pub fn to_sockaddr_ipv4(addr: &sockaddr_storage) -> SockAddr { let sin : &sockaddr_in = unsafe { mem::transmute(addr) }; @@ -385,6 +390,8 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> SysResult<(uint, SockAddr)> { } fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result { + use std::num::Int; + let ip_addr = Int::from_be(sin.sin_addr.s_addr); let port = Int::from_be(sin.sin_port); @@ -399,7 +406,7 @@ fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result { impl fmt::Show for SockAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - SockIpV4(sin) => print_ipv4_addr(&sin, f), + SockAddr::SockIpV4(sin) => print_ipv4_addr(&sin, f), _ => unimplemented!() } } @@ -420,6 +427,8 @@ fn sendto_sockaddr(sockfd: Fd, buf: &[u8], flags: SockMessageFlags, addr: &T) } pub fn sendto(sockfd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> SysResult { + use self::SockAddr::*; + let ret = match *addr { SockIpV4(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr), SockIpV6(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr), @@ -482,6 +491,8 @@ fn getsockname_sockaddr(sockfd: Fd, addr: &T) -> SysResult { } pub fn getsockname(sockfd: Fd, addr: &mut SockAddr) -> SysResult { + use self::SockAddr::*; + match *addr { SockIpV4(ref addr) => getsockname_sockaddr(sockfd, addr), SockIpV6(ref addr) => getsockname_sockaddr(sockfd, addr), diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 6f232bffd0..018f406208 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -21,6 +21,8 @@ pub enum WaitStatus { } pub fn waitpid(pid: pid_t, options: WaitPidFlag) -> SysResult { + use self::WaitStatus::*; + let mut status: i32 = 0; let res = unsafe { ffi::waitpid(pid as pid_t, &mut status as *mut c_int, options.bits()) }; diff --git a/src/unistd.rs b/src/unistd.rs index 1c8ed6ab9f..1dc7e7d8e5 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1,7 +1,9 @@ use std::{mem, ptr}; use std::c_str::{CString, ToCStr}; use libc::{c_char, c_void, c_int, size_t, pid_t, off_t}; -use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC, F_SETFD, F_SETFL}; +use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; +use fcntl::FcntlArg::{F_SETFD, F_SETFL}; + use errno::{SysResult, SysError, from_ffi}; use core::raw::Slice as RawSlice; @@ -59,20 +61,22 @@ pub enum Fork { impl Fork { pub fn is_child(&self) -> bool { match *self { - Child => true, + Fork::Child => true, _ => false } } pub fn is_parent(&self) -> bool { match *self { - Parent(_) => true, + Fork::Parent(_) => true, _ => false } } } pub fn fork() -> SysResult { + use self::Fork::*; + let res = unsafe { ffi::fork() }; if res < 0 {