Skip to content

Commit

Permalink
rust: account for changes to NameAndType bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rssor committed May 1, 2024
1 parent 8817116 commit 87b1470
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
6 changes: 3 additions & 3 deletions rust/src/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl Intrinsic for crate::architecture::CoreIntrinsic {

let ret = slice::from_raw_parts_mut(inputs, count)
.iter()
.map(NameAndType::from_raw)
.map(|x| NameAndType::from_raw(x).to_owned())
.collect();

BNFreeNameAndTypeList(inputs, count);
Expand Down Expand Up @@ -2419,7 +2419,7 @@ where
};

let inputs = intrinsic.inputs();
let mut res: Box<[_]> = inputs.into_iter().map(|input| input.into_raw()).collect();
let mut res: Box<[_]> = inputs.into_iter().map(|input| unsafe { Ref::into_raw(input) }.0).collect();

unsafe {
*count = res.len();
Expand All @@ -2443,7 +2443,7 @@ where
unsafe {
let name_and_types = Box::from_raw(ptr::slice_from_raw_parts_mut(nt, count));
for nt in name_and_types.into_iter() {
BnString::from_raw(nt.name);
Ref::new(NameAndType::from_raw(nt));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl DebugInfo {
let result: Vec<Ref<NameAndType>> = unsafe {
slice::from_raw_parts_mut(debug_types_ptr, count)
.iter()
.map(NameAndType::from_raw)
.map(|x| NameAndType::from_raw(x).to_owned())
.collect()
};

Expand All @@ -405,7 +405,7 @@ impl DebugInfo {
let result: Vec<Ref<NameAndType>> = unsafe {
slice::from_raw_parts_mut(debug_types_ptr, count)
.iter()
.map(NameAndType::from_raw)
.map(|x| NameAndType::from_raw(x).to_owned())
.collect()
};

Expand Down
19 changes: 5 additions & 14 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2440,16 +2440,11 @@ unsafe impl CoreArrayWrapper for QualifiedNameTypeAndId {
//////////////////////////
// NameAndType

#[repr(transparent)]
pub struct NameAndType(pub(crate) BNNameAndType);

impl NameAndType {
pub(crate) fn from_raw(raw: &BNNameAndType) -> Ref<Self> {
Self::new(
raw_to_string(raw.name).unwrap(),
unsafe { &Type::ref_from_raw(raw.type_) },
raw.typeConfidence,
)
pub(crate) unsafe fn from_raw(raw: &BNNameAndType) -> Self {
Self ( *raw )
}
}

Expand All @@ -2464,10 +2459,6 @@ impl NameAndType {
}
}

pub(crate) fn into_raw(self) -> BNNameAndType {
self.0
}

pub fn name(&self) -> &str {
let c_str = unsafe { CStr::from_ptr(self.0.name) };
c_str.to_str().unwrap()
Expand Down Expand Up @@ -2495,7 +2486,7 @@ unsafe impl RefCountable for NameAndType {
Self::new(
CStr::from_ptr(handle.0.name),
handle.t(),
handle.type_with_confidence().confidence,
handle.0.typeConfidence,
)
}

Expand All @@ -2519,10 +2510,10 @@ unsafe impl CoreOwnedArrayProvider for NameAndType {
}

unsafe impl CoreArrayWrapper for NameAndType {
type Wrapped<'a> = &'a NameAndType;
type Wrapped<'a> = Guard<'a, NameAndType>;

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
mem::transmute(raw)
unsafe { Guard::new(NameAndType::from_raw(raw), raw) }
}
}

Expand Down

0 comments on commit 87b1470

Please sign in to comment.