@@ -6,13 +6,13 @@ use binaryninjacore_sys::*;
6
6
use crate :: basic_block:: BasicBlock ;
7
7
use crate :: binary_view:: BinaryView ;
8
8
use crate :: function:: { Function , NativeBlock } ;
9
- use crate :: rc:: { Array , CoreArrayProvider , CoreArrayProviderInner } ;
9
+ use crate :: rc:: { Array , CoreArrayProvider , CoreArrayProviderInner , Ref , RefCountable } ;
10
10
use crate :: string:: { BnStrCompatible , BnString } ;
11
11
12
12
pub type ScriptingProviderExecuteResult = BNScriptingProviderExecuteResult ;
13
13
pub type ScriptingProviderInputReadyState = BNScriptingProviderInputReadyState ;
14
14
15
- #[ derive( Clone , Copy ) ]
15
+ #[ derive( Clone , Copy , Eq , PartialEq , Hash ) ]
16
16
#[ repr( transparent) ]
17
17
pub struct ScriptingProvider {
18
18
handle : ptr:: NonNull < BNScriptingProvider > ,
@@ -143,16 +143,22 @@ pub struct ScriptingInstance {
143
143
handle : ptr:: NonNull < BNScriptingInstance > ,
144
144
}
145
145
146
- impl Clone for ScriptingInstance {
147
- fn clone ( & self ) -> Self {
148
- let result = unsafe { BNNewScriptingInstanceReference ( self . as_raw ( ) ) } ;
149
- unsafe { Self :: from_raw ( ptr:: NonNull :: new ( result) . unwrap ( ) ) }
146
+ impl ToOwned for ScriptingInstance {
147
+ type Owned = Ref < Self > ;
148
+
149
+ fn to_owned ( & self ) -> Self :: Owned {
150
+ unsafe { Self :: inc_ref ( self ) }
150
151
}
151
152
}
152
153
153
- impl Drop for ScriptingInstance {
154
- fn drop ( & mut self ) {
155
- unsafe { BNFreeScriptingInstance ( self . as_raw ( ) ) }
154
+ unsafe impl RefCountable for ScriptingInstance {
155
+ unsafe fn inc_ref ( handle : & Self ) -> Ref < Self > {
156
+ let result = unsafe { BNNewScriptingInstanceReference ( handle. as_raw ( ) ) } ;
157
+ unsafe { Self :: ref_from_raw ( ptr:: NonNull :: new ( result) . unwrap ( ) ) }
158
+ }
159
+
160
+ unsafe fn dec_ref ( handle : & Self ) {
161
+ unsafe { BNFreeScriptingInstance ( handle. as_raw ( ) ) }
156
162
}
157
163
}
158
164
@@ -161,6 +167,10 @@ impl ScriptingInstance {
161
167
Self { handle }
162
168
}
163
169
170
+ pub ( crate ) unsafe fn ref_from_raw ( handle : ptr:: NonNull < BNScriptingInstance > ) -> Ref < Self > {
171
+ Ref :: new ( Self { handle } )
172
+ }
173
+
164
174
pub ( crate ) unsafe fn into_raw ( self ) -> * mut BNScriptingInstance {
165
175
mem:: ManuallyDrop :: new ( self ) . handle . as_ptr ( )
166
176
}
0 commit comments