Skip to content

Commit cd58f77

Browse files
committed
fix binary option array processing approach
1 parent 556d959 commit cd58f77

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/generators/option_generator.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
7979
# TODO: make some/none-ordering-agnostic!
8080
some_variant_name = option_value_details[0].tag_value # var_name
8181
none_variant_name = option_value_details[1].var_name
82-
field_details = option_value_details[0].fields[0]
82+
constructor_argument_types = option_value_details[0].fields
83+
field_details = constructor_argument_types[0]
8384

8485
assert field_details.var_name == 'some'
8586

8687
raw_rust_type = field_details.rust_obj
8788
swift_type = field_details.swift_type
8889
nullable_swift_type = swift_type + '?'
8990

91+
92+
array_parsing_prep = ''
93+
array_return_line = None
94+
9095
native_conversion_prefix = ''
9196
native_conversion_suffix = ''
9297
swift_local_conversion_prefix = ''
@@ -97,6 +102,23 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
97102
native_conversion_suffix = '.cOpaqueStruct!'
98103
swift_local_conversion_prefix = f'{swift_type}(pointer: '
99104
swift_local_conversion_suffix = ')'
105+
elif swift_type.startswith('['):
106+
prepared_arguments = ConversionHelper.prepare_swift_to_native_arguments(constructor_argument_types, array_unwrapping_preparation_only=True)
107+
array_parsing_prep = f"""
108+
{prepared_arguments['native_call_prep'].replace('some', 'value')}
109+
let somevalue = Bindings.new_{raw_rust_type}Wrapper(array: valueUnwrapped)
110+
// try! self.addAnchor(anchor: somevalue)
111+
somevalue.dangle()
112+
"""
113+
native_conversion_prefix = 'some'
114+
native_conversion_suffix = '.cOpaqueStruct!'
115+
116+
value_return_wrappers = ConversionHelper.prepare_return_value(field_details, is_clone_method=False, is_raw_property_getter=True)
117+
current_swift_return_type = value_return_wrappers['swift_type']
118+
current_replacement = 'return ' + value_return_wrappers["prefix"] + 'self.cOpaqueStruct!.varName' + value_return_wrappers["suffix"]
119+
current_replacement = current_replacement.replace('self.cOpaqueStruct!.varName', f'self.cOpaqueStruct!.{field_details.var_name}')
120+
array_return_line = current_replacement
121+
100122

101123
# DEFAULT CONSTRUCTOR
102124

@@ -106,6 +128,7 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
106128
self.cOpaqueStruct = {struct_name}()
107129
if let value = value {{
108130
self.cOpaqueStruct!.tag = {some_variant_name}
131+
{array_parsing_prep}
109132
self.cOpaqueStruct!.some = {native_conversion_prefix}value{native_conversion_suffix}
110133
}} else {{
111134
self.cOpaqueStruct!.tag = {none_variant_name}
@@ -118,13 +141,18 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
118141
current_replacement = current_replacement.replace('methodName', current_method_name)
119142
current_replacement = current_replacement.replace('swift_arguments', '')
120143
current_replacement = current_replacement.replace('-> Void', '-> ' + nullable_swift_type)
144+
145+
some_return_line = f'''return {swift_local_conversion_prefix}self.cOpaqueStruct!.some{swift_local_conversion_suffix}'''
146+
if array_return_line is not None:
147+
some_return_line = array_return_line
148+
121149
current_replacement = current_replacement.replace('/* NATIVE_CALL_PREP */', f'''
122150
123151
if self.cOpaqueStruct!.tag == {none_variant_name} {{
124152
return nil
125153
}}
126154
if self.cOpaqueStruct!.tag == {some_variant_name} {{
127-
return {swift_local_conversion_prefix}self.cOpaqueStruct!.some{swift_local_conversion_suffix}
155+
{some_return_line}
128156
}}
129157
assert(false, "invalid option enum value")
130158
return nil

src/generators/util_generators/static_method_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def generate_static_methods(self, static_methods):
2424
method_name = 'swift' + swift_method_name
2525

2626
if native_method_name == 'get_route':
27-
continue
27+
# continue
28+
pass
2829

2930
arguments = ConversionHelper.prepare_swift_to_native_arguments(current_method['argument_types'], False)
3031
return_wrappers = ConversionHelper.prepare_return_value(current_method['return_type'], False)

templates/BindingsTemplate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public class Bindings {
380380
}
381381
}
382382

383+
/*
383384
public class func getRoute(our_node_id: [UInt8], network: NetworkGraph, payee: [UInt8], payee_features: InvoiceFeatures, first_hops: [LDKChannelDetails], last_hops: [LDKRouteHint], final_value_msat: UInt64, final_cltv: UInt32, logger: Logger) -> Result_RouteLightningErrorZ {
384385
return withUnsafePointer(to: network.cOpaqueStruct!) { (networkPointer: UnsafePointer<LDKNetworkGraph>) in
385386
var mutableHops = Bindings.new_LDKCVec_ChannelDetailsZWrapper(array: first_hops).cOpaqueStruct!
@@ -388,6 +389,7 @@ public class Bindings {
388389
}
389390
}
390391
}
392+
*/
391393

392394
public class func get_ldk_swift_bindings_version() -> String {
393395
return "/* SWIFT_BINDINGS_VERSION */"

0 commit comments

Comments
 (0)