Skip to content

Commit 562fbfa

Browse files
committed
remove unnecessary transmutions
1 parent 58673b2 commit 562fbfa

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

rust/src/binaryview.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ pub trait BinaryViewExt: BinaryViewBase {
574574
}
575575
}
576576

577-
fn define_auto_data_var(&self, dv: Ref<DataVariable>) {
577+
fn define_auto_data_var(&self, dv: &DataVariable) {
578578
unsafe {
579579
BNDefineDataVariable(
580580
self.as_ref().handle,
@@ -585,7 +585,7 @@ pub trait BinaryViewExt: BinaryViewBase {
585585
}
586586

587587
/// You likely would also like to call [`Self::define_user_symbol`] to bind this data variable with a name
588-
fn define_user_data_var(&self, dv: Ref<DataVariable>) {
588+
fn define_user_data_var(&self, dv: &DataVariable) {
589589
unsafe {
590590
BNDefineUserDataVariable(
591591
self.as_ref().handle,

rust/src/rc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub unsafe trait RefCountable: ToOwned<Owned = Ref<Self>> + Sized {
4343
// Represents an 'owned' reference tracked by the core
4444
// that we are responsible for cleaning up once we're
4545
// done with the encapsulated value.
46-
#[repr(transparent)]
4746
pub struct Ref<T: RefCountable> {
4847
contents: T,
4948
}

rust/src/types.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub type MemberScope = BNMemberScope;
5757
// Confidence
5858

5959
/// Compatible with the `BNType*WithConfidence` types
60-
#[repr(C)]
6160
pub struct Conf<T> {
6261
pub contents: T,
6362
pub confidence: u8,
@@ -2487,9 +2486,8 @@ impl NameAndType {
24872486
unsafe { mem::transmute::<_, &Type>(&self.0.type_) }
24882487
}
24892488

2490-
pub fn type_with_confidence(&self) -> &Conf<Type> {
2491-
// the struct BNNameAndType contains a Conf inside of it, so this is safe
2492-
unsafe { mem::transmute::<_, &Conf<Type>>(&self.0.type_) }
2489+
pub fn type_with_confidence(&self) -> Conf<&Type> {
2490+
Conf::new(self.t(), self.0.typeConfidence)
24932491
}
24942492
}
24952493

@@ -2545,11 +2543,11 @@ pub struct DataVariable(pub(crate) BNDataVariable);
25452543

25462544
// impl DataVariable {
25472545
// pub(crate) fn from_raw(var: &BNDataVariable) -> Self {
2548-
// Self {
2549-
// address: var.address,
2550-
// t: Conf::new(unsafe { Type::ref_from_raw(var.type_) }, var.typeConfidence),
2551-
// auto_discovered: var.autoDiscovered,
2552-
// }
2546+
// let var = DataVariable(*var);
2547+
// Self(BNDataVariable {
2548+
// type_: unsafe { Ref::into_raw(var.t().to_owned()).handle },
2549+
// ..var.0
2550+
// })
25532551
// }
25542552
// }
25552553

@@ -2558,18 +2556,16 @@ impl DataVariable {
25582556
self.0.address
25592557
}
25602558

2561-
pub fn auto_discovered(&self) -> &bool {
2562-
unsafe { mem::transmute(&self.0.autoDiscovered) }
2559+
pub fn auto_discovered(&self) -> bool {
2560+
self.0.autoDiscovered
25632561
}
25642562

25652563
pub fn t(&self) -> &Type {
25662564
unsafe { mem::transmute(&self.0.type_) }
25672565
}
25682566

2569-
pub fn type_with_confidence(&self) -> Conf<Ref<Type>> {
2570-
// if it was not for the `autoDiscovered: bool` between `type_` and
2571-
// `typeConfidence` this could have being a reference, like NameAndType
2572-
Conf::new(self.t().to_owned(), self.0.typeConfidence)
2567+
pub fn type_with_confidence(&self) -> Conf<&Type> {
2568+
Conf::new(self.t(), self.0.typeConfidence)
25732569
}
25742570

25752571
pub fn symbol(&self, bv: &BinaryView) -> Option<Ref<Symbol>> {

0 commit comments

Comments
 (0)