|
1 | 1 | use std::collections::HashMap;
|
2 | 2 |
|
3 |
| -use rustc::ty::layout::{Size, Align}; |
| 3 | +use rustc::ty::layout::{Size}; |
4 | 4 | use rustc_mir::interpret::{Pointer, Memory};
|
5 | 5 | use crate::stacked_borrows::Tag;
|
6 | 6 | use crate::*;
|
@@ -36,24 +36,11 @@ fn alloc_env_var<'mir, 'tcx>(
|
36 | 36 | value: &[u8],
|
37 | 37 | memory: &mut Memory<'mir, 'tcx, Evaluator<'tcx>>,
|
38 | 38 | ) -> Pointer<Tag> {
|
39 |
| - let bytes = [name, b"=", value].concat(); |
40 |
| - let tcx = {memory.tcx.tcx}; |
41 |
| - let length = bytes.len() as u64; |
42 |
| - // `+1` for the null terminator. |
43 |
| - let ptr = memory.allocate( |
44 |
| - Size::from_bytes(length + 1), |
45 |
| - Align::from_bytes(1).unwrap(), |
46 |
| - MiriMemoryKind::Env.into(), |
47 |
| - ); |
48 |
| - // We just allocated these, so the write cannot fail. |
49 |
| - let alloc = memory.get_mut(ptr.alloc_id).unwrap(); |
50 |
| - alloc.write_bytes(&tcx, ptr, &bytes).unwrap(); |
51 |
| - let trailing_zero_ptr = ptr.offset( |
52 |
| - Size::from_bytes(length), |
53 |
| - &tcx, |
54 |
| - ).unwrap(); |
55 |
| - alloc.write_bytes(&tcx, trailing_zero_ptr, &[0]).unwrap(); |
56 |
| - ptr |
| 39 | + let mut bytes = name.to_vec(); |
| 40 | + bytes.push(b'='); |
| 41 | + bytes.extend_from_slice(value); |
| 42 | + bytes.push(0); |
| 43 | + memory.allocate_static_bytes(bytes.as_slice(), MiriMemoryKind::Env.into()) |
57 | 44 | }
|
58 | 45 |
|
59 | 46 | impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
|
|
0 commit comments