summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2024-04-16 17:03:20 -0300
committerRubens Brandao <git@rubens.io>2024-04-16 17:03:20 -0300
commitf3c1a3cb3cbdd25d5f556d1ab770f8cbc29fd567 (patch)
tree71a6f2e8df93f7ef08bda08caca3a637588cc919 /rust
parent37b51462dcf26dc40ac5d7e82acdfd4cbe754157 (diff)
add guard to array with unbound return types
Diffstat (limited to 'rust')
-rw-r--r--rust/src/custombinaryview.rs6
-rw-r--r--rust/src/downloadprovider.rs8
-rw-r--r--rust/src/references.rs8
-rw-r--r--rust/src/relocation.rs7
-rw-r--r--rust/src/types.rs2
5 files changed, 11 insertions, 20 deletions
diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs
index c69bad39..898102d6 100644
--- a/rust/src/custombinaryview.rs
+++ b/rust/src/custombinaryview.rs
@@ -298,12 +298,10 @@ unsafe impl CoreOwnedArrayProvider for BinaryViewType {
}
unsafe impl CoreArrayWrapper for BinaryViewType {
- // TODO there is nothing blocking the returned value from out-living the
- // array, change it to &_ or Guard?
- type Wrapped<'a> = BinaryViewType;
+ type Wrapped<'a> = Guard<'a, BinaryViewType>;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
- BinaryViewType(*raw)
+ Guard::new(BinaryViewType(*raw), &())
}
}
diff --git a/rust/src/downloadprovider.rs b/rust/src/downloadprovider.rs
index cc243722..8334e0ce 100644
--- a/rust/src/downloadprovider.rs
+++ b/rust/src/downloadprovider.rs
@@ -1,5 +1,5 @@
use crate::rc::{
- Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable,
+ Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable,
};
use crate::settings::Settings;
use crate::string::{BnStrCompatible, BnString};
@@ -72,12 +72,10 @@ unsafe impl CoreOwnedArrayProvider for DownloadProvider {
}
unsafe impl CoreArrayWrapper for DownloadProvider {
- // TODO there is nothing blocking the returned value from out-living the
- // array, change it to &_ or Guard?
- type Wrapped<'a> = DownloadProvider;
+ type Wrapped<'a> = Guard<'a, DownloadProvider>;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
- DownloadProvider::from_raw(*raw)
+ Guard::new(DownloadProvider::from_raw(*raw), &())
}
}
diff --git a/rust/src/references.rs b/rust/src/references.rs
index a30f3f5e..8b4ebb87 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, Ref};
+use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref};
use binaryninjacore_sys::{BNFreeCodeReferences, BNFreeDataReferences, BNReferenceSource};
use std::mem::ManuallyDrop;
@@ -65,12 +65,10 @@ unsafe impl CoreOwnedArrayProvider for CodeReference {
}
unsafe impl CoreArrayWrapper for CodeReference {
- // TODO there is nothing blocking the returned value from out-living the
- // array, change it to Guard?
- type Wrapped<'a> = CodeReference;
+ type Wrapped<'a> = Guard<'a, CodeReference>;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
- CodeReference::new(raw)
+ Guard::new(CodeReference::new(raw), &())
}
}
diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs
index 47ec2ac0..455f5a5a 100644
--- a/rust/src/relocation.rs
+++ b/rust/src/relocation.rs
@@ -1,3 +1,4 @@
+use crate::rc::Guard;
use crate::string::BnStrCompatible;
use crate::{
architecture::{Architecture, CoreArchitecture},
@@ -228,11 +229,9 @@ unsafe impl CoreOwnedArrayProvider for Relocation {
}
unsafe impl CoreArrayWrapper for Relocation {
- // TODO there is nothing blocking the returned value from out-living the
- // array, change it to &_ or Guard?
- type Wrapped<'a> = Relocation;
+ type Wrapped<'a> = Guard<'a, Relocation>;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
- Relocation(*raw)
+ Guard::new(Relocation(*raw), &())
}
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 43d48b3f..280d50fd 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -2501,7 +2501,6 @@ unsafe impl<S: BnStrCompatible> CoreArrayWrapper for NameAndType<S> {
type Wrapped<'a> = &'a NameAndType<S> where S: 'a;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
- // TODO this is not always valid, because the type is not transparent
mem::transmute(raw)
}
}
@@ -2549,7 +2548,6 @@ 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> {
- // TODO this is not always valid, because the type is not transparent
mem::transmute(raw)
}
}