Remove slice_to_end · model-checking/verify-rust-std@8e76b15 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -138,16 +138,21 @@ impl Handle {
138 138
139 139 pub unsafe fn read_overlapped(
140 140 &self,
141 -buf: &mut [u8],
141 +buf: &mut [mem::MaybeUninit<u8>],
142 142 overlapped: *mut c::OVERLAPPED,
143 143 ) -> io::Result<Option<usize>> {
144 144 // SAFETY: We have exclusive access to the buffer and it's up to the caller to
145 145 // ensure the OVERLAPPED pointer is valid for the lifetime of this function.
146 146 unsafe {
147 147 let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
148 148 let mut amt = 0;
149 -let res =
150 -cvt(c::ReadFile(self.as_raw_handle(), buf.as_mut_ptr(), len, &mut amt, overlapped));
149 +let res = cvt(c::ReadFile(
150 +self.as_raw_handle(),
151 + buf.as_mut_ptr().cast::<u8>(),
152 + len,
153 +&mut amt,
154 + overlapped,
155 +));
151 156 match res {
152 157 Ok(_) => Ok(Some(amt as usize)),
153 158 Err(e) => {
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read};
5 5 use crate::mem;
6 6 use crate::path::Path;
7 7 use crate::ptr;
8 -use crate::slice;
9 8 use crate::sync::atomic::AtomicUsize;
10 9 use crate::sync::atomic::Ordering::Relaxed;
11 10 use crate::sys::c;
@@ -479,8 +478,11 @@ impl<'a> AsyncPipe<'a> {
479 478 fn schedule_read(&mut self) -> io::Result<bool> {
480 479 assert_eq!(self.state, State::NotReading);
481 480 let amt = unsafe {
482 -let slice = slice_to_end(self.dst);
483 -self.pipe.read_overlapped(slice, &mut *self.overlapped)?
481 +if self.dst.capacity() == self.dst.len() {
482 +let additional = if self.dst.capacity() == 0 { 16 } else { 1 };
483 +self.dst.reserve(additional);
484 +}
485 +self.pipe.read_overlapped(self.dst.spare_capacity_mut(), &mut *self.overlapped)?
484 486 };
485 487
486 488 // If this read finished immediately then our overlapped event will
@@ -560,15 +562,3 @@ impl<'a> Drop for AsyncPipe<'a> {
560 562 }
561 563 }
562 564 }
563 -
564 -#[allow(unsafe_op_in_unsafe_fn)]
565 -unsafe fn slice_to_end(v: &mut Vec<u8>) -> &mut [u8] {
566 -if v.capacity() == 0 {
567 - v.reserve(16);
568 -}
569 -if v.capacity() == v.len() {
570 - v.reserve(1);
571 -}
572 -// FIXME: Isn't this just spare_capacity_mut but worse?
573 - slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len())
574 -}