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

More cleanups and enable some more compiler lints #837

Merged
merged 14 commits into from
Jan 31, 2018
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Display and Debug for SysControlAddr now includes all fields.
([#837](https://github.com/nix-rust/nix/pull/837))

### Fixed
- Properly exposed 460800 and 921600 baud rates on NetBSD
([#837](https://github.com/nix-rust/nix/pull/837))

### Removed

Expand Down
7 changes: 5 additions & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ libc_bitflags!(
}
);

#[allow(missing_debug_implementations)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you allow missing debug impls for certain types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No libc types implement Debug, so derive(Debug) doesn't work for them. I've decided to defer these implementations for now in order to get these checks working for PRs in general. I'd like to come back and add impl Debug for all types as a future PR.

pub enum FcntlArg<'a> {
F_DUPFD(RawFd),
F_DUPFD_CLOEXEC(RawFd),
Expand All @@ -230,7 +231,7 @@ pub enum FcntlArg<'a> {
#[cfg(any(target_os = "linux", target_os = "android"))]
F_GETPIPE_SZ,
#[cfg(any(target_os = "linux", target_os = "android"))]
F_SETPIPE_SZ(libc::c_int),
F_SETPIPE_SZ(c_int),

// TODO: Rest of flags
}
Expand Down Expand Up @@ -267,6 +268,8 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
Errno::result(res)
}

#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
pub enum FlockArg {
LockShared,
LockExclusive,
Expand Down Expand Up @@ -343,7 +346,7 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
#[cfg(any(target_os = "linux"))]
libc_bitflags!(
/// Mode argument flags for fallocate determining operation performed on a given range.
pub struct FallocateFlags: libc::c_int {
pub struct FallocateFlags: c_int {
/// File size is not changed.
///
/// offset + len can be greater than file size.
Expand Down
3 changes: 3 additions & 0 deletions src/features.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Feature tests for OS functionality
pub use self::os::*;

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -82,6 +83,7 @@ mod os {
}
}

/// Check if the OS supports atomic close-on-exec for sockets
pub fn socket_atomic_cloexec() -> bool {
kernel_version() >= VERS_2_6_27
}
Expand All @@ -94,6 +96,7 @@ mod os {

#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
mod os {
/// Check if the OS supports atomic close-on-exec for sockets
pub fn socket_atomic_cloexec() -> bool {
false
}
Expand Down
53 changes: 22 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,52 @@
#![allow(dead_code)]
#![cfg_attr(test, deny(warnings))]
#![recursion_limit = "500"]
#![deny(unused)]
#![deny(unstable_features)]
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]

// External crates
extern crate bytes;
#[macro_use]
extern crate bitflags;

#[macro_use]
extern crate cfg_if;
extern crate void;

#[macro_use] mod macros;

// Re-exported external crates
pub extern crate libc;

use errno::Errno;
// Private internal modules
#[macro_use] mod macros;

// Public crates
pub mod errno;
#[deny(missing_docs)]
pub mod features;
pub mod fcntl;

#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod mount;

#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "fushsia",
target_os = "linux",
target_os = "netbsd"))]
pub mod mqueue;

pub mod pty;

pub mod poll;

#[deny(missing_docs)]
pub mod net;

#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
pub mod ifaddrs;

#[deny(missing_docs)]
pub mod poll;
#[deny(missing_docs)]
pub mod pty;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod sched;

pub mod sys;

// This can be implemented for other platforms as soon as libc
// provides bindings for them.
#[cfg(all(target_os = "linux",
any(target_arch = "x86", target_arch = "x86_64")))]
pub mod ucontext;

pub mod unistd;

/*
Expand All @@ -73,14 +64,14 @@ pub mod unistd;
*
*/

use libc::c_char;
use std::{ptr, result};
use libc::{c_char, PATH_MAX};

use std::{error, fmt, ptr, result};
use std::ffi::{CStr, OsStr};
use std::path::{Path, PathBuf};
use std::os::unix::ffi::OsStrExt;
use std::fmt;
use std::error;
use libc::PATH_MAX;
use std::path::{Path, PathBuf};

use errno::Errno;

/// Nix Result Type
pub type Result<T> = result::Result<T, Error>;
Expand All @@ -94,7 +85,7 @@ pub type Result<T> = result::Result<T, Error>;
/// implementing other common traits.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Error {
Sys(errno::Errno),
Sys(Errno),
InvalidPath,
/// The operation involved a conversion to Rust's native String type, which failed because the
/// string did not contain all valid UTF-8.
Expand Down
1 change: 1 addition & 0 deletions src/mqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ libc_bitflags!{

#[repr(C)]
#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
pub struct MqAttr {
mq_attr: libc::mq_attr,
}
Expand Down
1 change: 1 addition & 0 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Functionality involving network interfaces
// To avoid clashing with the keyword "if", we use "if_" as the module name.
// The original header is called "net/if.h".
pub mod if_;
2 changes: 2 additions & 0 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Wait for events to trigger on specific file descriptors
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
use sys::time::TimeSpec;
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
Expand All @@ -18,6 +19,7 @@ use errno::Errno;
/// retrieved by calling [`revents()`](#method.revents) on the `PollFd`.
#[repr(C)]
#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
pub struct PollFd {
pollfd: libc::pollfd,
}
Expand Down
4 changes: 4 additions & 0 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ use errno::Errno;
///
/// This is returned by `openpty`. Note that this type does *not* implement `Drop`, so the user
/// must manually close the file descriptors.
#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
pub struct OpenptyResult {
/// The master port in a virtual pty pair
pub master: RawFd,
/// The slave port in a virtual pty pair
pub slave: RawFd,
}

Expand Down
3 changes: 2 additions & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ::unistd::Pid;
// For some functions taking with a parameter of type CloneFlags,
// only a subset of these flags have an effect.
libc_bitflags!{
pub struct CloneFlags: libc::c_int {
pub struct CloneFlags: c_int {
CLONE_VM;
CLONE_FS;
CLONE_FILES;
Expand Down Expand Up @@ -40,6 +40,7 @@ pub type CloneCb<'a> = Box<FnMut() -> isize + 'a>;

#[repr(C)]
#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
pub struct CpuSet {
cpu_set: libc::cpu_set_t,
}
Expand Down
8 changes: 4 additions & 4 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<'a> AioCb<'a> {
aiocb: a,
mutable: true,
in_progress: false,
buffer: Buffer::Phantom(PhantomData)
buffer: Buffer::Phantom(PhantomData),
}
}

Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'a> AioCb<'a> {
aiocb: a,
mutable: false,
in_progress: false,
buffer: Buffer::Bytes(buf2)
buffer: Buffer::Bytes(buf2),
}
}

Expand Down Expand Up @@ -464,7 +464,7 @@ impl<'a> AioCb<'a> {
aiocb: a,
mutable: true,
in_progress: false,
buffer: Buffer::BytesMut(buf2)
buffer: Buffer::BytesMut(buf2),
}
}

Expand Down Expand Up @@ -619,7 +619,7 @@ impl<'a> AioCb<'a> {
aiocb: a,
mutable: false,
in_progress: false,
buffer: Buffer::None
buffer: Buffer::None,
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::mem;
use ::Error;

libc_bitflags!(
pub struct EpollFlags: libc::c_int {
pub struct EpollFlags: c_int {
EPOLLIN;
EPOLLPRI;
EPOLLOUT;
Expand Down Expand Up @@ -42,6 +42,7 @@ libc_bitflags!{
}
}

#[allow(missing_debug_implementations)]
#[derive(Clone, Copy)]
#[repr(C)]
pub struct EpollEvent {
Expand All @@ -58,7 +59,7 @@ impl EpollEvent {
}

pub fn events(&self) -> EpollFlags {
EpollFlags::from_bits(self.event.events as libc::c_int).unwrap()
EpollFlags::from_bits(self.event.events as c_int).unwrap()
}

pub fn data(&self) -> u64 {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::mem;
// Redefine kevent in terms of programmer-friendly enums and bitfields.
#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_debug_implementations)]
pub struct KEvent {
kevent: libc::kevent,
}
Expand All @@ -24,7 +25,7 @@ pub struct KEvent {
type type_of_udata = *mut libc::c_void;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
target_os = "ios", target_os = "macos"))]
type type_of_data = libc::intptr_t;
type type_of_data = intptr_t;
#[cfg(any(target_os = "netbsd"))]
type type_of_udata = intptr_t;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
Expand Down
8 changes: 6 additions & 2 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use {Error, Result, NixPath};
use {Error, Result};
#[cfg(not(target_os = "android"))]
use NixPath;
use errno::Errno;
#[cfg(not(target_os = "android"))]
use fcntl::OFlag;
use libc::{self, c_int, c_void, size_t, off_t};
#[cfg(not(target_os = "android"))]
use sys::stat::Mode;
use std::os::unix::io::RawFd;

libc_bitflags!{
/// Desired memory protection of a memory mapping.
pub struct ProtFlags: libc::c_int {
pub struct ProtFlags: c_int {
/// Pages cannot be accessed.
PROT_NONE;
/// Pages can be read.
Expand Down
Loading