Skip to content

Commit e2905d9

Browse files
committed
Make array deallocation approach recursive for multi-dimensional unwrapping.
1 parent f859feb commit e2905d9

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

bindings/LDK/Bindings.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ public class Bindings {
14981498
var array = [[LDKRouteHop]]()
14991499
for index in 0..<Int(nativeType.datalen) {
15001500
let currentEntry = nativeType.data[index]
1501-
let convertedEntry = LDKCVec_RouteHopZ_to_array(nativeType: currentEntry)
1501+
let convertedEntry = LDKCVec_RouteHopZ_to_array(nativeType: currentEntry, deallocate: deallocate)
15021502
array.append(convertedEntry)
15031503
}
15041504

@@ -1582,7 +1582,7 @@ public class Bindings {
15821582
var array = [[UInt8]]()
15831583
for index in 0..<Int(nativeType.datalen) {
15841584
let currentEntry = nativeType.data[index]
1585-
let convertedEntry = LDKCVec_u8Z_to_array(nativeType: currentEntry)
1585+
let convertedEntry = LDKCVec_u8Z_to_array(nativeType: currentEntry, deallocate: deallocate)
15861586
array.append(convertedEntry)
15871587
}
15881588

@@ -3046,7 +3046,7 @@ public class Bindings {
30463046
var array = [[UInt8]]()
30473047
for index in 0..<Int(nativeType.datalen) {
30483048
let currentEntry = nativeType.data[index]
3049-
let convertedEntry = LDKTransaction_to_array(nativeType: currentEntry)
3049+
let convertedEntry = LDKTransaction_to_array(nativeType: currentEntry, deallocate: deallocate)
30503050
array.append(convertedEntry)
30513051
}
30523052

src/conversion_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ 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:
337+
if (rust_return_type.startswith('LDKCVec_') or rust_return_type == 'LDKTransaction') and is_raw_property_getter:
338338
return_suffix = ', deallocate: false)'
339339
elif return_type.swift_raw_type.startswith('(UInt8'):
340340
# TODO: get array length

src/generators/option_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ 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_'):
346+
if current_return_type.rust_obj.startswith('LDKCVec_') or current_return_type.rust_obj == 'LDKTransaction':
347347
return_type_wrapper_suffix = ', deallocate: false)'
348348
current_replacement = current_replacement.replace('return self.cOpaqueStruct!.varName', f'return {return_type_wrapper_prefix}self.cOpaqueStruct!.varName{return_type_wrapper_suffix}')
349349
elif current_return_type.swift_raw_type.startswith('(UInt8'):

src/generators/util_generators/vector_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def generate_vector(self, vector_name, vector_type_details):
4040
swift_primitive = deepest_iteratee.name
4141
if dimensions > 1:
4242
conversion_call = f'let convertedEntry = {shallowmost_iteratee.name}_to_array(nativeType: currentEntry)'
43+
if shallowmost_iteratee.name.startswith('LDKCVec_') or shallowmost_iteratee.name == 'LDKTransaction':
44+
conversion_call = f'let convertedEntry = {shallowmost_iteratee.name}_to_array(nativeType: currentEntry, deallocate: deallocate)'
4345
pointerTypeName = shallowmost_iteratee.name
4446
subdimension_prefix = ''
4547
subdimension_suffix = '.cOpaqueStruct!'

0 commit comments

Comments
 (0)