Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/dense_byte_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::hint::unreachable_unchecked;

use crate::alloc::Allocator;
use crate::ring::*;
use crate::utils::ByteMask;
use crate::utils::{AbortOnUnwind, ByteMask};

use crate::utils::BitMask;
use crate::trie_node::*;
Expand Down Expand Up @@ -2215,6 +2215,10 @@ impl<V: Clone + Send + Sync + Lattice, A: Allocator, Cf: CoFree<V=V, A=A>, Other
let mut r = 0;
let mut c = 0;

// The loop moves entries before repairing vector lengths. Do not let a
// panic unwind into vectors that still claim ownership of moved entries.
let abort_on_unwind = AbortOnUnwind;

for i in 0..4 {
let mut lm = jm.0[i];
while lm != 0 {
Expand Down Expand Up @@ -2250,6 +2254,7 @@ impl<V: Clone + Send + Sync + Lattice, A: Allocator, Cf: CoFree<V=V, A=A>, Other
unsafe { self.values.set_len(0) }
unsafe { other.values.set_len(0) }
unsafe { v.v.set_len(c) }
core::mem::forget(abort_on_unwind);
self.mask = jm;
self.values = v.v;

Expand Down
13 changes: 12 additions & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ pub mod ints;

pub mod debug;

/// Aborts if dropped, preventing unwinding through a temporarily invalid state.
/// Forget this guard once the protected invariants have been restored.
pub(crate) struct AbortOnUnwind;

impl Drop for AbortOnUnwind {
#[cold]
fn drop(&mut self) {
std::process::abort();
}
}

/// Use `fast_slice_utils` directly. We don't want to maintain this re-export from pathmap
//GOAT, remove this re-export when nothing downstream is going to break
#[deprecated]
Expand Down Expand Up @@ -1233,4 +1244,4 @@ mod tests {
core::assert_eq!(mask_byte,range_byte);
}
}
}
}