Skip to content

Commit f859feb

Browse files
committed
Make raw property getters not deallocate their underlying objects.
1 parent 9705bca commit f859feb

File tree

7 files changed

+13
-9
lines changed

7 files changed

+13
-9
lines changed

bindings/LDK/options/Event.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Event_write(objPointer)
202202
}
203203

204204
public func getOutput_script() -> [UInt8] {
205-
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.output_script)
205+
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.output_script, deallocate: false)
206206
}
207207

208208
public func getUser_channel_id() -> UInt64 {
@@ -308,7 +308,7 @@ Event_write(objPointer)
308308

309309

310310
public func getOutputs() -> [LDKSpendableOutputDescriptor] {
311-
return Bindings.LDKCVec_SpendableOutputDescriptorZ_to_array(nativeType: self.cOpaqueStruct!.outputs)
311+
return Bindings.LDKCVec_SpendableOutputDescriptorZ_to_array(nativeType: self.cOpaqueStruct!.outputs, deallocate: false)
312312
}
313313

314314

bindings/LDK/options/Fallback.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Fallback_eq(aPointer, bPointer)
139139
}
140140

141141
public func getProgram() -> [UInt8] {
142-
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.program)
142+
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.program, deallocate: false)
143143
}
144144

145145

bindings/LDK/options/PaymentSendFailure.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ public class PaymentSendFailure: NativeTypeWrapper {
4848
if self.cOpaqueStruct?.tag != LDKPaymentSendFailure_PathParameterError {
4949
return nil
5050
}
51-
return Bindings.LDKCVec_CResult_NoneAPIErrorZZ_to_array(nativeType: self.cOpaqueStruct!.path_parameter_error)
51+
return Bindings.LDKCVec_CResult_NoneAPIErrorZZ_to_array(nativeType: self.cOpaqueStruct!.path_parameter_error, deallocate: false)
5252
}
5353

5454
public func getValueAsAllFailedRetrySafe() -> [LDKAPIError]? {
5555
if self.cOpaqueStruct?.tag != LDKPaymentSendFailure_AllFailedRetrySafe {
5656
return nil
5757
}
58-
return Bindings.LDKCVec_APIErrorZ_to_array(nativeType: self.cOpaqueStruct!.all_failed_retry_safe)
58+
return Bindings.LDKCVec_APIErrorZ_to_array(nativeType: self.cOpaqueStruct!.all_failed_retry_safe, deallocate: false)
5959
}
6060

6161
public func getValueAsPartialFailure() -> [LDKCResult_NoneAPIErrorZ]? {
6262
if self.cOpaqueStruct?.tag != LDKPaymentSendFailure_PartialFailure {
6363
return nil
6464
}
65-
return Bindings.LDKCVec_CResult_NoneAPIErrorZZ_to_array(nativeType: self.cOpaqueStruct!.partial_failure)
65+
return Bindings.LDKCVec_CResult_NoneAPIErrorZZ_to_array(nativeType: self.cOpaqueStruct!.partial_failure, deallocate: false)
6666
}
6767

6868

bindings/LDK/structs/TxOut.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TxOut_clone(origPointer)
6666

6767
public func get_script_pubkey() -> [UInt8] {
6868

69-
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.script_pubkey);
69+
return Bindings.LDKCVec_u8Z_to_array(nativeType: self.cOpaqueStruct!.script_pubkey, deallocate: false);
7070
}
7171

7272
public func get_value() -> UInt64 {

src/conversion_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def prepare_native_to_swift_callback_arguments(cls, argument_types):
322322
}
323323

324324
@classmethod
325-
def prepare_return_value(cls, return_type, is_clone_method = False, is_trait_instantiator = False):
325+
def prepare_return_value(cls, return_type, is_clone_method = False, is_trait_instantiator = False, is_raw_property_getter = False):
326326
rust_return_type = return_type.rust_obj
327327
return_prefix = ''
328328
return_suffix = ''
@@ -334,6 +334,8 @@ def prepare_return_value(cls, return_type, is_clone_method = False, is_trait_ins
334334
if rust_return_type is not None and rust_return_type.startswith('LDK') and return_type_string.startswith('['):
335335
return_prefix = f'Bindings.{rust_return_type}_to_array(nativeType: '
336336
return_suffix = ')'
337+
if rust_return_type.startswith('LDKCVec_') and is_raw_property_getter:
338+
return_suffix = ', deallocate: false)'
337339
elif return_type.swift_raw_type.startswith('(UInt8'):
338340
# TODO: get array length
339341
array_length = return_type.arr_len

src/generators/opaque_struct_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def generate_opaque_struct(self, struct_name, struct_details, all_type_details={
166166
for current_field in struct_details.fields:
167167
current_field_name = current_field['name']
168168
current_field_type = current_field['field_details']
169-
value_return_wrappers = ConversionHelper.prepare_return_value(current_field_type)
169+
value_return_wrappers = ConversionHelper.prepare_return_value(current_field_type, is_raw_property_getter=True)
170170
current_swift_return_type = value_return_wrappers['swift_type']
171171
current_method_name = f'get_{current_field_name}'
172172

src/generators/option_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def prepare_return_body(self, type_details):
343343
if current_return_type.rust_obj is not None and current_return_type.rust_obj.startswith('LDK') and current_return_type.swift_type.startswith('['):
344344
return_type_wrapper_prefix = f'Bindings.{current_return_type.rust_obj}_to_array(nativeType: '
345345
return_type_wrapper_suffix = ')'
346+
if current_return_type.rust_obj.startswith('LDKCVec_'):
347+
return_type_wrapper_suffix = ', deallocate: false)'
346348
current_replacement = current_replacement.replace('return self.cOpaqueStruct!.varName', f'return {return_type_wrapper_prefix}self.cOpaqueStruct!.varName{return_type_wrapper_suffix}')
347349
elif current_return_type.swift_raw_type.startswith('(UInt8'):
348350
# TODO: get array length

0 commit comments

Comments
 (0)