Skip to content

Commit de1e46a

Browse files
committed
Revert "Inline a bunch of variable"
This reverts commit dc74101.
1 parent 7721683 commit de1e46a

File tree

4 files changed

+42
-37
lines changed

4 files changed

+42
-37
lines changed

src/shims/unix/fd.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ 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-
ecx.read_byte_helper(ptr, bytes.to_vec(), Read::read(&mut { self }, bytes), dest)?;
143+
let result = Read::read(&mut { self }, bytes);
144+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
144145
Ok(())
145146
}
146147

@@ -194,7 +195,8 @@ impl FileDescription for io::Stderr {
194195
) -> InterpResult<'tcx> {
195196
// We allow writing to stderr even with isolation enabled.
196197
// No need to flush, stderr is not buffered.
197-
ecx.write_byte_helper(Write::write(&mut { self }, bytes), dest)?;
198+
let result = Write::write(&mut { self }, bytes);
199+
ecx.write_byte_helper(result, dest)?;
198200
Ok(())
199201
}
200202

@@ -221,7 +223,8 @@ impl FileDescription for NullOutput {
221223
ecx: &mut MiriInterpCx<'tcx>,
222224
) -> InterpResult<'tcx> {
223225
// We just don't write anything, but report to the user that we did.
224-
ecx.write_byte_helper(Ok(bytes.len()), dest)?;
226+
let result = Ok(bytes.len());
227+
ecx.write_byte_helper(result, dest)?;
225228
Ok(())
226229
}
227230
}

src/shims/unix/fs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl FileDescription for FileHandle {
5454
ecx: &mut MiriInterpCx<'tcx>,
5555
) -> InterpResult<'tcx> {
5656
assert!(communicate_allowed, "isolation should have prevented even opening a file");
57-
ecx.write_byte_helper((&mut &self.file).write(bytes), dest)?;
57+
let result = (&mut &self.file).write(bytes);
58+
ecx.write_byte_helper(result, dest)?;
5859
Ok(())
5960
}
6061

@@ -81,8 +82,8 @@ impl FileDescription for FileHandle {
8182
.expect("failed to restore file position, this shouldn't be possible");
8283
res
8384
};
84-
let res = f();
85-
ecx.read_byte_helper(ptr, bytes.to_vec(), res, dest)?;
85+
let result = f();
86+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
8687
Ok(())
8788
}
8889

@@ -108,7 +109,8 @@ impl FileDescription for FileHandle {
108109
.expect("failed to restore file position, this shouldn't be possible");
109110
res
110111
};
111-
ecx.write_byte_helper(f(), dest)?;
112+
let result = f();
113+
ecx.write_byte_helper(result, dest)?;
112114
Ok(())
113115
}
114116

src/shims/unix/linux/eventfd.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,16 @@ 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-
ecx.read_byte_helper(
73-
ptr,
74-
bytes.to_vec(),
75-
Err(Error::from(ErrorKind::InvalidInput)),
76-
dest,
77-
)?;
72+
let result = Err(Error::from(ErrorKind::InvalidInput));
73+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
7874
return Ok(());
7975
};
8076
// Block when counter == 0.
8177
let counter = self.counter.get();
8278
if counter == 0 {
8379
if self.is_nonblock {
84-
ecx.read_byte_helper(
85-
ptr,
86-
bytes.to_vec(),
87-
Err(Error::from(ErrorKind::WouldBlock)),
88-
dest,
89-
)?;
80+
let result = Err(Error::from(ErrorKind::WouldBlock));
81+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
9082
return Ok(());
9183
} else {
9284
//FIXME: blocking is not supported
@@ -105,7 +97,8 @@ impl FileDescription for Event {
10597
// types for current file description.
10698
ecx.check_and_update_readiness(self_ref)?;
10799

108-
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(U64_ARRAY_SIZE), dest)?;
100+
let result = Ok(U64_ARRAY_SIZE);
101+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
109102
return Ok(());
110103
}
111104
}
@@ -132,7 +125,8 @@ impl FileDescription for Event {
132125
) -> InterpResult<'tcx> {
133126
// Check the size of slice, and return error only if the size of the slice < 8.
134127
let Some(bytes) = bytes.first_chunk::<U64_ARRAY_SIZE>() else {
135-
ecx.write_byte_helper(Err(Error::from(ErrorKind::InvalidInput)), dest)?;
128+
let result = Err(Error::from(ErrorKind::InvalidInput));
129+
ecx.write_byte_helper(result, dest)?;
136130
return Ok(());
137131
};
138132
// Convert from bytes to int according to host endianness.
@@ -142,7 +136,8 @@ impl FileDescription for Event {
142136
};
143137
// u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1.
144138
if num == u64::MAX {
145-
ecx.write_byte_helper(Err(Error::from(ErrorKind::InvalidInput)), dest)?;
139+
let result = Err(Error::from(ErrorKind::InvalidInput));
140+
ecx.write_byte_helper(result, dest)?;
146141
return Ok(());
147142
}
148143
// If the addition does not let the counter to exceed the maximum value, update the counter.
@@ -157,7 +152,8 @@ impl FileDescription for Event {
157152
}
158153
None | Some(u64::MAX) => {
159154
if self.is_nonblock {
160-
ecx.write_byte_helper(Err(Error::from(ErrorKind::WouldBlock)), dest)?;
155+
let result = Err(Error::from(ErrorKind::WouldBlock));
156+
ecx.write_byte_helper(result, dest)?;
161157
return Ok(());
162158
} else {
163159
//FIXME: blocking is not supported
@@ -169,7 +165,8 @@ impl FileDescription for Event {
169165
// types for current file description.
170166
ecx.check_and_update_readiness(self_ref)?;
171167

172-
ecx.write_byte_helper(Ok(U64_ARRAY_SIZE), dest)?;
168+
let result = Ok(U64_ARRAY_SIZE);
169+
ecx.write_byte_helper(result, dest)?;
173170
Ok(())
174171
}
175172
}

src/shims/unix/unnamed_socket.rs

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

136136
// Always succeed on read size 0.
137137
if request_byte_size == 0 {
138-
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(0), dest)?;
138+
let result = Ok(0);
139+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
139140
return Ok(());
140141
}
141142

@@ -149,7 +150,8 @@ impl FileDescription for AnonSocket {
149150
if self.peer_fd().upgrade().is_none() {
150151
// Socketpair with no peer and empty buffer.
151152
// 0 bytes successfully read indicates end-of-file.
152-
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(0), dest)?;
153+
let result = Ok(0);
154+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
153155
return Ok(());
154156
} else {
155157
if self.is_nonblock {
@@ -158,12 +160,8 @@ impl FileDescription for AnonSocket {
158160
// EAGAIN or EWOULDBLOCK can be returned for socket,
159161
// POSIX.1-2001 allows either error to be returned for this case.
160162
// Since there is no ErrorKind for EAGAIN, WouldBlock is used.
161-
ecx.read_byte_helper(
162-
ptr,
163-
bytes.to_vec(),
164-
Err(Error::from(ErrorKind::WouldBlock)),
165-
dest,
166-
)?;
163+
let result = Err(Error::from(ErrorKind::WouldBlock));
164+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
167165
return Ok(());
168166
} else {
169167
// Blocking socketpair with writer and empty buffer.
@@ -196,7 +194,8 @@ impl FileDescription for AnonSocket {
196194
ecx.check_and_update_readiness(&peer_fd)?;
197195
}
198196

199-
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(actual_read_size), dest)?;
197+
let result = Ok(actual_read_size);
198+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
200199
return Ok(());
201200
}
202201

@@ -212,15 +211,17 @@ impl FileDescription for AnonSocket {
212211
// Always succeed on write size 0.
213212
// ("If count is zero and fd refers to a file other than a regular file, the results are not specified.")
214213
if write_size == 0 {
215-
ecx.write_byte_helper(Ok(0), dest)?;
214+
let result = Ok(0);
215+
ecx.write_byte_helper(result, dest)?;
216216
return Ok(());
217217
}
218218

219219
// We are writing to our peer's readbuf.
220220
let Some(peer_fd) = self.peer_fd().upgrade() else {
221221
// If the upgrade from Weak to Rc fails, it indicates that all read ends have been
222222
// closed.
223-
ecx.write_byte_helper(Err(Error::from(ErrorKind::BrokenPipe)), dest)?;
223+
let result = Err(Error::from(ErrorKind::BrokenPipe));
224+
ecx.write_byte_helper(result, dest)?;
224225
return Ok(());
225226
};
226227

@@ -235,7 +236,8 @@ impl FileDescription for AnonSocket {
235236
if available_space == 0 {
236237
if self.is_nonblock {
237238
// Non-blocking socketpair with a full buffer.
238-
ecx.write_byte_helper(Err(Error::from(ErrorKind::WouldBlock)), dest)?;
239+
let result = Err(Error::from(ErrorKind::WouldBlock));
240+
ecx.write_byte_helper(result, dest)?;
239241
return Ok(());
240242
} else {
241243
// Blocking socketpair with a full buffer.
@@ -257,7 +259,8 @@ impl FileDescription for AnonSocket {
257259
// The kernel does this even if the fd was already readable before, so we follow suit.
258260
ecx.check_and_update_readiness(&peer_fd)?;
259261

260-
ecx.write_byte_helper(Ok(actual_write_size), dest)?;
262+
let result = Ok(actual_write_size);
263+
ecx.write_byte_helper(result, dest)?;
261264
return Ok(());
262265
}
263266
}

0 commit comments

Comments
 (0)