Merge branch 'stdio-cvec-cleanup' into 'master'
stdio and c_vec cleanup See merge request redox-os/relibc!1027
This commit is contained in:
+1
-1
@@ -117,7 +117,7 @@ impl<'a, T: Kind> NulStr<'a, T> {
|
||||
/// The ptr must be valid up to and including the first NUL byte from the base ptr.
|
||||
pub const unsafe fn from_ptr(ptr: *const T::C) -> Self {
|
||||
Self {
|
||||
ptr: unsafe { NonNull::new_unchecked(ptr as *mut T::C) },
|
||||
ptr: unsafe { NonNull::new_unchecked(ptr.cast_mut()) },
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -37,7 +37,7 @@ impl<T> CVec<T> {
|
||||
}
|
||||
}
|
||||
fn check_bounds(i: usize) -> Result<usize, AllocError> {
|
||||
if i > core::isize::MAX as usize {
|
||||
if i > isize::MAX as usize {
|
||||
Err(AllocError)
|
||||
} else {
|
||||
Ok(i)
|
||||
@@ -53,7 +53,7 @@ impl<T> CVec<T> {
|
||||
return Ok(Self::new());
|
||||
}
|
||||
let size = Self::check_mul(cap, mem::size_of::<T>())?;
|
||||
let ptr = NonNull::new(unsafe { platform::alloc(size) as *mut T }).ok_or(AllocError)?;
|
||||
let ptr = NonNull::new(unsafe { platform::alloc(size).cast::<T>() }).ok_or(AllocError)?;
|
||||
Ok(Self { ptr, len: 0, cap })
|
||||
}
|
||||
unsafe fn resize(&mut self, cap: usize) -> Result<(), AllocError> {
|
||||
@@ -62,11 +62,11 @@ impl<T> CVec<T> {
|
||||
NonNull::dangling()
|
||||
} else if self.cap > 0 {
|
||||
NonNull::new(
|
||||
unsafe { platform::realloc(self.ptr.as_ptr() as *mut c_void, size) } as *mut T,
|
||||
unsafe { platform::realloc(self.ptr.as_ptr().cast::<c_void>(), size) }.cast::<T>(),
|
||||
)
|
||||
.ok_or(AllocError)?
|
||||
} else {
|
||||
NonNull::new((unsafe { platform::alloc(size) }) as *mut T).ok_or(AllocError)?
|
||||
NonNull::new((unsafe { platform::alloc(size) }).cast::<T>()).ok_or(AllocError)?
|
||||
};
|
||||
self.ptr = ptr;
|
||||
self.cap = cap;
|
||||
@@ -90,7 +90,7 @@ impl<T> CVec<T> {
|
||||
.ok_or(AllocError)
|
||||
.and_then(Self::check_bounds)?;
|
||||
if required_len > self.cap {
|
||||
let new_cap = cmp::min(required_len.next_power_of_two(), core::isize::MAX as usize);
|
||||
let new_cap = cmp::min(required_len.next_power_of_two(), isize::MAX as usize);
|
||||
unsafe {
|
||||
self.resize(new_cap)?;
|
||||
}
|
||||
|
||||
@@ -1124,7 +1124,7 @@ pub unsafe extern "C" fn puts(s: *const c_char) -> c_int {
|
||||
if stream.write_all(&buf).is_err() {
|
||||
return -1;
|
||||
}
|
||||
if stream.write(&[b'\n']).is_err() {
|
||||
if stream.write(b"\n").is_err() {
|
||||
return -1;
|
||||
}
|
||||
0
|
||||
|
||||
@@ -412,7 +412,7 @@ fn fmt_float_exp<W: Write>(
|
||||
|
||||
pad(w, !left, b' ', len..pad_space)?;
|
||||
let bytes = if string.starts_with('-') {
|
||||
w.write_all(&[b'-'])?;
|
||||
w.write_all(b"-")?;
|
||||
&string.as_bytes()[1..]
|
||||
} else {
|
||||
string.as_bytes()
|
||||
@@ -438,7 +438,7 @@ fn fmt_float_normal<W: Write>(
|
||||
|
||||
pad(w, !left, b' ', string.len()..pad_space)?;
|
||||
let bytes = if string.starts_with('-') {
|
||||
w.write_all(&[b'-'])?;
|
||||
w.write_all(b"-")?;
|
||||
&string.as_bytes()[1..]
|
||||
} else {
|
||||
string.as_bytes()
|
||||
@@ -477,7 +477,7 @@ fn fmt_float_nonfinite<W: Write>(
|
||||
// Infinity is always padded with spaces, rather than zeroes
|
||||
pad(w, !left, b' ', string.len()..pad_space + pad_zero)?;
|
||||
if float.is_sign_negative() {
|
||||
w.write_all(&[b'-'])?;
|
||||
w.write_all(b"-")?;
|
||||
}
|
||||
w.write_all(string.as_bytes())?;
|
||||
pad(w, left, b' ', string.len()..pad_space + pad_zero)?;
|
||||
@@ -748,7 +748,7 @@ pub(crate) unsafe fn inner_printf<T: c_str::Kind>(
|
||||
});
|
||||
|
||||
match fmtkind {
|
||||
FmtKind::Percent => w.write_all(&[b'%'])?,
|
||||
FmtKind::Percent => w.write_all(b"%")?,
|
||||
FmtKind::Signed => {
|
||||
let string = match unsafe {
|
||||
varargs.get(index, &mut ap, Some((arg.fmtkind, arg.intkind)))
|
||||
@@ -782,13 +782,13 @@ pub(crate) unsafe fn inner_printf<T: c_str::Kind>(
|
||||
|
||||
let bytes = if positive {
|
||||
if sign_reserve {
|
||||
w.write_all(&[b' '])?;
|
||||
w.write_all(b" ")?;
|
||||
} else if sign_always {
|
||||
w.write_all(&[b'+'])?;
|
||||
w.write_all(b"+")?;
|
||||
}
|
||||
string.as_bytes()
|
||||
} else {
|
||||
w.write_all(&[b'-'])?;
|
||||
w.write_all(b"-")?;
|
||||
&string.as_bytes()[1..]
|
||||
};
|
||||
pad(w, true, b'0', len..precision.unwrap_or(pad_zero))?;
|
||||
|
||||
@@ -154,10 +154,10 @@ pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
static SHM_PATH: &'static [u8] = b"/dev/shm/";
|
||||
static SHM_PATH: &[u8] = b"/dev/shm/";
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
static SHM_PATH: &'static [u8] = b"/scheme/shm/";
|
||||
static SHM_PATH: &[u8] = b"/scheme/shm/";
|
||||
|
||||
unsafe fn shm_path(name: *const c_char) -> CString {
|
||||
let name_c = unsafe { CStr::from_ptr(name) };
|
||||
|
||||
Reference in New Issue
Block a user