summaryrefslogtreecommitdiff
path: root/rust/src
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
parent58673b20ef858ae5d4d7b1ff0dec1460a0f36e5f (diff)
remove unnecessary transmutions
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/binaryview.rs4
-rw-r--r--rust/src/rc.rs1
-rw-r--r--rust/src/types.rs26
3 files changed, 13 insertions, 18 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs
index ecf75384..33fd9881 100644
--- a/rust/src/binaryview.rs
+++ b/rust/src/binaryview.rs
@@ -574,7 +574,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn define_auto_data_var(&self, dv: Ref<DataVariable>) {
+ fn define_auto_data_var(&self, dv: &DataVariable) {
unsafe {
BNDefineDataVariable(
self.as_ref().handle,
@@ -585,7 +585,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
/// You likely would also like to call [`Self::define_user_symbol`] to bind this data variable with a name
- fn define_user_data_var(&self, dv: Ref<DataVariable>) {
+ fn define_user_data_var(&self, dv: &DataVariable) {
unsafe {
BNDefineUserDataVariable(
self.as_ref().handle,
diff --git a/rust/src/rc.rs b/rust/src/rc.rs
index 91e51565..cdcae179 100644
--- a/rust/src/rc.rs
+++ b/rust/src/rc.rs
@@ -43,7 +43,6 @@ pub unsafe trait RefCountable: ToOwned<Owned = Ref<Self>> + Sized {
// Represents an 'owned' reference tracked by the core
// that we are responsible for cleaning up once we're
// done with the encapsulated value.
-#[repr(transparent)]
pub struct Ref<T: RefCountable> {
contents: T,
}
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>> {