summaryrefslogtreecommitdiff
path: root/rust/src/disassembly.rs
diff options
context:
space:
mode:
authorrose <47357290+rose4096@users.noreply.github.com>2022-06-24 16:22:11 -0400
committerrose <47357290+rose4096@users.noreply.github.com>2022-06-24 16:22:11 -0400
commitaad1e9b9861ece0afa6d731d98e5c5c4ed377753 (patch)
tree3ae0ac9784fb2df7a3b64e788c9252fe06509aa4 /rust/src/disassembly.rs
parent45ff2fcd62335ed5c505af00133e4bab3c525229 (diff)
Rust API: Change tokens to use slice::from_raw_parts
Diffstat (limited to 'rust/src/disassembly.rs')
-rw-r--r--rust/src/disassembly.rs17
1 files changed, 5 insertions, 12 deletions
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs
index ab8f91f9..d1430888 100644
--- a/rust/src/disassembly.rs
+++ b/rust/src/disassembly.rs
@@ -24,6 +24,7 @@ use crate::rc::*;
use std::convert::From;
use std::mem;
use std::ptr;
+use std::ptr::slice_from_raw_parts;
pub type InstructionTextTokenType = BNInstructionTextTokenType;
pub type InstructionTextTokenContext = BNInstructionTextTokenContext;
@@ -218,9 +219,9 @@ impl DisassemblyTextLine {
pub fn tokens(&self) -> Vec<InstructionTextToken> {
unsafe {
- Vec::<BNInstructionTextToken>::from_raw_parts(self.0.tokens, self.0.count, self.0.count)
+ std::slice::from_raw_parts::<BNInstructionTextToken>(self.0.tokens, self.0.count)
.iter()
- .map(|x| InstructionTextToken::from_raw(x))
+ .map(|&x| InstructionTextToken::from_raw(&x))
.collect()
}
}
@@ -228,22 +229,14 @@ impl DisassemblyTextLine {
impl std::fmt::Display for DisassemblyTextLine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let tokens: Vec<InstructionTextToken> =
- unsafe { Vec::from_raw_parts(self.0.tokens as *mut _, self.0.count, self.0.count) };
-
- for token in &tokens {
- let token_string = unsafe { BnString::from_raw(token.0.text) };
- let result = write!(f, "{}", token_string);
- token_string.into_raw();
+ for token in self.tokens() {
+ let result = write!(f, "{}", token.text());
if result.is_err() {
- mem::forget(tokens);
return result;
}
}
- mem::forget(tokens);
-
Ok(())
}
}