From 97b1a72e1e32331ec05a092059acf17db1313bd8 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 6 May 2022 22:56:59 -0600 Subject: [PATCH] Portability fixes --- src/sys/aio.rs | 19 ++++++++++++++----- test/sys/test_aio.rs | 6 +++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 6d2a26d367..3e7663d4e3 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -30,7 +30,6 @@ use pin_utils::unsafe_pinned; use std::{ convert::TryFrom, fmt::{self, Debug}, - io::{IoSlice, IoSliceMut}, marker::{PhantomData, PhantomPinned}, mem, os::unix::io::RawFd, @@ -38,6 +37,8 @@ use std::{ ptr, thread }; +#[cfg(target_os = "freebsd")] +use std::io::{IoSlice, IoSliceMut}; use crate::sys::signal::*; use crate::sys::time::TimeSpec; @@ -1185,16 +1186,24 @@ mod t { assert_eq!(aior.as_ref() as *const libc::aiocb, &aior as *const AioRead as *const libc::aiocb); + let wbuf = []; + let aiow = AioWrite::new(666, 0, &wbuf, 0, sev); + assert_eq!(aiow.as_ref() as *const libc::aiocb, + &aiow as *const AioWrite as *const libc::aiocb); + } + + #[cfg(target_os = "freebsd")] + #[test] + fn casting_vectored() { + let sev = SigevNotify::SigevNone; + + let mut rbuf = []; let mut rbufs = [IoSliceMut::new(&mut rbuf)]; let aiorv = AioReadv::new(666, 0, &mut rbufs[..], 0, sev); assert_eq!(aiorv.as_ref() as *const libc::aiocb, &aiorv as *const AioReadv as *const libc::aiocb); let wbuf = []; - let aiow = AioWrite::new(666, 0, &wbuf, 0, sev); - assert_eq!(aiow.as_ref() as *const libc::aiocb, - &aiow as *const AioWrite as *const libc::aiocb); - let wbufs = [IoSlice::new(&wbuf)]; let aiowv = AioWritev::new(666, 0, &wbufs, 0, sev); assert_eq!(aiowv.as_ref() as *const libc::aiocb, diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 834543b084..1cfc6e604d 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -3,7 +3,7 @@ use nix::errno::*; use nix::sys::aio::*; use nix::sys::signal::{SaFlags, SigAction, sigaction, SigevNotify, SigHandler, Signal, SigSet}; use nix::sys::time::{TimeValLike, TimeSpec}; -use std::io::{IoSlice, IoSliceMut, Write, Read, Seek, SeekFrom}; +use std::io::{Write, Read, Seek, SeekFrom}; use std::ops::Deref; use std::os::unix::io::AsRawFd; use std::pin::Pin; @@ -200,8 +200,10 @@ mod aio_read { } } +#[cfg(target_os = "freebsd")] mod aio_readv { use super::*; + use std::io::IoSliceMut; #[test] fn test_accessors() { @@ -378,8 +380,10 @@ mod aio_write { } } +#[cfg(target_os = "freebsd")] mod aio_writev { use super::*; + use std::io::IoSlice; #[test] fn test_accessors() {