Skip to content

Commit eb19364

Browse files
committed
Don't dangle return values of methods taking references to self if the return type is a Vec.
1 parent 3ec14fd commit eb19364

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

ci/LDKSwift/Tests/LDKSwiftTests/HumanObjectPeerTestInstance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public class HumanObjectPeerTestInstance {
375375
let port = UInt16(i)
376376
let bound = self.tcpSocketHandler!.bind(address: "127.0.0.1", port: port)
377377
if bound {
378-
print("Bound socket to port \(port) on attempt \(i)")
378+
print("Bound socket to port \(port) on attempt \(i-9999)")
379379
self.tcpPort = port
380380
return
381381
}

out/VersionDescriptor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
extension Bindings {
77
public class func getLDKSwiftBindingsSerializationHash() -> String {
8-
return "658748821a6d2592609e6ebecd7bac57a540d82fb1cf75c12814010e6f95488f"
8+
return "aa6f30a3db94ea30b2790da44a24edca61205baa4e9893da31e33a98e7b66c65"
99
}
1010
public class func getLDKSwiftBindingsVersion() -> String {
11-
return "0.0.114-12-g2d08ea22-dirty"
11+
return "0.0.114-18-g3ec14fd1-dirty"
1212
}
1313
public class func getLDKSwiftBindingsCommitHash() -> String {
14-
return "2d08ea22d467b53c885f9a6ae0f3f54e57f49020"
14+
return "3ec14fd17fe15bd5e450b0363369ad88db93288b"
1515
}
1616
}
1717

out/structs/ChainMonitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160

161161

162162
// return value (do some wrapping)
163-
let returnValue = Vec_BalanceZ(cType: nativeCallResult, instantiationContext: "ChainMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
163+
let returnValue = Vec_BalanceZ(cType: nativeCallResult, instantiationContext: "ChainMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
164164

165165

166166
return returnValue

out/structs/ChannelManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362

363363

364364
// return value (do some wrapping)
365-
let returnValue = Vec_RecentPaymentDetailsZ(cType: nativeCallResult, instantiationContext: "ChannelManager.swift::\(#function):\(#line)", anchor: self).getValue()
365+
let returnValue = Vec_RecentPaymentDetailsZ(cType: nativeCallResult, instantiationContext: "ChannelManager.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
366366

367367

368368
return returnValue

out/structs/ChannelMonitor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311

312312

313313
// return value (do some wrapping)
314-
let returnValue = Vec_MonitorEventZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
314+
let returnValue = Vec_MonitorEventZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
315315

316316

317317
return returnValue
@@ -341,7 +341,7 @@
341341

342342

343343
// return value (do some wrapping)
344-
let returnValue = Vec_EventZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
344+
let returnValue = Vec_EventZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
345345

346346

347347
return returnValue
@@ -461,7 +461,7 @@
461461

462462

463463
// return value (do some wrapping)
464-
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
464+
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
465465

466466

467467
return returnValue
@@ -530,7 +530,7 @@
530530

531531

532532
// return value (do some wrapping)
533-
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
533+
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
534534

535535

536536
return returnValue
@@ -599,7 +599,7 @@
599599

600600

601601
// return value (do some wrapping)
602-
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
602+
let returnValue = Vec_TransactionOutputsZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
603603

604604

605605
return returnValue
@@ -683,7 +683,7 @@
683683

684684

685685
// return value (do some wrapping)
686-
let returnValue = Vec_BalanceZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).getValue()
686+
let returnValue = Vec_BalanceZ(cType: nativeCallResult, instantiationContext: "ChannelMonitor.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
687687

688688

689689
return returnValue

out/structs/NodeAnnouncementInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297

298298

299299
// return value (do some wrapping)
300-
let returnValue = Vec_NetAddressZ(cType: nativeCallResult, instantiationContext: "NodeAnnouncementInfo.swift::\(#function):\(#line)", anchor: self).getValue()
300+
let returnValue = Vec_NetAddressZ(cType: nativeCallResult, instantiationContext: "NodeAnnouncementInfo.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
301301

302302

303303
return returnValue

out/structs/PeerManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184

185185
// return value (do some wrapping)
186-
let returnValue = Vec_C2Tuple_PublicKeyCOption_NetAddressZZZ(cType: nativeCallResult, instantiationContext: "PeerManager.swift::\(#function):\(#line)", anchor: self).getValue()
186+
let returnValue = Vec_C2Tuple_PublicKeyCOption_NetAddressZZZ(cType: nativeCallResult, instantiationContext: "PeerManager.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
187187

188188

189189
return returnValue

out/structs/UnsignedNodeAnnouncement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356

357357

358358
// return value (do some wrapping)
359-
let returnValue = Vec_NetAddressZ(cType: nativeCallResult, instantiationContext: "UnsignedNodeAnnouncement.swift::\(#function):\(#line)", anchor: self).getValue()
359+
let returnValue = Vec_NetAddressZ(cType: nativeCallResult, instantiationContext: "UnsignedNodeAnnouncement.swift::\(#function):\(#line)", anchor: self).dangle(false).getValue()
360360

361361

362362
return returnValue

src/generation/base_type_generator.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,10 @@ export abstract class BaseTypeGenerator<Type extends RustType> {
983983
* In this peculiar condition where an instance pointer needs to be passed, we
984984
* actually can still free the returned object – we simply need to make sure that
985985
* the returned object doesn't outlive its creating object.
986+
*
987+
* The same exception also applies if the return type is a vector.
986988
*/
987-
if (hasRecursiveOwnershipFlags) {
989+
if (hasRecursiveOwnershipFlags || returnType.type instanceof RustVector) {
988990
dangleSuffix = '.dangle(false)';
989991
}
990992

0 commit comments

Comments
 (0)