@@ -2454,7 +2454,7 @@ unsafe impl<'a> CoreArrayWrapper<'a> for QualifiedNameTypeAndId {
24542454pub struct NameAndType ( pub ( crate ) BNNameAndType ) ;
24552455
24562456impl NameAndType {
2457- pub ( crate ) fn from_raw ( raw : & BNNameAndType ) -> Self {
2457+ pub ( crate ) fn from_raw ( raw : & BNNameAndType ) -> Ref < Self > {
24582458 Self :: new (
24592459 raw_to_string ( raw. name ) . unwrap ( ) ,
24602460 unsafe { & Type :: ref_from_raw ( raw. type_ ) } ,
@@ -2464,12 +2464,14 @@ impl NameAndType {
24642464}
24652465
24662466impl NameAndType {
2467- pub fn new < S : BnStrCompatible > ( name : S , t : & Ref < Type > , confidence : u8 ) -> Self {
2468- Self ( BNNameAndType {
2469- name : unsafe { BNAllocString ( name. into_bytes_with_nul ( ) . as_ref ( ) . as_ptr ( ) as * mut _ ) } ,
2470- type_ : unsafe { Ref :: into_raw ( t. to_owned ( ) ) . handle } ,
2471- typeConfidence : confidence,
2472- } )
2467+ pub fn new < S : BnStrCompatible > ( name : S , t : & Type , confidence : u8 ) -> Ref < Self > {
2468+ unsafe {
2469+ Ref :: new ( Self ( BNNameAndType {
2470+ name : BNAllocString ( name. into_bytes_with_nul ( ) . as_ref ( ) . as_ptr ( ) as * mut _ ) ,
2471+ type_ : Ref :: into_raw ( t. to_owned ( ) ) . handle ,
2472+ typeConfidence : confidence,
2473+ } ) )
2474+ }
24732475 }
24742476
24752477 pub ( crate ) fn into_raw ( self ) -> BNNameAndType {
@@ -2491,11 +2493,27 @@ impl NameAndType {
24912493 }
24922494}
24932495
2494- impl Drop for NameAndType {
2495- fn drop ( & mut self ) {
2496+ impl ToOwned for NameAndType {
2497+ type Owned = Ref < Self > ;
2498+
2499+ fn to_owned ( & self ) -> Self :: Owned {
2500+ unsafe { RefCountable :: inc_ref ( self ) }
2501+ }
2502+ }
2503+
2504+ unsafe impl RefCountable for NameAndType {
2505+ unsafe fn inc_ref ( handle : & Self ) -> Ref < Self > {
2506+ Self :: new (
2507+ CStr :: from_ptr ( handle. 0 . name ) ,
2508+ handle. t ( ) ,
2509+ handle. type_with_confidence ( ) . confidence ,
2510+ )
2511+ }
2512+
2513+ unsafe fn dec_ref ( handle : & Self ) {
24962514 unsafe {
2497- BNFreeString ( self . 0 . name ) ;
2498- BNFreeType ( self . 0 . type_ ) ;
2515+ BNFreeString ( handle . 0 . name ) ;
2516+ RefCountable :: dec_ref ( handle . t ( ) ) ;
24992517 }
25002518 }
25012519}
@@ -2559,6 +2577,29 @@ impl DataVariable {
25592577 }
25602578}
25612579
2580+ impl ToOwned for DataVariable {
2581+ type Owned = Ref < Self > ;
2582+
2583+ fn to_owned ( & self ) -> Self :: Owned {
2584+ unsafe { RefCountable :: inc_ref ( self ) }
2585+ }
2586+ }
2587+
2588+ unsafe impl RefCountable for DataVariable {
2589+ unsafe fn inc_ref ( handle : & Self ) -> Ref < Self > {
2590+ unsafe {
2591+ Ref :: new ( Self ( BNDataVariable {
2592+ type_ : Ref :: into_raw ( handle. t ( ) . to_owned ( ) ) . handle ,
2593+ ..handle. 0
2594+ } ) )
2595+ }
2596+ }
2597+
2598+ unsafe fn dec_ref ( handle : & Self ) {
2599+ unsafe { BNFreeType ( handle. 0 . type_ ) }
2600+ }
2601+ }
2602+
25622603impl CoreArrayProvider for DataVariable {
25632604 type Raw = BNDataVariable ;
25642605 type Context = ( ) ;
0 commit comments