Skip to content

Commit c68f8d4

Browse files
committed
[Rust API] Add BinaryViewExt::{tags_all_scopes, tag_types, tags_by_type}
1 parent 56b2398 commit c68f8d4

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

rust/src/binary_view.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::segment::{Segment, SegmentBuilder};
5454
use crate::settings::Settings;
5555
use crate::string::*;
5656
use crate::symbol::{Symbol, SymbolType};
57-
use crate::tags::{Tag, TagType};
57+
use crate::tags::{Tag, TagReference, TagType};
5858
use crate::types::{
5959
NamedTypeReference, QualifiedName, QualifiedNameAndType, QualifiedNameTypeAndId, Type,
6060
TypeArchive, TypeArchiveId, TypeContainer, TypeLibrary,
@@ -1646,6 +1646,34 @@ pub trait BinaryViewExt: BinaryViewBase {
16461646
}
16471647
}
16481648

1649+
/// Get all tags in all scopes
1650+
fn tags_all_scopes(&self) -> Array<TagReference> {
1651+
let mut count = 0;
1652+
unsafe {
1653+
let tag_references = BNGetAllTagReferences(self.as_ref().handle, &mut count);
1654+
Array::new(tag_references, count, ())
1655+
}
1656+
}
1657+
1658+
/// Get all tag types present for the view
1659+
fn tag_types(&self) -> Array<TagType> {
1660+
let mut count = 0;
1661+
unsafe {
1662+
let tag_types_raw = BNGetTagTypes(self.as_ref().handle, &mut count);
1663+
Array::new(tag_types_raw, count, ())
1664+
}
1665+
}
1666+
1667+
// Get all tags of a specific type
1668+
fn tags_by_type(&self, tag_type: &TagType) -> Array<TagReference> {
1669+
let mut count = 0;
1670+
unsafe {
1671+
let tag_references =
1672+
BNGetAllTagReferencesOfType(self.as_ref().handle, tag_type.handle, &mut count);
1673+
Array::new(tag_references, count, ())
1674+
}
1675+
}
1676+
16491677
/// Get a tag by its id.
16501678
///
16511679
/// Note this does not tell you anything about where it is used.

rust/src/tags.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,28 @@ pub struct TagType {
128128
pub(crate) handle: *mut BNTagType,
129129
}
130130

131+
impl CoreArrayProvider for TagType {
132+
type Raw = *mut BNTagType;
133+
type Context = ();
134+
type Wrapped<'a> = Guard<'a, Self>;
135+
}
136+
137+
unsafe impl CoreArrayProviderInner for TagType {
138+
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
139+
BNFreeTagTypeList(raw, count)
140+
}
141+
142+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
143+
Guard::new(Self::from_raw(*raw), context)
144+
}
145+
}
146+
131147
impl TagType {
148+
pub(crate) unsafe fn from_raw(handle: *mut BNTagType) -> Self {
149+
debug_assert!(!handle.is_null());
150+
Self { handle }
151+
}
152+
132153
pub(crate) unsafe fn ref_from_raw(handle: *mut BNTagType) -> Ref<Self> {
133154
debug_assert!(!handle.is_null());
134155
Ref::new(Self { handle })

0 commit comments

Comments
 (0)