Skip to content

Commit f3c1a3c

Browse files
committed
add guard to array with unbound return types
1 parent 37b5146 commit f3c1a3c

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

rust/src/custombinaryview.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,10 @@ unsafe impl CoreOwnedArrayProvider for BinaryViewType {
298298
}
299299

300300
unsafe impl CoreArrayWrapper for BinaryViewType {
301-
// TODO there is nothing blocking the returned value from out-living the
302-
// array, change it to &_ or Guard?
303-
type Wrapped<'a> = BinaryViewType;
301+
type Wrapped<'a> = Guard<'a, BinaryViewType>;
304302

305303
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
306-
BinaryViewType(*raw)
304+
Guard::new(BinaryViewType(*raw), &())
307305
}
308306
}
309307

rust/src/downloadprovider.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::rc::{
2-
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable,
2+
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable,
33
};
44
use crate::settings::Settings;
55
use crate::string::{BnStrCompatible, BnString};
@@ -72,12 +72,10 @@ unsafe impl CoreOwnedArrayProvider for DownloadProvider {
7272
}
7373

7474
unsafe impl CoreArrayWrapper for DownloadProvider {
75-
// TODO there is nothing blocking the returned value from out-living the
76-
// array, change it to &_ or Guard?
77-
type Wrapped<'a> = DownloadProvider;
75+
type Wrapped<'a> = Guard<'a, DownloadProvider>;
7876

7977
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
80-
DownloadProvider::from_raw(*raw)
78+
Guard::new(DownloadProvider::from_raw(*raw), &())
8179
}
8280
}
8381

rust/src/references.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::architecture::CoreArchitecture;
22
use crate::function::Function;
3-
use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref};
3+
use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref};
44
use binaryninjacore_sys::{BNFreeCodeReferences, BNFreeDataReferences, BNReferenceSource};
55
use std::mem::ManuallyDrop;
66

@@ -65,12 +65,10 @@ unsafe impl CoreOwnedArrayProvider for CodeReference {
6565
}
6666

6767
unsafe impl CoreArrayWrapper for CodeReference {
68-
// TODO there is nothing blocking the returned value from out-living the
69-
// array, change it to Guard?
70-
type Wrapped<'a> = CodeReference;
68+
type Wrapped<'a> = Guard<'a, CodeReference>;
7169

7270
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
73-
CodeReference::new(raw)
71+
Guard::new(CodeReference::new(raw), &())
7472
}
7573
}
7674

rust/src/relocation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::rc::Guard;
12
use crate::string::BnStrCompatible;
23
use crate::{
34
architecture::{Architecture, CoreArchitecture},
@@ -228,11 +229,9 @@ unsafe impl CoreOwnedArrayProvider for Relocation {
228229
}
229230

230231
unsafe impl CoreArrayWrapper for Relocation {
231-
// TODO there is nothing blocking the returned value from out-living the
232-
// array, change it to &_ or Guard?
233-
type Wrapped<'a> = Relocation;
232+
type Wrapped<'a> = Guard<'a, Relocation>;
234233
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
235-
Relocation(*raw)
234+
Guard::new(Relocation(*raw), &())
236235
}
237236
}
238237

rust/src/types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,6 @@ unsafe impl<S: BnStrCompatible> CoreArrayWrapper for NameAndType<S> {
25012501
type Wrapped<'a> = &'a NameAndType<S> where S: 'a;
25022502

25032503
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
2504-
// TODO this is not always valid, because the type is not transparent
25052504
mem::transmute(raw)
25062505
}
25072506
}
@@ -2549,7 +2548,6 @@ unsafe impl CoreArrayWrapper for DataVariable {
25492548
type Wrapped<'a> = &'a DataVariable;
25502549

25512550
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
2552-
// TODO this is not always valid, because the type is not transparent
25532551
mem::transmute(raw)
25542552
}
25552553
}

0 commit comments

Comments
 (0)