Skip to content

Commit 6bcdcde

Browse files
committed
let read_byte_helper take in io::Result<usize> too
1 parent 3d3effc commit 6bcdcde

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/shims/unix/fd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl FileDescription for io::Stdin {
140140
// We want isolation mode to be deterministic, so we have to disallow all reads, even stdin.
141141
helpers::isolation_abort_error("`read` from stdin")?;
142142
}
143-
let result = Ok(Read::read(&mut { self }, bytes));
143+
let result = Read::read(&mut { self }, bytes);
144144
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
145145
Ok(())
146146
}
@@ -650,12 +650,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
650650
&mut self,
651651
buf: Pointer,
652652
bytes: Vec<u8>,
653-
result: InterpResult<'tcx, io::Result<usize>>,
653+
result: io::Result<usize>,
654654
dest: &MPlaceTy<'tcx>,
655655
) -> InterpResult<'tcx> {
656656
let this = self.eval_context_mut();
657657
// `File::read` never returns a value larger than `count`, so this cannot fail.
658-
match result?.map(|c| i64::try_from(c).unwrap()) {
658+
match result.map(|c| i64::try_from(c).unwrap()) {
659659
// try to pass this the write_ptr inside write
660660
// Pass the pointer inside the write function.
661661
Ok(read_bytes) => {

src/shims/unix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl FileDescription for FileHandle {
4040
ecx: &mut MiriInterpCx<'tcx>,
4141
) -> InterpResult<'tcx> {
4242
assert!(communicate_allowed, "isolation should have prevented even opening a file");
43-
let result = Ok((&mut &self.file).read(bytes));
43+
let result = (&mut &self.file).read(bytes);
4444
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
4545
Ok(())
4646
}
@@ -82,7 +82,7 @@ impl FileDescription for FileHandle {
8282
.expect("failed to restore file position, this shouldn't be possible");
8383
res
8484
};
85-
let result = Ok(f());
85+
let result = f();
8686
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
8787
Ok(())
8888
}

src/shims/unix/linux/eventfd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ impl FileDescription for Event {
6969
) -> InterpResult<'tcx> {
7070
// Check the size of slice, and return error only if the size of the slice < 8.
7171
let Some(bytes) = bytes.first_chunk_mut::<U64_ARRAY_SIZE>() else {
72-
let result = Ok(Err(Error::from(ErrorKind::InvalidInput)));
72+
let result = Err(Error::from(ErrorKind::InvalidInput));
7373
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
7474
return Ok(());
7575
};
7676
// Block when counter == 0.
7777
let counter = self.counter.get();
7878
if counter == 0 {
7979
if self.is_nonblock {
80-
let result = Ok(Err(Error::from(ErrorKind::WouldBlock)));
80+
let result = Err(Error::from(ErrorKind::WouldBlock));
8181
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
8282
return Ok(());
8383
} else {
@@ -97,7 +97,7 @@ impl FileDescription for Event {
9797
// types for current file description.
9898
ecx.check_and_update_readiness(self_ref)?;
9999

100-
let result = Ok(Ok(U64_ARRAY_SIZE));
100+
let result = Ok(U64_ARRAY_SIZE);
101101
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
102102
return Ok(());
103103
}

src/shims/unix/unnamed_socket.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl FileDescription for AnonSocket {
135135

136136
// Always succeed on read size 0.
137137
if request_byte_size == 0 {
138-
let result = Ok(Ok(0));
138+
let result = Ok(0);
139139
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
140140
return Ok(());
141141
}
@@ -150,7 +150,7 @@ impl FileDescription for AnonSocket {
150150
if self.peer_fd().upgrade().is_none() {
151151
// Socketpair with no peer and empty buffer.
152152
// 0 bytes successfully read indicates end-of-file.
153-
let result = Ok(Ok(0));
153+
let result = Ok(0);
154154
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
155155
return Ok(());
156156
} else {
@@ -160,7 +160,7 @@ impl FileDescription for AnonSocket {
160160
// EAGAIN or EWOULDBLOCK can be returned for socket,
161161
// POSIX.1-2001 allows either error to be returned for this case.
162162
// Since there is no ErrorKind for EAGAIN, WouldBlock is used.
163-
let result = Ok(Err(Error::from(ErrorKind::WouldBlock)));
163+
let result = Err(Error::from(ErrorKind::WouldBlock));
164164
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
165165
return Ok(());
166166
} else {
@@ -194,7 +194,7 @@ impl FileDescription for AnonSocket {
194194
ecx.check_and_update_readiness(&peer_fd)?;
195195
}
196196

197-
let result = Ok(Ok(actual_read_size));
197+
let result = Ok(actual_read_size);
198198
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
199199
return Ok(());
200200
}

0 commit comments

Comments
 (0)