Skip to content

Commit

Permalink
add tests for other allocators
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Oct 24, 2023
1 parent 616aa18 commit 35e2f73
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions capnp/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,16 @@ unsafe impl<'a> Allocator for ScratchSpaceHeapAllocator<'a> {
}

unsafe fn deallocate_segment(&mut self, ptr: *mut u8, word_size: u32, words_used: u32) {
if ptr == self.scratch_space.as_mut_ptr() {
let seg_ptr = self.scratch_space.as_mut_ptr();
if ptr == seg_ptr {
// Rezero the slice to allow reuse of the allocator. We only need to write
// words that we know might contain nonzero values.
unsafe {
core::ptr::write_bytes(ptr, 0u8, (words_used as usize) * BYTES_PER_WORD);
core::ptr::write_bytes(
seg_ptr, // miri isn't happy if we use ptr instead
0u8,
(words_used as usize) * BYTES_PER_WORD,
);
}
self.scratch_space_allocated = false;
} else {
Expand Down

0 comments on commit 35e2f73

Please sign in to comment.