Skip to content

Commit cc2f46e

Browse files
committed
Reorder methods in allocation.rs
1 parent 20dee47 commit cc2f46e

File tree

1 file changed

+85
-85
lines changed

1 file changed

+85
-85
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,91 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
8989
}
9090
}
9191

92+
/// Byte accessors
93+
impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
94+
/// The last argument controls whether we error out when there are undefined
95+
/// or pointer bytes. You should never call this, call `get_bytes` or
96+
/// `get_bytes_with_undef_and_ptr` instead,
97+
///
98+
/// This function also guarantees that the resulting pointer will remain stable
99+
/// even when new allocations are pushed to the `HashMap`. `copy_repeatedly` relies
100+
/// on that.
101+
fn get_bytes_internal(
102+
&self,
103+
cx: &impl HasDataLayout,
104+
ptr: Pointer<Tag>,
105+
size: Size,
106+
align: Align,
107+
check_defined_and_ptr: bool,
108+
) -> EvalResult<'tcx, &[u8]> {
109+
self.check_align(ptr.into(), align)?;
110+
self.check_bounds(cx, ptr, size)?;
111+
112+
if check_defined_and_ptr {
113+
self.check_defined(ptr, size)?;
114+
self.check_relocations(cx, ptr, size)?;
115+
} else {
116+
// We still don't want relocations on the *edges*
117+
self.check_relocation_edges(cx, ptr, size)?;
118+
}
119+
120+
AllocationExtra::memory_read(self, ptr, size)?;
121+
122+
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
123+
assert_eq!(size.bytes() as usize as u64, size.bytes());
124+
let offset = ptr.offset.bytes() as usize;
125+
Ok(&self.bytes[offset..offset + size.bytes() as usize])
126+
}
127+
128+
#[inline]
129+
fn get_bytes(
130+
&self,
131+
cx: &impl HasDataLayout,
132+
ptr: Pointer<Tag>,
133+
size: Size,
134+
align: Align
135+
) -> EvalResult<'tcx, &[u8]> {
136+
self.get_bytes_internal(cx, ptr, size, align, true)
137+
}
138+
139+
/// It is the caller's responsibility to handle undefined and pointer bytes.
140+
/// However, this still checks that there are no relocations on the *edges*.
141+
#[inline]
142+
pub fn get_bytes_with_undef_and_ptr(
143+
&self,
144+
cx: &impl HasDataLayout,
145+
ptr: Pointer<Tag>,
146+
size: Size,
147+
align: Align
148+
) -> EvalResult<'tcx, &[u8]> {
149+
self.get_bytes_internal(cx, ptr, size, align, false)
150+
}
151+
152+
/// Just calling this already marks everything as defined and removes relocations,
153+
/// so be sure to actually put data there!
154+
pub fn get_bytes_mut(
155+
&mut self,
156+
cx: &impl HasDataLayout,
157+
ptr: Pointer<Tag>,
158+
size: Size,
159+
align: Align,
160+
) -> EvalResult<'tcx, &mut [u8]> {
161+
assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
162+
self.check_align(ptr.into(), align)?;
163+
self.check_bounds(cx, ptr, size)?;
164+
165+
self.mark_definedness(ptr, size, true)?;
166+
self.clear_relocations(cx, ptr, size)?;
167+
168+
AllocationExtra::memory_written(self, ptr, size)?;
169+
170+
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
171+
assert_eq!(size.bytes() as usize as u64, size.bytes());
172+
let offset = ptr.offset.bytes() as usize;
173+
Ok(&mut self.bytes[offset..offset + size.bytes() as usize])
174+
}
175+
}
176+
92177
/// Reading and writing
93178
impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
94179
pub fn read_c_str(
@@ -291,91 +376,6 @@ fn int_align(
291376
ity.align(cx).abi
292377
}
293378

294-
/// Byte accessors
295-
impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
296-
/// The last argument controls whether we error out when there are undefined
297-
/// or pointer bytes. You should never call this, call `get_bytes` or
298-
/// `get_bytes_with_undef_and_ptr` instead,
299-
///
300-
/// This function also guarantees that the resulting pointer will remain stable
301-
/// even when new allocations are pushed to the `HashMap`. `copy_repeatedly` relies
302-
/// on that.
303-
fn get_bytes_internal(
304-
&self,
305-
cx: &impl HasDataLayout,
306-
ptr: Pointer<Tag>,
307-
size: Size,
308-
align: Align,
309-
check_defined_and_ptr: bool,
310-
) -> EvalResult<'tcx, &[u8]> {
311-
self.check_align(ptr.into(), align)?;
312-
self.check_bounds(cx, ptr, size)?;
313-
314-
if check_defined_and_ptr {
315-
self.check_defined(ptr, size)?;
316-
self.check_relocations(cx, ptr, size)?;
317-
} else {
318-
// We still don't want relocations on the *edges*
319-
self.check_relocation_edges(cx, ptr, size)?;
320-
}
321-
322-
AllocationExtra::memory_read(self, ptr, size)?;
323-
324-
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
325-
assert_eq!(size.bytes() as usize as u64, size.bytes());
326-
let offset = ptr.offset.bytes() as usize;
327-
Ok(&self.bytes[offset..offset + size.bytes() as usize])
328-
}
329-
330-
#[inline]
331-
fn get_bytes(
332-
&self,
333-
cx: &impl HasDataLayout,
334-
ptr: Pointer<Tag>,
335-
size: Size,
336-
align: Align
337-
) -> EvalResult<'tcx, &[u8]> {
338-
self.get_bytes_internal(cx, ptr, size, align, true)
339-
}
340-
341-
/// It is the caller's responsibility to handle undefined and pointer bytes.
342-
/// However, this still checks that there are no relocations on the *edges*.
343-
#[inline]
344-
pub fn get_bytes_with_undef_and_ptr(
345-
&self,
346-
cx: &impl HasDataLayout,
347-
ptr: Pointer<Tag>,
348-
size: Size,
349-
align: Align
350-
) -> EvalResult<'tcx, &[u8]> {
351-
self.get_bytes_internal(cx, ptr, size, align, false)
352-
}
353-
354-
/// Just calling this already marks everything as defined and removes relocations,
355-
/// so be sure to actually put data there!
356-
pub fn get_bytes_mut(
357-
&mut self,
358-
cx: &impl HasDataLayout,
359-
ptr: Pointer<Tag>,
360-
size: Size,
361-
align: Align,
362-
) -> EvalResult<'tcx, &mut [u8]> {
363-
assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
364-
self.check_align(ptr.into(), align)?;
365-
self.check_bounds(cx, ptr, size)?;
366-
367-
self.mark_definedness(ptr, size, true)?;
368-
self.clear_relocations(cx, ptr, size)?;
369-
370-
AllocationExtra::memory_written(self, ptr, size)?;
371-
372-
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
373-
assert_eq!(size.bytes() as usize as u64, size.bytes());
374-
let offset = ptr.offset.bytes() as usize;
375-
Ok(&mut self.bytes[offset..offset + size.bytes() as usize])
376-
}
377-
}
378-
379379
/// Relocations
380380
impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
381381
/// Return all relocations overlapping with the given ptr-offset pair.

0 commit comments

Comments
 (0)