Skip to content

Commit

Permalink
Remove some trait bounds.
Browse files Browse the repository at this point in the history
This will make it easier to implement Clone on some of these structs.
  • Loading branch information
mstange committed Apr 11, 2024
1 parent b754c6a commit 32d3103
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/aarch64/unwinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ use super::{ArchAarch64, CacheAarch64, UnwindRegsAarch64};
///
/// - `D`: The type for unwind section data in the modules. See [`Module`].
/// - `P`: The [`AllocationPolicy`].
pub struct UnwinderAarch64<D: Deref<Target = [u8]>, P: AllocationPolicy = MayAllocateDuringUnwind>(
UnwinderInternal<D, ArchAarch64, P>,
);
pub struct UnwinderAarch64<D, P = MayAllocateDuringUnwind>(UnwinderInternal<D, ArchAarch64, P>);

impl<D: Deref<Target = [u8]>, P: AllocationPolicy> Default for UnwinderAarch64<D, P> {
impl<D, P> Default for UnwinderAarch64<D, P> {
fn default() -> Self {
Self::new()
}
}

impl<D: Deref<Target = [u8]>, P: AllocationPolicy> UnwinderAarch64<D, P> {
impl<D, P> UnwinderAarch64<D, P> {
/// Create an unwinder for a process.
pub fn new() -> Self {
Self(UnwinderInternal::new())
Expand Down
16 changes: 8 additions & 8 deletions src/unwinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ cfg_if::cfg_if! {
}
}

pub struct UnwinderInternal<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> {
pub struct UnwinderInternal<D, A, P> {
/// sorted by avma_range.start
modules: Vec<Module<D>>,
/// Incremented every time modules is changed.
Expand All @@ -230,15 +230,13 @@ pub struct UnwinderInternal<D: Deref<Target = [u8]>, A: Unwinding, P: Allocation
_allocation_policy: PhantomData<P>,
}

impl<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> Default
for UnwinderInternal<D, A, P>
{
impl<D, A, P> Default for UnwinderInternal<D, A, P> {
fn default() -> Self {
Self::new()
}
}

impl<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> UnwinderInternal<D, A, P> {
impl<D, A, P> UnwinderInternal<D, A, P> {
pub fn new() -> Self {
Self {
modules: Vec::new(),
Expand All @@ -247,7 +245,9 @@ impl<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> UnwinderInterna
_allocation_policy: PhantomData,
}
}
}

impl<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> UnwinderInternal<D, A, P> {
pub fn add_module(&mut self, module: Module<D>) {
let insertion_index = match self
.modules
Expand Down Expand Up @@ -566,7 +566,7 @@ impl<D: Deref<Target = [u8]>, A: Unwinding, P: AllocationPolicy> UnwinderInterna
/// module, e.g. `Vec<u8>`. But it could also be a wrapper around mapped memory from
/// a file or a different process, for example. It just needs to provide a slice of
/// bytes via its `Deref` implementation.
enum ModuleUnwindDataInternal<D: Deref<Target = [u8]>> {
enum ModuleUnwindDataInternal<D> {
/// Used on macOS, with mach-O binaries. Compact unwind info is in the `__unwind_info`
/// section and is sometimes supplemented with DWARF CFI information in the `__eh_frame`
/// section. `__stubs` and `__stub_helper` ranges are used by the unwinder.
Expand Down Expand Up @@ -729,7 +729,7 @@ impl<D: Deref<Target = [u8]>> ModuleUnwindDataInternal<D> {
/// a file or a different process, for example. It just needs to provide a slice of
/// bytes via its `Deref` implementation.
#[cfg(feature = "macho")]
struct TextByteData<D: Deref<Target = [u8]>> {
struct TextByteData<D> {
pub bytes: D,
pub svma_range: Range<u64>,
}
Expand All @@ -747,7 +747,7 @@ struct TextByteData<D: Deref<Target = [u8]>> {
/// module, e.g. `Vec<u8>`. But it could also be a wrapper around mapped memory from
/// a file or a different process, for example. It just needs to provide a slice of
/// bytes via its `Deref` implementation.
pub struct Module<D: Deref<Target = [u8]>> {
pub struct Module<D> {
/// The name or file path of the module. Unused, it's just there for easier debugging.
#[allow(unused)]
name: String,
Expand Down
8 changes: 3 additions & 5 deletions src/x86_64/unwinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ use crate::FrameAddress;
///
/// - `D`: The type for unwind section data in the modules. See [`Module`].
/// - `P`: The [`AllocationPolicy`].
pub struct UnwinderX86_64<D: Deref<Target = [u8]>, P: AllocationPolicy = MayAllocateDuringUnwind>(
UnwinderInternal<D, ArchX86_64, P>,
);
pub struct UnwinderX86_64<D, P = MayAllocateDuringUnwind>(UnwinderInternal<D, ArchX86_64, P>);

impl<D: Deref<Target = [u8]>, P: AllocationPolicy> Default for UnwinderX86_64<D, P> {
impl<D, P> Default for UnwinderX86_64<D, P> {
fn default() -> Self {
Self::new()
}
}

impl<D: Deref<Target = [u8]>, P: AllocationPolicy> UnwinderX86_64<D, P> {
impl<D, P> UnwinderX86_64<D, P> {
/// Create an unwinder for a process.
pub fn new() -> Self {
Self(UnwinderInternal::new())
Expand Down

0 comments on commit 32d3103

Please sign in to comment.