From a651dd81ff72d5155b122ce99e9252d6e714cc1e Mon Sep 17 00:00:00 2001 From: rose <47357290+rose4096@users.noreply.github.com> Date: Wed, 22 Jun 2022 13:37:21 -0400 Subject: Rust API: Change instruction_text to use Vec<> --- rust/src/disassembly.rs | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'rust/src/disassembly.rs') diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index ff00e8d0..ab8f91f9 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -192,25 +192,6 @@ impl Clone for InstructionTextToken { // } // } -impl CoreArrayProvider for InstructionTextToken { - type Raw = BNInstructionTextToken; - type Context = (); -} - -unsafe impl CoreOwnedArrayProvider for InstructionTextToken { - unsafe fn free(raw: *mut BNInstructionTextToken, count: usize, _context: &()) { - BNFreeInstructionText(raw, count); - } -} - -unsafe impl<'a> CoreArrayWrapper<'a> for InstructionTextToken { - type Wrapped = Guard<'a, InstructionTextToken>; - - unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { - Guard::new(InstructionTextToken::from_raw(raw), _context) - } -} - pub struct DisassemblyTextLine(pub(crate) BNDisassemblyTextLine); impl DisassemblyTextLine { @@ -235,8 +216,13 @@ impl DisassemblyTextLine { self.0.tagCount } - pub fn tokens(&self) -> ArrayGuard { - unsafe { ArrayGuard::new(self.0.tokens, self.0.count, ()) } + pub fn tokens(&self) -> Vec { + unsafe { + Vec::::from_raw_parts(self.0.tokens, self.0.count, self.0.count) + .iter() + .map(|x| InstructionTextToken::from_raw(x)) + .collect() + } } } @@ -267,7 +253,7 @@ impl From> for DisassemblyTextLine { tokens.shrink_to_fit(); assert!(tokens.len() == tokens.capacity()); - // let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nighly feature + // TODO: let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nightly feature let tokens_pointer = tokens.as_mut_ptr(); let tokens_len = tokens.len(); mem::forget(tokens); -- cgit v1.3.1