Apply cargo fmt to the whole repo

This commit is contained in:
oddcoder
2020-07-19 21:22:17 +02:00
parent 890a9ed033
commit 37a462de5d
7 changed files with 35 additions and 26 deletions
+10 -8
View File
@@ -1,10 +1,9 @@
use crate::{
io::{self, Write},
platform::{self, WriteByte, types::*},
platform::{self, types::*, WriteByte},
};
use core::{
cmp,
fmt,
cmp, fmt,
iter::IntoIterator,
mem,
ops::{Deref, DerefMut},
@@ -60,7 +59,8 @@ impl<T> CVec<T> {
let ptr = if cap == 0 {
NonNull::dangling()
} else if self.cap > 0 {
NonNull::new(platform::realloc(self.ptr.as_ptr() as *mut c_void, size) as *mut T).ok_or(AllocError)?
NonNull::new(platform::realloc(self.ptr.as_ptr() as *mut c_void, size) as *mut T)
.ok_or(AllocError)?
} else {
NonNull::new((platform::alloc(size)) as *mut T).ok_or(AllocError)?
};
@@ -208,10 +208,12 @@ impl<'a, T> IntoIterator for &'a mut CVec<T> {
impl Write for CVec<u8> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.extend_from_slice(buf).map_err(|err| io::Error::new(
io::ErrorKind::Other,
"AllocStringWriter::write failed to allocate",
))?;
self.extend_from_slice(buf).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
"AllocStringWriter::write failed to allocate",
)
})?;
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
+1 -1
View File
@@ -12,7 +12,7 @@ use alloc::{borrow::ToOwned, boxed::Box, str::SplitWhitespace, vec::Vec};
use crate::{
c_str::{CStr, CString},
header::{
arpa_inet::htons, arpa_inet::ntohl, arpa_inet::inet_aton,
arpa_inet::{htons, inet_aton, ntohl},
errno::*,
fcntl::O_RDONLY,
netinet_in::{in_addr, sockaddr_in, sockaddr_in6},
+1 -1
View File
@@ -85,7 +85,7 @@ impl Linker {
pub fn unload(&mut self, libspace: usize) {
if let Some(lib) = self.lib_spaces.remove(&libspace) {
for (_, mmap) in lib.mmaps {
unsafe{sys_mman::munmap(mmap.as_mut_ptr() as *mut c_void, mmap.len())};
unsafe { sys_mman::munmap(mmap.as_mut_ptr() as *mut c_void, mmap.len()) };
}
}
}
+5 -5
View File
@@ -1,8 +1,8 @@
use crate::ALLOCATOR;
use core::{
alloc::{GlobalAlloc, Layout},
sync::atomic::{AtomicUsize, Ordering},
};
use crate::ALLOCATOR;
use super::types::*;
@@ -12,10 +12,10 @@ extern "C" {
fn mspace_memalign(msp: usize, alignment: size_t, bytes: size_t) -> *mut c_void;
fn mspace_realloc(msp: usize, oldmem: *mut c_void, bytes: size_t) -> *mut c_void;
fn mspace_free(msp: usize, mem: *mut c_void);
//fn dlmalloc(bytes: size_t) -> *mut c_void;
//fn dlmemalign(alignment: size_t, bytes: size_t) -> *mut c_void;
//fn dlrealloc(oldmem: *mut c_void, bytes: size_t) -> *mut c_void;
//fn dlfree(mem: *mut c_void);
//fn dlmalloc(bytes: size_t) -> *mut c_void;
//fn dlmemalign(alignment: size_t, bytes: size_t) -> *mut c_void;
//fn dlrealloc(oldmem: *mut c_void, bytes: size_t) -> *mut c_void;
//fn dlfree(mem: *mut c_void);
}
pub struct Allocator {
+3 -1
View File
@@ -117,7 +117,9 @@ impl PalEpoll for Sys {
}
*event_ptr = epoll_event {
events: event.flags.bits() as _,
data: epoll_data { u64: event.data as u64, },
data: epoll_data {
u64: event.data as u64,
},
..Default::default()
};
count += 1;
+14 -9
View File
@@ -8,7 +8,7 @@ use super::{
};
use crate::header::{
arpa_inet::inet_aton,
netinet_in::{in_port_t, sockaddr_in, in_addr},
netinet_in::{in_addr, in_port_t, sockaddr_in},
string::strnlen,
sys_socket::{constants::*, sa_family_t, sockaddr, socklen_t},
sys_time::timeval,
@@ -112,10 +112,8 @@ unsafe fn inner_af_unix(buf: &[u8], address: *mut sockaddr, address_len: *mut so
data.sun_family = AF_UNIX as c_ushort;
let path = slice::from_raw_parts_mut(
&mut data.sun_path as *mut _ as *mut u8,
data.sun_path.len(),
);
let path =
slice::from_raw_parts_mut(&mut data.sun_path as *mut _ as *mut u8, data.sun_path.len());
let len = cmp::min(path.len(), buf.len());
path[..len].copy_from_slice(&buf[..len]);
@@ -139,7 +137,10 @@ unsafe fn inner_af_inet(
let sep = memchr::memchr(b':', &unparsed_addr).expect("missing port");
let (raw_addr, rest) = unparsed_addr.split_at_mut(sep);
let (colon, raw_port) = rest.split_at_mut(1);
let port = str::from_utf8(raw_port).expect("non-utf8 port").parse().expect("invalid port");
let port = str::from_utf8(raw_port)
.expect("non-utf8 port")
.parse()
.expect("invalid port");
// Make address be followed by a NUL-byte
colon[0] = b'\0';
@@ -147,7 +148,11 @@ unsafe fn inner_af_inet(
trace!("address: {:?}, port: {:?}", str::from_utf8(&raw_addr), port);
let mut addr = in_addr::default();
assert_eq!(inet_aton(raw_addr.as_ptr() as *mut i8, &mut addr), 1, "inet_aton might be broken, failed to parse netstack address");
assert_eq!(
inet_aton(raw_addr.as_ptr() as *mut i8, &mut addr),
1,
"inet_aton might be broken, failed to parse netstack address"
);
let ret = sockaddr_in {
sin_family: AF_INET as sa_family_t,
@@ -414,7 +419,7 @@ impl PalSocket for Sys {
_ => {
errno = syscall::EPROTONOSUPPORT;
-1
},
}
}
}
@@ -448,7 +453,7 @@ impl PalSocket for Sys {
sv[0] = fd0 as c_int;
sv[1] = fd1 as c_int;
0
},
}
_ => unsafe {
eprintln!(
"socketpair({}, {}, {}, {:p})",
+1 -1
View File
@@ -68,7 +68,7 @@ static INIT_ARRAY: [extern "C" fn(); 1] = [init_array];
static mut init_complete: bool = false;
fn alloc_init() {
unsafe{
unsafe {
if let Some(tcb) = ld_so::tcb::Tcb::current() {
if tcb.mspace != 0 {
ALLOCATOR.set_book_keeper(tcb.mspace);