summaryrefslogtreecommitdiff
path: root/rust/src/types.rs
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2024-04-17 12:49:43 -0300
committerRubens Brandao <git@rubens.io>2024-04-17 12:49:43 -0300
commit562fbfae8aa17a2f3758710b23ec25e828d16cd6 (patch)
tree0e2b93a4355a8f1815024c73914c1e197bf1d7c3 /rust/src/types.rs
parent58673b20ef858ae5d4d7b1ff0dec1460a0f36e5f (diff)
remove unnecessary transmutions
Diffstat (limited to 'rust/src/types.rs')
-rw-r--r--rust/src/types.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 05cad7e6..9fcd9d45 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -57,7 +57,6 @@ pub type MemberScope = BNMemberScope;
// Confidence
/// Compatible with the `BNType*WithConfidence` types
-#[repr(C)]
pub struct Conf<T> {
pub contents: T,
pub confidence: u8,
@@ -2487,9 +2486,8 @@ impl NameAndType {
unsafe { mem::transmute::<_, &Type>(&self.0.type_) }
}
- pub fn type_with_confidence(&self) -> &Conf<Type> {
- // the struct BNNameAndType contains a Conf inside of it, so this is safe
- unsafe { mem::transmute::<_, &Conf<Type>>(&self.0.type_) }
+ pub fn type_with_confidence(&self) -> Conf<&Type> {
+ Conf::new(self.t(), self.0.typeConfidence)
}
}
@@ -2545,11 +2543,11 @@ pub struct DataVariable(pub(crate) BNDataVariable);
// impl DataVariable {
// pub(crate) fn from_raw(var: &BNDataVariable) -> Self {
-// Self {
-// address: var.address,
-// t: Conf::new(unsafe { Type::ref_from_raw(var.type_) }, var.typeConfidence),
-// auto_discovered: var.autoDiscovered,
-// }
+// let var = DataVariable(*var);
+// Self(BNDataVariable {
+// type_: unsafe { Ref::into_raw(var.t().to_owned()).handle },
+// ..var.0
+// })
// }
// }
@@ -2558,18 +2556,16 @@ impl DataVariable {
self.0.address
}
- pub fn auto_discovered(&self) -> &bool {
- unsafe { mem::transmute(&self.0.autoDiscovered) }
+ pub fn auto_discovered(&self) -> bool {
+ self.0.autoDiscovered
}
pub fn t(&self) -> &Type {
unsafe { mem::transmute(&self.0.type_) }
}
- pub fn type_with_confidence(&self) -> Conf<Ref<Type>> {
- // if it was not for the `autoDiscovered: bool` between `type_` and
- // `typeConfidence` this could have being a reference, like NameAndType
- Conf::new(self.t().to_owned(), self.0.typeConfidence)
+ pub fn type_with_confidence(&self) -> Conf<&Type> {
+ Conf::new(self.t(), self.0.typeConfidence)
}
pub fn symbol(&self, bv: &BinaryView) -> Option<Ref<Symbol>> {