diff --git a/rust/src/backgroundtask.rs b/rust/src/backgroundtask.rs index e62cfbcb0..e5fa6e77a 100644 --- a/rust/src/backgroundtask.rs +++ b/rust/src/backgroundtask.rs @@ -104,21 +104,14 @@ unsafe impl RefCountable for BackgroundTask { impl CoreArrayProvider for BackgroundTask { type Raw = *mut BNBackgroundTask; type Context = (); + type Wrapped<'a> = Guard<'a, BackgroundTask>; } -unsafe impl CoreOwnedArrayProvider for BackgroundTask { +unsafe impl CoreArrayProviderInner for BackgroundTask { unsafe fn free(raw: *mut *mut BNBackgroundTask, count: usize, _context: &()) { BNFreeBackgroundTaskList(raw, count); } -} - -unsafe impl CoreArrayWrapper for BackgroundTask { - type Wrapped<'a> = Guard<'a, BackgroundTask>; - - unsafe fn wrap_raw<'a>( - raw: &'a *mut BNBackgroundTask, - context: &'a (), - ) -> Self::Wrapped<'a> { + unsafe fn wrap_raw<'a>(raw: &'a *mut BNBackgroundTask, context: &'a ()) -> Self::Wrapped<'a> { Guard::new(BackgroundTask::from_raw(*raw), context) } } diff --git a/rust/src/basicblock.rs b/rust/src/basicblock.rs index f28e596f1..a6ac8f745 100644 --- a/rust/src/basicblock.rs +++ b/rust/src/basicblock.rs @@ -68,17 +68,13 @@ pub struct EdgeContext<'a, C: 'a + BlockContext> { impl<'a, C: 'a + BlockContext> CoreArrayProvider for Edge<'a, C> { type Raw = BNBasicBlockEdge; type Context = EdgeContext<'a, C>; + type Wrapped<'b> = Edge<'b, C> where 'a: 'b; } -unsafe impl<'a, C: 'a + BlockContext> CoreOwnedArrayProvider for Edge<'a, C> { +unsafe impl<'a, C: 'a + BlockContext> CoreArrayProviderInner for Edge<'a, C> { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeBasicBlockEdgeList(raw, count); } -} - -unsafe impl<'a, C: BlockContext> CoreArrayWrapper for Edge<'a, C> { - type Wrapped<'b> = Edge<'b, C> where 'a: 'b; - unsafe fn wrap_raw<'b>(raw: &'b Self::Raw, context: &'b Self::Context) -> Self::Wrapped<'b> { let edge_target = Guard::new( BasicBlock::from_raw(raw.target, context.orig_block.context.clone()), @@ -301,17 +297,13 @@ unsafe impl RefCountable for BasicBlock { impl CoreArrayProvider for BasicBlock { type Raw = *mut BNBasicBlock; type Context = C; + type Wrapped<'a> = Guard<'a, BasicBlock> where C: 'a; } -unsafe impl CoreOwnedArrayProvider for BasicBlock { +unsafe impl CoreArrayProviderInner for BasicBlock { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeBasicBlockList(raw, count); } -} - -unsafe impl CoreArrayWrapper for BasicBlock { - type Wrapped<'a> = Guard<'a, BasicBlock> where C: 'a; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(BasicBlock::from_raw(*raw, context.clone()), context) } diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs index ef2725e8f..e29e41a83 100644 --- a/rust/src/callingconvention.rs +++ b/rust/src/callingconvention.rs @@ -26,7 +26,7 @@ use binaryninjacore_sys::*; use crate::architecture::{Architecture, ArchitectureExt, CoreArchitecture, Register}; use crate::rc::{ - CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable, + CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable, }; use crate::string::*; @@ -686,17 +686,13 @@ unsafe impl RefCountable for CallingConvention { impl CoreArrayProvider for CallingConvention { type Raw = *mut BNCallingConvention; type Context = A::Handle; + type Wrapped<'a> = Guard<'a, CallingConvention>; } -unsafe impl CoreOwnedArrayProvider for CallingConvention { +unsafe impl CoreArrayProviderInner for CallingConvention { unsafe fn free(raw: *mut *mut BNCallingConvention, count: usize, _content: &Self::Context) { BNFreeCallingConventionList(raw, count); } -} - -unsafe impl CoreArrayWrapper for CallingConvention { - type Wrapped<'a> = Guard<'a, CallingConvention>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new( CallingConvention { diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs index 4c645ffda..05f1acb8d 100644 --- a/rust/src/custombinaryview.rs +++ b/rust/src/custombinaryview.rs @@ -290,17 +290,13 @@ impl BinaryViewTypeBase for BinaryViewType { impl CoreArrayProvider for BinaryViewType { type Raw = *mut BNBinaryViewType; type Context = (); + type Wrapped<'a> = Guard<'a, BinaryViewType>; } -unsafe impl CoreOwnedArrayProvider for BinaryViewType { +unsafe impl CoreArrayProviderInner for BinaryViewType { unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { BNFreeBinaryViewTypeList(raw); } -} - -unsafe impl CoreArrayWrapper for BinaryViewType { - type Wrapped<'a> = Guard<'a, BinaryViewType>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(BinaryViewType(*raw), &()) } diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index d53faef3a..dd5d0e0b6 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -269,12 +269,16 @@ impl ToOwned for DebugInfoParser { impl CoreArrayProvider for DebugInfoParser { type Raw = *mut BNDebugInfoParser; type Context = (); + type Wrapped<'a> = Guard<'a, DebugInfoParser>; } -unsafe impl CoreOwnedArrayProvider for DebugInfoParser { +unsafe impl CoreArrayProviderInner for DebugInfoParser { unsafe fn free(raw: *mut Self::Raw, count: usize, _: &Self::Context) { BNFreeDebugInfoParserList(raw, count); } + unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { + Guard::new(Self { handle: *raw }, context) + } } /////////////////////// diff --git a/rust/src/downloadprovider.rs b/rust/src/downloadprovider.rs index 8334e0cea..0d388486e 100644 --- a/rust/src/downloadprovider.rs +++ b/rust/src/downloadprovider.rs @@ -1,6 +1,4 @@ -use crate::rc::{ - Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable, -}; +use crate::rc::{Array, CoreArrayProvider, Guard, CoreArrayProviderInner, Ref, RefCountable}; use crate::settings::Settings; use crate::string::{BnStrCompatible, BnString}; use binaryninjacore_sys::*; @@ -63,17 +61,13 @@ impl DownloadProvider { impl CoreArrayProvider for DownloadProvider { type Raw = *mut BNDownloadProvider; type Context = (); + type Wrapped<'a> = Guard<'a, DownloadProvider>; } -unsafe impl CoreOwnedArrayProvider for DownloadProvider { +unsafe impl CoreArrayProviderInner for DownloadProvider { unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { BNFreeDownloadProviderList(raw); } -} - -unsafe impl CoreArrayWrapper for DownloadProvider { - type Wrapped<'a> = Guard<'a, DownloadProvider>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(DownloadProvider::from_raw(*raw), &()) } diff --git a/rust/src/function.rs b/rust/src/function.rs index 74e05ea55..f57d2fe3b 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -414,17 +414,13 @@ unsafe impl RefCountable for Function { impl CoreArrayProvider for Function { type Raw = *mut BNFunction; type Context = (); + type Wrapped<'a> = Guard<'a, Function>; } -unsafe impl CoreOwnedArrayProvider for Function { +unsafe impl CoreArrayProviderInner for Function { unsafe fn free(raw: *mut *mut BNFunction, count: usize, _context: &()) { BNFreeFunctionList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Function { - type Wrapped<'a> = Guard<'a, Function>; - unsafe fn wrap_raw<'a>(raw: &'a *mut BNFunction, context: &'a ()) -> Self::Wrapped<'a> { Guard::new(Function { handle: *raw }, context) } @@ -469,16 +465,12 @@ impl AddressRange { impl CoreArrayProvider for AddressRange { type Raw = BNAddressRange; type Context = (); + type Wrapped<'a> = &'a AddressRange; } -unsafe impl CoreOwnedArrayProvider for AddressRange { +unsafe impl CoreArrayProviderInner for AddressRange { unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { BNFreeAddressRanges(raw); } -} - -unsafe impl CoreArrayWrapper for AddressRange { - type Wrapped<'a> = &'a AddressRange; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { mem::transmute(raw) } diff --git a/rust/src/linearview.rs b/rust/src/linearview.rs index 31b05ad27..84b4323e4 100644 --- a/rust/src/linearview.rs +++ b/rust/src/linearview.rs @@ -415,17 +415,13 @@ impl std::fmt::Display for LinearDisassemblyLine { impl CoreArrayProvider for LinearDisassemblyLine { type Raw = BNLinearDisassemblyLine; type Context = (); + type Wrapped<'a> = Guard<'a, LinearDisassemblyLine>; } -unsafe impl CoreOwnedArrayProvider for LinearDisassemblyLine { +unsafe impl CoreArrayProviderInner for LinearDisassemblyLine { unsafe fn free(raw: *mut BNLinearDisassemblyLine, count: usize, _context: &()) { BNFreeLinearDisassemblyLines(raw, count); } -} - -unsafe impl CoreArrayWrapper for LinearDisassemblyLine { - type Wrapped<'a> = Guard<'a, LinearDisassemblyLine>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(LinearDisassemblyLine::from_raw(raw), _context) } diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs index 6f026a04c..8cb32d72b 100644 --- a/rust/src/metadata.rs +++ b/rust/src/metadata.rs @@ -1,6 +1,4 @@ -use crate::rc::{ - Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable, -}; +use crate::rc::{Array, CoreArrayProvider, Guard, CoreArrayProviderInner, Ref, RefCountable}; use crate::string::{BnStrCompatible, BnString}; use binaryninjacore_sys::*; use std::collections::HashMap; @@ -335,17 +333,13 @@ unsafe impl RefCountable for Metadata { impl CoreArrayProvider for Metadata { type Raw = *mut BNMetadata; type Context = (); + type Wrapped<'a> = Guard<'a, Metadata>; } -unsafe impl CoreOwnedArrayProvider for Metadata { +unsafe impl CoreArrayProviderInner for Metadata { unsafe fn free(raw: *mut *mut BNMetadata, _count: usize, _context: &()) { BNFreeMetadataArray(raw); } -} - -unsafe impl CoreArrayWrapper for Metadata { - type Wrapped<'a> = Guard<'a, Metadata>; - unsafe fn wrap_raw<'a>(raw: &'a *mut BNMetadata, context: &'a ()) -> Self::Wrapped<'a> { Guard::new(Metadata::from_raw(*raw), context) } diff --git a/rust/src/platform.rs b/rust/src/platform.rs index 42e2f80cc..11f76284b 100644 --- a/rust/src/platform.rs +++ b/rust/src/platform.rs @@ -365,17 +365,13 @@ unsafe impl RefCountable for Platform { impl CoreArrayProvider for Platform { type Raw = *mut BNPlatform; type Context = (); + type Wrapped<'a> = Guard<'a, Platform>; } -unsafe impl CoreOwnedArrayProvider for Platform { +unsafe impl CoreArrayProviderInner for Platform { unsafe fn free(raw: *mut *mut BNPlatform, count: usize, _context: &()) { BNFreePlatformList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Platform { - type Wrapped<'a> = Guard<'a, Platform>; - unsafe fn wrap_raw<'a>(raw: &'a *mut BNPlatform, context: &'a ()) -> Self::Wrapped<'a> { debug_assert!(!raw.is_null()); Guard::new(Platform { handle: *raw }, context) diff --git a/rust/src/rc.rs b/rust/src/rc.rs index eaf8e5d26..dc1a502bb 100644 --- a/rust/src/rc.rs +++ b/rust/src/rc.rs @@ -35,7 +35,7 @@ use std::slice; // `T` does not have the `Drop` impl in order to allow more // efficient handling of core owned objects we receive pointers // to in callbacks -pub unsafe trait RefCountable: ToOwned> + Sized { +pub(crate) unsafe trait RefCountable: ToOwned> + Sized { unsafe fn inc_ref(handle: &Self) -> Ref; unsafe fn dec_ref(handle: &Self); } @@ -43,10 +43,12 @@ pub unsafe trait RefCountable: ToOwned> + Sized { // Represents an 'owned' reference tracked by the core // that we are responsible for cleaning up once we're // done with the encapsulated value. +#[allow(private_bounds)] pub struct Ref { contents: T, } +#[allow(private_bounds)] impl Ref { /// Safety: You need to make sure wherever you got the contents from incremented the ref count already. Anywhere the core passes out an object to the API does this. pub(crate) unsafe fn new(contents: T) -> Self { @@ -151,6 +153,7 @@ impl<'a, T> Guard<'a, T> { } } +#[allow(private_bounds)] impl<'a, T> Guard<'a, T> where T: RefCountable, @@ -190,21 +193,18 @@ impl<'a, T> Borrow for Guard<'a, T> { pub trait CoreArrayProvider { type Raw; type Context; -} - -pub unsafe trait CoreOwnedArrayProvider: CoreArrayProvider { - unsafe fn free(raw: *mut Self::Raw, count: usize, context: &Self::Context); -} - -pub unsafe trait CoreArrayWrapper: CoreArrayProvider { type Wrapped<'a> where Self: 'a; +} +pub(crate) unsafe trait CoreArrayProviderInner: CoreArrayProvider { + unsafe fn free(raw: *mut Self::Raw, count: usize, context: &Self::Context); unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a>; } -pub struct Array { +#[allow(private_bounds)] +pub struct Array { contents: *mut P::Raw, count: usize, context: P::Context, @@ -212,18 +212,19 @@ pub struct Array { unsafe impl

Sync for Array

where - P: CoreOwnedArrayProvider, + P: CoreArrayProviderInner, P::Context: Sync, { } unsafe impl

Send for Array

where - P: CoreOwnedArrayProvider, + P: CoreArrayProviderInner, P::Context: Send, { } -impl Array

{ +#[allow(private_bounds)] +impl Array

{ pub(crate) unsafe fn new(raw: *mut P::Raw, count: usize, context: P::Context) -> Self { Self { contents: raw, @@ -241,14 +242,10 @@ impl Array

{ pub fn is_empty(&self) -> bool { self.count == 0 } - - pub fn into_raw_parts(self) -> (*mut P::Raw, usize) { - let me = mem::ManuallyDrop::new(self); - (me.contents, me.count) - } } -impl Array

{ +#[allow(private_bounds)] +impl Array

{ #[inline] pub fn get(&self, index: usize) -> P::Wrapped<'_> { unsafe { @@ -265,7 +262,7 @@ impl Array

{ } } -impl<'a, P: CoreArrayWrapper + CoreOwnedArrayProvider> IntoIterator for &'a Array

{ +impl<'a, P: CoreArrayProviderInner> IntoIterator for &'a Array

{ type Item = P::Wrapped<'a>; type IntoIter = ArrayIter<'a, P>; @@ -274,7 +271,7 @@ impl<'a, P: CoreArrayWrapper + CoreOwnedArrayProvider> IntoIterator for &'a Arra } } -impl Drop for Array

{ +impl Drop for Array

{ fn drop(&mut self) { unsafe { P::free(self.contents, self.count, &self.context); @@ -282,7 +279,8 @@ impl Drop for Array

{ } } -pub struct ArrayGuard { +#[allow(private_bounds)] +pub struct ArrayGuard { contents: *mut P::Raw, count: usize, context: P::Context, @@ -290,18 +288,19 @@ pub struct ArrayGuard { unsafe impl

Sync for ArrayGuard

where - P: CoreArrayProvider, + P: CoreArrayProviderInner, P::Context: Sync, { } unsafe impl

Send for ArrayGuard

where - P: CoreArrayProvider, + P: CoreArrayProviderInner, P::Context: Send, { } -impl ArrayGuard

{ +#[allow(private_bounds)] +impl ArrayGuard

{ pub(crate) unsafe fn new(raw: *mut P::Raw, count: usize, context: P::Context) -> Self { Self { contents: raw, @@ -321,7 +320,8 @@ impl ArrayGuard

{ } } -impl ArrayGuard

{ +#[allow(private_bounds)] +impl ArrayGuard

{ #[inline] pub fn get(&self, index: usize) -> P::Wrapped<'_> { unsafe { @@ -338,7 +338,7 @@ impl ArrayGuard

{ } } -impl<'a, P: CoreArrayWrapper + CoreArrayProvider> IntoIterator for &'a ArrayGuard

{ +impl<'a, P: CoreArrayProviderInner> IntoIterator for &'a ArrayGuard

{ type Item = P::Wrapped<'a>; type IntoIter = ArrayIter<'a, P>; @@ -347,9 +347,10 @@ impl<'a, P: CoreArrayWrapper + CoreArrayProvider> IntoIterator for &'a ArrayGuar } } +#[allow(private_bounds)] pub struct ArrayIter<'a, P> where - P: CoreArrayWrapper, + P: CoreArrayProviderInner, { it: slice::Iter<'a, P::Raw>, context: &'a P::Context, @@ -357,14 +358,14 @@ where unsafe impl

Send for ArrayIter<'_, P> where - P: CoreArrayWrapper, + P: CoreArrayProviderInner, P::Context: Sync, { } impl<'a, P> Iterator for ArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, { type Item = P::Wrapped<'a>; @@ -383,7 +384,7 @@ where impl<'a, P> ExactSizeIterator for ArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, { #[inline] fn len(&self) -> usize { @@ -393,7 +394,7 @@ where impl<'a, P> DoubleEndedIterator for ArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, { #[inline] fn next_back(&mut self) -> Option> { @@ -409,10 +410,11 @@ use rayon::prelude::*; #[cfg(feature = "rayon")] use rayon::iter::plumbing::*; +#[allow(private_bounds)] #[cfg(feature = "rayon")] impl

Array

where - P: CoreArrayWrapper + CoreOwnedArrayProvider, + P: CoreArrayProviderInner, P::Context: Sync, for<'a> P::Wrapped<'a>: Send, { @@ -420,10 +422,11 @@ where ParArrayIter { it: self.iter() } } } +#[allow(private_bounds)] #[cfg(feature = "rayon")] pub struct ParArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: CoreArrayProviderInner, ArrayIter<'a, P>: Send, { it: ArrayIter<'a, P>, @@ -432,7 +435,7 @@ where #[cfg(feature = "rayon")] impl<'a, P> ParallelIterator for ParArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, P::Wrapped<'a>: Send, ArrayIter<'a, P>: Send, { @@ -453,7 +456,7 @@ where #[cfg(feature = "rayon")] impl<'a, P> IndexedParallelIterator for ParArrayIter<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, P::Wrapped<'a>: Send, ArrayIter<'a, P>: Send, { @@ -479,7 +482,7 @@ where #[cfg(feature = "rayon")] struct ArrayIterProducer<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, ArrayIter<'a, P>: Send, { it: ArrayIter<'a, P>, @@ -488,7 +491,7 @@ where #[cfg(feature = "rayon")] impl<'a, P> Producer for ArrayIterProducer<'a, P> where - P: 'a + CoreArrayWrapper, + P: 'a + CoreArrayProviderInner, ArrayIter<'a, P>: Send, { type Item = P::Wrapped<'a>; diff --git a/rust/src/references.rs b/rust/src/references.rs index 8b4ebb874..d12c33c55 100644 --- a/rust/src/references.rs +++ b/rust/src/references.rs @@ -1,6 +1,6 @@ use crate::architecture::CoreArchitecture; use crate::function::Function; -use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref}; +use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref}; use binaryninjacore_sys::{BNFreeCodeReferences, BNFreeDataReferences, BNReferenceSource}; use std::mem::ManuallyDrop; @@ -56,17 +56,13 @@ impl<'a> CodeReference { impl CoreArrayProvider for CodeReference { type Raw = BNReferenceSource; type Context = (); + type Wrapped<'a> = Guard<'a, CodeReference>; } -unsafe impl CoreOwnedArrayProvider for CodeReference { +unsafe impl CoreArrayProviderInner for CodeReference { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeCodeReferences(raw, count) } -} - -unsafe impl CoreArrayWrapper for CodeReference { - type Wrapped<'a> = Guard<'a, CodeReference>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(CodeReference::new(raw), &()) } @@ -77,17 +73,13 @@ unsafe impl CoreArrayWrapper for CodeReference { impl CoreArrayProvider for DataReference { type Raw = u64; type Context = (); + type Wrapped<'a> = DataReference; } -unsafe impl CoreOwnedArrayProvider for DataReference { +unsafe impl CoreArrayProviderInner for DataReference { unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { BNFreeDataReferences(raw) } -} - -unsafe impl CoreArrayWrapper for DataReference { - type Wrapped<'a> = DataReference; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { DataReference { address: *raw } } diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs index 17fd59582..f9ece0435 100644 --- a/rust/src/relocation.rs +++ b/rust/src/relocation.rs @@ -4,7 +4,7 @@ use crate::{ architecture::{Architecture, CoreArchitecture}, binaryview::BinaryView, llil, - rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable}, + rc::{CoreArrayProvider, CoreArrayProviderInner, Ref, RefCountable}, symbol::Symbol, }; use binaryninjacore_sys::*; @@ -221,16 +221,13 @@ impl Relocation { impl CoreArrayProvider for Relocation { type Raw = *mut BNRelocation; type Context = (); + type Wrapped<'a> = Guard<'a, Relocation>; } -unsafe impl CoreOwnedArrayProvider for Relocation { +unsafe impl CoreArrayProviderInner for Relocation { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeRelocationList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Relocation { - type Wrapped<'a> = Guard<'a, Relocation>; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(Relocation(*raw), &()) } diff --git a/rust/src/section.rs b/rust/src/section.rs index 06d09fcaa..a8efa40da 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -171,17 +171,13 @@ unsafe impl RefCountable for Section { impl CoreArrayProvider for Section { type Raw = *mut BNSection; type Context = (); + type Wrapped<'a> = Guard<'a, Section>; } -unsafe impl CoreOwnedArrayProvider for Section { +unsafe impl CoreArrayProviderInner for Section { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeSectionList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Section { - type Wrapped<'a> = Guard<'a, Section>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(Section::from_raw(*raw), context) } diff --git a/rust/src/segment.rs b/rust/src/segment.rs index 32f9db3ab..802bacc41 100644 --- a/rust/src/segment.rs +++ b/rust/src/segment.rs @@ -201,17 +201,13 @@ unsafe impl RefCountable for Segment { impl CoreArrayProvider for Segment { type Raw = *mut BNSegment; type Context = (); + type Wrapped<'a> = Guard<'a, Segment>; } -unsafe impl CoreOwnedArrayProvider for Segment { +unsafe impl CoreArrayProviderInner for Segment { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeSegmentList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Segment { - type Wrapped<'a> = Guard<'a, Segment>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(Segment::from_raw(*raw), context) } diff --git a/rust/src/string.rs b/rust/src/string.rs index 75942da91..92d344aa6 100644 --- a/rust/src/string.rs +++ b/rust/src/string.rs @@ -160,18 +160,14 @@ impl fmt::Debug for BnString { impl CoreArrayProvider for BnString { type Raw = *mut raw::c_char; type Context = (); + type Wrapped<'a> = &'a str; } -unsafe impl CoreOwnedArrayProvider for BnString { +unsafe impl CoreArrayProviderInner for BnString { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { use binaryninjacore_sys::BNFreeStringList; BNFreeStringList(raw, count); } -} - -unsafe impl CoreArrayWrapper for BnString { - type Wrapped<'a> = &'a str; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { CStr::from_ptr(*raw).to_str().unwrap() } diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs index bdf0d8552..9277b514f 100644 --- a/rust/src/symbol.rs +++ b/rust/src/symbol.rs @@ -327,17 +327,13 @@ unsafe impl RefCountable for Symbol { impl CoreArrayProvider for Symbol { type Raw = *mut BNSymbol; type Context = (); + type Wrapped<'a> = Guard<'a, Symbol>; } -unsafe impl CoreOwnedArrayProvider for Symbol { +unsafe impl CoreArrayProviderInner for Symbol { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeSymbolList(raw, count); } -} - -unsafe impl CoreArrayWrapper for Symbol { - type Wrapped<'a> = Guard<'a, Symbol>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { Guard::new(Symbol::from_raw(*raw), context) } diff --git a/rust/src/types.rs b/rust/src/types.rs index 75c8fb363..4e5b62d2f 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1438,17 +1438,13 @@ impl NamedTypedVariable { impl CoreArrayProvider for NamedTypedVariable { type Raw = BNVariableNameAndType; type Context = (); + type Wrapped<'a> = ManuallyDrop; } -unsafe impl CoreOwnedArrayProvider for NamedTypedVariable { +unsafe impl CoreArrayProviderInner for NamedTypedVariable { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeVariableNameAndTypeList(raw, count) } -} - -unsafe impl CoreArrayWrapper for NamedTypedVariable { - type Wrapped<'a> = ManuallyDrop; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { ManuallyDrop::new(NamedTypedVariable { var: raw.var, @@ -2334,16 +2330,12 @@ impl Drop for QualifiedName { impl CoreArrayProvider for QualifiedName { type Raw = BNQualifiedName; type Context = (); + type Wrapped<'a> = &'a QualifiedName; } -unsafe impl CoreOwnedArrayProvider for QualifiedName { +unsafe impl CoreArrayProviderInner for QualifiedName { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeTypeNameList(raw, count); } -} - -unsafe impl CoreArrayWrapper for QualifiedName { - type Wrapped<'a> = &'a QualifiedName; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { mem::transmute(raw) } @@ -2376,16 +2368,12 @@ impl Drop for QualifiedNameAndType { impl CoreArrayProvider for QualifiedNameAndType { type Raw = BNQualifiedNameAndType; type Context = (); + type Wrapped<'a> = &'a QualifiedNameAndType; } -unsafe impl CoreOwnedArrayProvider for QualifiedNameAndType { +unsafe impl CoreArrayProviderInner for QualifiedNameAndType { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeTypeAndNameList(raw, count); } -} - -unsafe impl CoreArrayWrapper for QualifiedNameAndType { - type Wrapped<'a> = &'a QualifiedNameAndType; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { mem::transmute(raw) } @@ -2422,16 +2410,12 @@ impl Drop for QualifiedNameTypeAndId { impl CoreArrayProvider for QualifiedNameTypeAndId { type Raw = BNQualifiedNameTypeAndId; type Context = (); + type Wrapped<'a> = &'a QualifiedNameTypeAndId; } -unsafe impl CoreOwnedArrayProvider for QualifiedNameTypeAndId { +unsafe impl CoreArrayProviderInner for QualifiedNameTypeAndId { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeTypeIdList(raw, count); } -} - -unsafe impl CoreArrayWrapper for QualifiedNameTypeAndId { - type Wrapped<'a> = &'a QualifiedNameTypeAndId; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { mem::transmute(raw) } @@ -2501,17 +2485,13 @@ unsafe impl RefCountable for NameAndType { impl CoreArrayProvider for NameAndType { type Raw = BNNameAndType; type Context = (); + type Wrapped<'a> = Guard<'a, NameAndType>; } -unsafe impl CoreOwnedArrayProvider for NameAndType { +unsafe impl CoreArrayProviderInner for NameAndType { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeNameAndTypeList(raw, count); } -} - -unsafe impl CoreArrayWrapper for NameAndType { - type Wrapped<'a> = Guard<'a, NameAndType>; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { unsafe { Guard::new(NameAndType::from_raw(raw), raw) } } @@ -2581,16 +2561,12 @@ unsafe impl RefCountable for DataVariable { impl CoreArrayProvider for DataVariable { type Raw = BNDataVariable; type Context = (); + type Wrapped<'a> = &'a DataVariable; } -unsafe impl CoreOwnedArrayProvider for DataVariable { +unsafe impl CoreArrayProviderInner for DataVariable { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeDataVariables(raw, count); } -} - -unsafe impl CoreArrayWrapper for DataVariable { - type Wrapped<'a> = &'a DataVariable; - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { mem::transmute(raw) }