Skip to content

Commit 447530b

Browse files
authored
Remove BufMut::bytes_vectored_mut() (#430)
There are issues with regard to uninitialized memory. We are avoiding stabilizing this function for now.
1 parent 422048e commit 447530b

File tree

4 files changed

+0
-121
lines changed

4 files changed

+0
-121
lines changed

src/buf/buf_mut.rs

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use core::{
44
ptr, usize,
55
};
66

7-
#[cfg(feature = "std")]
8-
use std::fmt;
9-
107
use alloc::{boxed::Box, vec::Vec};
118

129
/// A trait for values that provide sequential write access to bytes.
@@ -168,48 +165,6 @@ pub trait BufMut {
168165
/// return an empty slice.
169166
fn bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
170167

171-
/// Fills `dst` with potentially multiple mutable slices starting at `self`'s
172-
/// current position.
173-
///
174-
/// If the `BufMut` is backed by disjoint slices of bytes, `bytes_vectored_mut`
175-
/// enables fetching more than one slice at once. `dst` is a slice of
176-
/// mutable `IoSliceMut` references, enabling the slice to be directly used with
177-
/// [`readv`] without any further conversion. The sum of the lengths of all
178-
/// the buffers in `dst` will be less than or equal to
179-
/// `Buf::remaining_mut()`.
180-
///
181-
/// The entries in `dst` will be overwritten, but the data **contained** by
182-
/// the slices **will not** be modified. If `bytes_vectored_mut` does not fill every
183-
/// entry in `dst`, then `dst` is guaranteed to contain all remaining slices
184-
/// in `self.
185-
///
186-
/// This is a lower level function. Most operations are done with other
187-
/// functions.
188-
///
189-
/// # Implementer notes
190-
///
191-
/// This function should never panic. Once the end of the buffer is reached,
192-
/// i.e., `BufMut::remaining_mut` returns 0, calls to `bytes_vectored_mut` must
193-
/// return 0 without mutating `dst`.
194-
///
195-
/// Implementations should also take care to properly handle being called
196-
/// with `dst` being a zero length slice.
197-
///
198-
/// [`readv`]: http://man7.org/linux/man-pages/man2/readv.2.html
199-
#[cfg(feature = "std")]
200-
fn bytes_vectored_mut<'a>(&'a mut self, dst: &mut [IoSliceMut<'a>]) -> usize {
201-
if dst.is_empty() {
202-
return 0;
203-
}
204-
205-
if self.has_remaining_mut() {
206-
dst[0] = IoSliceMut::from(self.bytes_mut());
207-
1
208-
} else {
209-
0
210-
}
211-
}
212-
213168
/// Transfer bytes into `self` from `src` and advance the cursor by the
214169
/// number of bytes written.
215170
///
@@ -890,11 +845,6 @@ macro_rules! deref_forward_bufmut {
890845
(**self).bytes_mut()
891846
}
892847

893-
#[cfg(feature = "std")]
894-
fn bytes_vectored_mut<'b>(&'b mut self, dst: &mut [IoSliceMut<'b>]) -> usize {
895-
(**self).bytes_vectored_mut(dst)
896-
}
897-
898848
unsafe fn advance_mut(&mut self, cnt: usize) {
899849
(**self).advance_mut(cnt)
900850
}
@@ -1057,44 +1007,3 @@ impl BufMut for Vec<u8> {
10571007
// The existence of this function makes the compiler catch if the BufMut
10581008
// trait is "object-safe" or not.
10591009
fn _assert_trait_object(_b: &dyn BufMut) {}
1060-
1061-
// ===== impl IoSliceMut =====
1062-
1063-
/// A buffer type used for `readv`.
1064-
///
1065-
/// This is a wrapper around an `std::io::IoSliceMut`, but does not expose
1066-
/// the inner bytes in a safe API, as they may point at uninitialized memory.
1067-
///
1068-
/// This is `repr(transparent)` of the `std::io::IoSliceMut`, so it is valid to
1069-
/// transmute them. However, as the memory might be uninitialized, care must be
1070-
/// taken to not *read* the internal bytes, only *write* to them.
1071-
#[repr(transparent)]
1072-
#[cfg(feature = "std")]
1073-
pub struct IoSliceMut<'a>(std::io::IoSliceMut<'a>);
1074-
1075-
#[cfg(feature = "std")]
1076-
impl fmt::Debug for IoSliceMut<'_> {
1077-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1078-
f.debug_struct("IoSliceMut")
1079-
.field("len", &self.0.len())
1080-
.finish()
1081-
}
1082-
}
1083-
1084-
#[cfg(feature = "std")]
1085-
impl<'a> From<&'a mut [u8]> for IoSliceMut<'a> {
1086-
fn from(buf: &'a mut [u8]) -> IoSliceMut<'a> {
1087-
IoSliceMut(std::io::IoSliceMut::new(buf))
1088-
}
1089-
}
1090-
1091-
#[cfg(feature = "std")]
1092-
impl<'a> From<&'a mut [MaybeUninit<u8>]> for IoSliceMut<'a> {
1093-
fn from(buf: &'a mut [MaybeUninit<u8>]) -> IoSliceMut<'a> {
1094-
IoSliceMut(std::io::IoSliceMut::new(unsafe {
1095-
// We don't look at the contents, and `std::io::IoSliceMut`
1096-
// doesn't either.
1097-
mem::transmute::<&'a mut [MaybeUninit<u8>], &'a mut [u8]>(buf)
1098-
}))
1099-
}
1100-
}

src/buf/ext/chain.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use crate::{Buf, BufMut};
33

44
use core::mem::MaybeUninit;
55

6-
#[cfg(feature = "std")]
7-
use crate::buf::IoSliceMut;
86
#[cfg(feature = "std")]
97
use std::io::IoSlice;
108

@@ -210,13 +208,6 @@ where
210208

211209
self.b.advance_mut(cnt);
212210
}
213-
214-
#[cfg(feature = "std")]
215-
fn bytes_vectored_mut<'a>(&'a mut self, dst: &mut [IoSliceMut<'a>]) -> usize {
216-
let mut n = self.a.bytes_vectored_mut(dst);
217-
n += self.b.bytes_vectored_mut(&mut dst[n..]);
218-
n
219-
}
220211
}
221212

222213
impl<T, U> IntoIterator for Chain<T, U>

src/buf/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ mod vec_deque;
2424

2525
pub use self::buf_impl::Buf;
2626
pub use self::buf_mut::BufMut;
27-
#[cfg(feature = "std")]
28-
pub use self::buf_mut::IoSliceMut;
2927
pub use self::ext::{BufExt, BufMutExt};
3028
pub use self::iter::IntoIter;

tests/test_buf_mut.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![warn(rust_2018_idioms)]
22

3-
#[cfg(feature = "std")]
4-
use bytes::buf::IoSliceMut;
53
use bytes::{BufMut, BytesMut};
64
use core::fmt::Write;
75
use core::usize;
@@ -66,23 +64,6 @@ fn test_clone() {
6664
assert!(buf != buf2);
6765
}
6866

69-
#[cfg(feature = "std")]
70-
#[test]
71-
fn test_bufs_vec_mut() {
72-
let b1: &mut [u8] = &mut [];
73-
let b2: &mut [u8] = &mut [];
74-
let mut dst = [IoSliceMut::from(b1), IoSliceMut::from(b2)];
75-
76-
// with no capacity
77-
let mut buf = BytesMut::new();
78-
assert_eq!(buf.capacity(), 0);
79-
assert_eq!(1, buf.bytes_vectored_mut(&mut dst[..]));
80-
81-
// with capacity
82-
let mut buf = BytesMut::with_capacity(64);
83-
assert_eq!(1, buf.bytes_vectored_mut(&mut dst[..]));
84-
}
85-
8667
#[test]
8768
fn test_mut_slice() {
8869
let mut v = vec![0, 0, 0, 0];

0 commit comments

Comments
 (0)