diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index db887e4f0..0e1349e67 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -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); @@ -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(); @@ -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)); } } } diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index ac3983341..d53faef3a 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -390,7 +390,7 @@ impl DebugInfo { let result: Vec> = unsafe { slice::from_raw_parts_mut(debug_types_ptr, count) .iter() - .map(NameAndType::from_raw) + .map(|x| NameAndType::from_raw(x).to_owned()) .collect() }; @@ -405,7 +405,7 @@ impl DebugInfo { let result: Vec> = unsafe { slice::from_raw_parts_mut(debug_types_ptr, count) .iter() - .map(NameAndType::from_raw) + .map(|x| NameAndType::from_raw(x).to_owned()) .collect() }; diff --git a/rust/src/types.rs b/rust/src/types.rs index dae8a6cc1..75c8fb363 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -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::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 ) } } @@ -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() @@ -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, ) } @@ -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) } } }