summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2024-05-03 13:28:53 -0300
committerKyle Martin <krm504@nyu.edu>2024-05-10 12:00:27 -0400
commitea7a22b16fc56c23af397dd690c6c839dfb3a8f1 (patch)
tree45f3ba19172017694388ab6f7266e23df76bb670
parent015314d34d073a8ebbd958edf8150a81381f12c2 (diff)
hide array implementation details
-rw-r--r--rust/src/backgroundtask.rs13
-rw-r--r--rust/src/basicblock.rs16
-rw-r--r--rust/src/callingconvention.rs10
-rw-r--r--rust/src/custombinaryview.rs8
-rw-r--r--rust/src/debuginfo.rs6
-rw-r--r--rust/src/downloadprovider.rs12
-rw-r--r--rust/src/function.rs16
-rw-r--r--rust/src/linearview.rs8
-rw-r--r--rust/src/metadata.rs12
-rw-r--r--rust/src/platform.rs8
-rw-r--r--rust/src/rc.rs77
-rw-r--r--rust/src/references.rs18
-rw-r--r--rust/src/relocation.rs9
-rw-r--r--rust/src/section.rs8
-rw-r--r--rust/src/segment.rs8
-rw-r--r--rust/src/string.rs8
-rw-r--r--rust/src/symbol.rs8
-rw-r--r--rust/src/types.rs48
18 files changed, 99 insertions, 194 deletions
diff --git a/rust/src/backgroundtask.rs b/rust/src/backgroundtask.rs
index e62cfbcb..e5fa6e77 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 f28e596f..a6ac8f74 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<C: BlockContext> RefCountable for BasicBlock<C> {
impl<C: BlockContext> CoreArrayProvider for BasicBlock<C> {
type Raw = *mut BNBasicBlock;
type Context = C;
+ type Wrapped<'a> = Guard<'a, BasicBlock<C>> where C: 'a;
}
-unsafe impl<C: BlockContext> CoreOwnedArrayProvider for BasicBlock<C> {
+unsafe impl<C: BlockContext> CoreArrayProviderInner for BasicBlock<C> {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeBasicBlockList(raw, count);
}
-}
-
-unsafe impl<C: BlockContext> CoreArrayWrapper for BasicBlock<C> {
- type Wrapped<'a> = Guard<'a, BasicBlock<C>> 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 723a7cfa..e7888131 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::*;
@@ -678,17 +678,13 @@ unsafe impl<A: Architecture> RefCountable for CallingConvention<A> {
impl<A: Architecture> CoreArrayProvider for CallingConvention<A> {
type Raw = *mut BNCallingConvention;
type Context = A::Handle;
+ type Wrapped<'a> = Guard<'a, CallingConvention<A>>;
}
-unsafe impl<A: Architecture> CoreOwnedArrayProvider for CallingConvention<A> {
+unsafe impl<A: Architecture> CoreArrayProviderInner for CallingConvention<A> {
unsafe fn free(raw: *mut *mut BNCallingConvention, count: usize, _content: &Self::Context) {
BNFreeCallingConventionList(raw, count);
}
-}
-
-unsafe impl<A: Architecture> CoreArrayWrapper for CallingConvention<A> {
- type Wrapped<'a> = Guard<'a, CallingConvention<A>>;
-
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 4c645ffd..05f1acb8 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 2b3a2cd0..054e15cd 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -273,12 +273,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)
+ }
}
unsafe impl CoreArrayWrapper for DebugInfoParser {
diff --git a/rust/src/downloadprovider.rs b/rust/src/downloadprovider.rs
index 8334e0ce..0d388486 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 74e05ea5..f57d2fe3 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 31b05ad2..84b4323e 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 6f026a04..8cb32d72 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 42e2f80c..11f76284 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 eaf8e5d2..dc1a502b 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<Owned = Ref<Self>> + Sized {
+pub(crate) unsafe trait RefCountable: ToOwned<Owned = Ref<Self>> + Sized {
unsafe fn inc_ref(handle: &Self) -> Ref<Self>;
unsafe fn dec_ref(handle: &Self);
}
@@ -43,10 +43,12 @@ pub unsafe trait RefCountable: ToOwned<Owned = Ref<Self>> + 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<T: RefCountable> {
contents: T,
}
+#[allow(private_bounds)]
impl<T: RefCountable> Ref<T> {
/// 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<T> 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<P: CoreOwnedArrayProvider> {
+#[allow(private_bounds)]
+pub struct Array<P: CoreArrayProviderInner> {
contents: *mut P::Raw,
count: usize,
context: P::Context,
@@ -212,18 +212,19 @@ pub struct Array<P: CoreOwnedArrayProvider> {
unsafe impl<P> Sync for Array<P>
where
- P: CoreOwnedArrayProvider,
+ P: CoreArrayProviderInner,
P::Context: Sync,
{
}
unsafe impl<P> Send for Array<P>
where
- P: CoreOwnedArrayProvider,
+ P: CoreArrayProviderInner,
P::Context: Send,
{
}
-impl<P: CoreOwnedArrayProvider> Array<P> {
+#[allow(private_bounds)]
+impl<P: CoreArrayProviderInner> Array<P> {
pub(crate) unsafe fn new(raw: *mut P::Raw, count: usize, context: P::Context) -> Self {
Self {
contents: raw,
@@ -241,14 +242,10 @@ impl<P: CoreOwnedArrayProvider> Array<P> {
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<P: CoreArrayWrapper + CoreOwnedArrayProvider> Array<P> {
+#[allow(private_bounds)]
+impl<P: CoreArrayProviderInner> Array<P> {
#[inline]
pub fn get(&self, index: usize) -> P::Wrapped<'_> {
unsafe {
@@ -265,7 +262,7 @@ impl<P: CoreArrayWrapper + CoreOwnedArrayProvider> Array<P> {
}
}
-impl<'a, P: CoreArrayWrapper + CoreOwnedArrayProvider> IntoIterator for &'a Array<P> {
+impl<'a, P: CoreArrayProviderInner> IntoIterator for &'a Array<P> {
type Item = P::Wrapped<'a>;
type IntoIter = ArrayIter<'a, P>;
@@ -274,7 +271,7 @@ impl<'a, P: CoreArrayWrapper + CoreOwnedArrayProvider> IntoIterator for &'a Arra
}
}
-impl<P: CoreOwnedArrayProvider> Drop for Array<P> {
+impl<P: CoreArrayProviderInner> Drop for Array<P> {
fn drop(&mut self) {
unsafe {
P::free(self.contents, self.count, &self.context);
@@ -282,7 +279,8 @@ impl<P: CoreOwnedArrayProvider> Drop for Array<P> {
}
}
-pub struct ArrayGuard<P: CoreArrayProvider> {
+#[allow(private_bounds)]
+pub struct ArrayGuard<P: CoreArrayProviderInner> {
contents: *mut P::Raw,
count: usize,
context: P::Context,
@@ -290,18 +288,19 @@ pub struct ArrayGuard<P: CoreArrayProvider> {
unsafe impl<P> Sync for ArrayGuard<P>
where
- P: CoreArrayProvider,
+ P: CoreArrayProviderInner,
P::Context: Sync,
{
}
unsafe impl<P> Send for ArrayGuard<P>
where
- P: CoreArrayProvider,
+ P: CoreArrayProviderInner,
P::Context: Send,
{
}
-impl<P: CoreArrayProvider> ArrayGuard<P> {
+#[allow(private_bounds)]
+impl<P: CoreArrayProviderInner> ArrayGuard<P> {
pub(crate) unsafe fn new(raw: *mut P::Raw, count: usize, context: P::Context) -> Self {
Self {
contents: raw,
@@ -321,7 +320,8 @@ impl<P: CoreArrayProvider> ArrayGuard<P> {
}
}
-impl<P: CoreArrayWrapper + CoreArrayProvider> ArrayGuard<P> {
+#[allow(private_bounds)]
+impl<P: CoreArrayProviderInner> ArrayGuard<P> {
#[inline]
pub fn get(&self, index: usize) -> P::Wrapped<'_> {
unsafe {
@@ -338,7 +338,7 @@ impl<P: CoreArrayWrapper + CoreArrayProvider> ArrayGuard<P> {
}
}
-impl<'a, P: CoreArrayWrapper + CoreArrayProvider> IntoIterator for &'a ArrayGuard<P> {
+impl<'a, P: CoreArrayProviderInner> IntoIterator for &'a ArrayGuard<P> {
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<P> 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<P::Wrapped<'a>> {
@@ -409,10 +410,11 @@ use rayon::prelude::*;
#[cfg(feature = "rayon")]
use rayon::iter::plumbing::*;
+#[allow(private_bounds)]
#[cfg(feature = "rayon")]
impl<P> Array<P>
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 8b4ebb87..d12c33c5 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 17fd5958..f9ece043 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 580d5a21..1e45db8b 100644
--- a/rust/src/section.rs
+++ b/rust/src/section.rs
@@ -174,17 +174,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 6ba2fbad..4c06a7ba 100644
--- a/rust/src/segment.rs
+++ b/rust/src/segment.rs
@@ -204,17 +204,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 96830ca5..f4098d66 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -164,18 +164,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 edb93b47..f022fd3f 100644
--- a/rust/src/symbol.rs
+++ b/rust/src/symbol.rs
@@ -329,17 +329,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 2b300444..750ca46c 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -1439,17 +1439,13 @@ impl NamedTypedVariable {
impl CoreArrayProvider for NamedTypedVariable {
type Raw = BNVariableNameAndType;
type Context = ();
+ type Wrapped<'a> = ManuallyDrop<NamedTypedVariable>;
}
-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<NamedTypedVariable>;
-
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
ManuallyDrop::new(NamedTypedVariable {
var: raw.var,
@@ -2406,16 +2402,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)
}
@@ -2448,16 +2440,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)
}
@@ -2494,16 +2482,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)
}
@@ -2573,17 +2557,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) }
}
@@ -2653,16 +2633,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)
}