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

Update code to compile with latest rustc. #6

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 17 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub mod intrinsics {

/// Swap bytes for `u8` slices on all targets.
pub mod u8 {
use std::num::Int;
use std::ptr;
use std::mem;
use std::error;
Expand All @@ -56,7 +55,7 @@ pub mod u8 {
#[inline]
pub unsafe fn align_of_ptr(src: *const u8) -> usize {
let off: usize = mem::transmute(src);
2.pow(off.trailing_zeros() as u32)
2usize.pow(off.trailing_zeros() as u32)
}

/// TODO
Expand All @@ -69,9 +68,9 @@ pub mod u8 {
#[inline]
pub fn reverse_slice(dst: &mut [u8], src: &[u8]) {
unsafe {
ptr::copy_nonoverlapping(dst.as_mut_ptr(),
src.as_ptr(),
src.len());
ptr::copy_nonoverlapping(src.as_ptr(),
dst.as_mut_ptr(),
src.len());
}
dst.reverse();
}
Expand Down Expand Up @@ -124,7 +123,7 @@ pub mod u8 {
}

/// Errors that can occur when decoding a hex encoded string
#[derive(Copy)]
#[derive(Copy,Clone)]
pub enum FromHexError {
/// The input contained a character not part of the hex format
InvalidHexCharacter(char, usize),
Expand Down Expand Up @@ -354,7 +353,6 @@ pub mod u56 {
/// Swap bytes for `u32` objects on all targets.
pub mod u32 {
use std::cmp;
use std::num::Int;
pub const BYTES: usize = 4;


Expand Down Expand Up @@ -428,7 +426,6 @@ pub mod u32 {
/// Swap bytes for `u64` objects on all targets.
pub mod u64 {
use std::cmp;
use std::num::Int;
pub const BYTES: usize = 7;

/// Swaps `len*8` bytes for `u64` objects inplace in `buf`.
Expand Down Expand Up @@ -505,7 +502,6 @@ pub mod u64 {
}

pub mod beusize {
use std::num::Int;
use std::ptr;
use std::mem;

Expand All @@ -517,7 +513,7 @@ pub mod beusize {
let ptr_out = dst.as_mut_ptr();
unsafe {
ptr::copy_nonoverlapping(
ptr_out.offset((8 - nbytes) as isize), src.as_ptr(), nbytes);
src.as_ptr(), ptr_out.offset((8 - nbytes) as isize), nbytes);
(*(ptr_out as *const u64)).to_be()
}
}
Expand All @@ -530,13 +526,12 @@ pub mod beusize {
// n.b. https://github.com/rust-lang/rust/issues/22776
let bytes: [u8; 8] = mem::transmute::<_, [u8; 8]>(src.to_be());
ptr::copy_nonoverlapping(
dst.as_mut_ptr(), (&bytes[8 - nbytes..]).as_ptr(), nbytes);
(&bytes[8 - nbytes..]).as_ptr(), dst.as_mut_ptr(), nbytes);
}
}
}

pub mod leusize {
use std::num::Int;
use std::ptr;
use std::mem;

Expand All @@ -548,7 +543,7 @@ pub mod leusize {
let ptr_out = dst.as_mut_ptr();
unsafe {
ptr::copy_nonoverlapping(
ptr_out, src.as_ptr(), nbytes);
src.as_ptr(), ptr_out, nbytes);
(*(ptr_out as *const u64)).to_le()
}
}
Expand All @@ -561,15 +556,14 @@ pub mod leusize {
// n.b. https://github.com/rust-lang/rust/issues/22776
let bytes: [u8; 8] = mem::transmute::<_, [u8; 8]>(src.to_le());
ptr::copy_nonoverlapping(
dst.as_mut_ptr(), (&bytes[..nbytes]).as_ptr(), nbytes);
(&bytes[..nbytes]).as_ptr(), dst.as_mut_ptr(), nbytes);
}
}
}


macro_rules! mod_odd_impls {
($I:ident, $T:ident, $S:ident, $Bytes:expr, $DFunc:ident, $EMeth:ident, $E:expr, $NotE:expr) => {
use std::num::Int;
use std::ptr;
use std::mem;

Expand All @@ -578,7 +572,7 @@ macro_rules! mod_odd_impls {
if cfg!(target_endian = $NotE) {
super::$T::swap_memory(dst, src, len);
} else {
ptr::copy_nonoverlapping(dst, src, len*$Bytes);
ptr::copy_nonoverlapping(src, dst, len*$Bytes);
}
}

Expand All @@ -588,8 +582,8 @@ macro_rules! mod_odd_impls {
assert_eq!(buf.len(), $Bytes);
unsafe {
let mut tmp: $S = mem::uninitialized();
ptr::copy_nonoverlapping(&mut tmp as *mut _ as *mut u8, buf.as_ptr(), $Bytes);
Int::$DFunc(tmp)
ptr::copy_nonoverlapping(buf.as_ptr(), &mut tmp as *mut _ as *mut u8, $Bytes);
$S::$DFunc(tmp)
}
}

Expand All @@ -608,7 +602,7 @@ macro_rules! mod_odd_impls {
assert_eq!(dst.len(), $Bytes);
unsafe {
let tmp: $S = src.$EMeth();
ptr::copy_nonoverlapping(dst.as_mut_ptr(), &tmp as *const _ as *const u8, $Bytes);
ptr::copy_nonoverlapping(&tmp as *const _ as *const u8, dst.as_mut_ptr(), $Bytes);
}
}

Expand All @@ -626,7 +620,6 @@ macro_rules! mod_odd_impls {

macro_rules! mod_std_impls {
($I:ident, $T:ident, $Bytes:expr, $DFunc:ident, $EMeth:ident, $E:expr, $NotE:expr) => {
use std::num::Int;
use std::ptr;
use std::mem;

Expand All @@ -635,7 +628,7 @@ macro_rules! mod_std_impls {
if cfg!(target_endian = $NotE) {
super::$T::swap_memory(dst, src, len);
} else {
ptr::copy_nonoverlapping(dst, src, len*$Bytes);
ptr::copy_nonoverlapping(src, dst, len*$Bytes);
}
}

Expand All @@ -645,8 +638,8 @@ macro_rules! mod_std_impls {
assert_eq!(buf.len(), $Bytes);
unsafe {
let mut tmp: $T = mem::uninitialized();
ptr::copy_nonoverlapping(&mut tmp as *mut _ as *mut u8, buf.as_ptr(), $Bytes);
Int::$DFunc(tmp)
ptr::copy_nonoverlapping(buf.as_ptr(), &mut tmp as *mut _ as *mut u8, $Bytes);
$T::$DFunc(tmp)
}
}

Expand All @@ -665,7 +658,7 @@ macro_rules! mod_std_impls {
assert_eq!(dst.len(), $Bytes);
unsafe {
let tmp: $T = src.$EMeth();
ptr::copy_nonoverlapping(dst.as_mut_ptr(), &tmp as *const _ as *const u8, $Bytes);
ptr::copy_nonoverlapping(&tmp as *const _ as *const u8, dst.as_mut_ptr(), $Bytes);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn test_u64_swap_memory_hi() {
fn test_u64_swap_memory_inplace_hi() {
let mut dst = [0u8; 8];
let src: &[u8] = b"hi world";
::std::slice::bytes::copy_memory(&mut dst, src);
::std::slice::bytes::copy_memory(src, &mut dst);
unsafe {
super::u64::swap_memory_inplace(
(&mut dst[..]).as_mut_ptr(),
Expand Down Expand Up @@ -185,7 +185,7 @@ fn test_u64_swap_memory_pangram() {
fn test_u64_swap_memory_inplace_pangram() {
let mut dst = [0u8; 32];
let src: &[u8] = b"Five boxing wizards jump quickly";
::std::slice::bytes::copy_memory(&mut dst, src);
::std::slice::bytes::copy_memory(src, &mut dst);
unsafe {
super::u64::swap_memory_inplace(
(&mut dst[..]).as_mut_ptr(),
Expand Down Expand Up @@ -215,7 +215,7 @@ fn test_u64_swap_memory_lorem_ipsum() {
fn test_u64_swap_memory_inplace_lorem_ipsum() {
let mut dst = [0u8; 160];
let src: &[u8] = &LOREM_IPSUM[..160];
::std::slice::bytes::copy_memory(&mut dst, src);
::std::slice::bytes::copy_memory(src, &mut dst);
unsafe {
super::u64::swap_memory_inplace(
(&mut dst[..]).as_mut_ptr(),
Expand Down