Skip to content

Commit 72420ff

Browse files
authored
Merge pull request #4 from lightningdevkit/leak_plugging
Expand memory leak detection coverage
2 parents 159fd5c + 3b54b42 commit 72420ff

File tree

310 files changed

+19640
-3574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+19640
-3574
lines changed

.github/workflows/swift.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ jobs:
1515
git config --global user.email "[email protected]"
1616
git config --global user.name "LDK CI"
1717
# Note this is a different endpoint, as we need one non-upstream commit!
18-
git clone https://git.bitcoin.ninja/rust-lightning
18+
# git clone https://git.bitcoin.ninja/rust-lightning
19+
git clone https://github.com/TheBlueMatt/rust-lightning
1920
cd rust-lightning
20-
git checkout origin/2021-03-java-bindings-base
21+
# git checkout origin/2021-03-java-bindings-base
22+
# git checkout v0.0.100
23+
git checkout dba15b73610e4f54378782e55874fc694bf8bda9
24+
echo "rust-lightning commit hash:"
25+
git rev-parse HEAD
2126
cd ..
2227
git clone https://github.com/lightningdevkit/ldk-c-bindings
28+
cd ldk-c-bindings
29+
git checkout v0.0.100.1
30+
echo "ldk-c-bindings commit hash:"
31+
git rev-parse HEAD
32+
cd ..
2333
- name: Install native Rust toolchain, Valgrind, and build utilitis
2434
run: |
2535
sudo apt-get update

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ci/LDKSwift/.swiftpm
1212
/xcode/LDKFramework/Build/
1313
/xcode/LDKFramework/LDKFramework.xcodeproj/project.xcworkspace/
1414
/xcode/LDKFramework/LDKFramework.xcodeproj/xcuserdata/
15+
/xcode/DirectBindingsApp/Build/
16+
/xcode/DirectBindingsApp/DirectBindingsApp.xcodeproj/project.xcworkspace/
17+
/xcode/DirectBindingsApp/DirectBindingsApp.xcodeproj/xcuserdata/

bindings/LDK/Bindings.swift

Lines changed: 2669 additions & 177 deletions
Large diffs are not rendered by default.

bindings/LDK/options/APIError.swift

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
public class APIError {
1+
public class APIError: NativeTypeWrapper {
22

3-
public internal(set) var cOpaqueStruct: LDKAPIError?;
3+
private static var instanceCounter: UInt = 0
4+
internal let instanceNumber: UInt
5+
6+
public internal(set) var cOpaqueStruct: LDKAPIError?
47

58

69

710
public init(pointer: LDKAPIError){
11+
Self.instanceCounter += 1
12+
self.instanceNumber = Self.instanceCounter
813
self.cOpaqueStruct = pointer
14+
super.init(conflictAvoidingVariableName: 0)
915
}
1016

1117
/* OPTION_METHODS_START */
1218

1319
public enum APIErrorValueType {
14-
case APIMisuseError, FeeRateTooHigh, RouteError, ChannelUnavailable
20+
case APIMisuseError, FeeRateTooHigh, RouteError, ChannelUnavailable, IncompatibleShutdownScript
1521
}
1622

1723
public func getValueType() -> APIErrorValueType? {
@@ -25,6 +31,8 @@ public class APIError {
2531
return .RouteError
2632
case LDKAPIError_ChannelUnavailable:
2733
return .ChannelUnavailable
34+
case LDKAPIError_IncompatibleShutdownScript:
35+
return .IncompatibleShutdownScript
2836
default:
2937
return nil
3038
}
@@ -59,19 +67,78 @@ public class APIError {
5967
return ChannelUnavailable(pointer: self.cOpaqueStruct!.channel_unavailable)
6068
}
6169

70+
public func getValueAsIncompatibleShutdownScript() -> IncompatibleShutdownScript? {
71+
if self.cOpaqueStruct?.tag != LDKAPIError_IncompatibleShutdownScript {
72+
return nil
73+
}
74+
return IncompatibleShutdownScript(pointer: self.cOpaqueStruct!.incompatible_shutdown_script)
75+
}
76+
6277

63-
public func free() -> Void {
78+
internal func free() -> Void {
6479

65-
return APIError_free(self.clone().cOpaqueStruct!);
80+
return APIError_free(self.cOpaqueStruct!);
6681
}
6782

83+
internal func dangle() -> APIError {
84+
self.dangling = true
85+
return self
86+
}
87+
88+
deinit {
89+
if !self.dangling {
90+
print("Freeing APIError \(self.instanceNumber).")
91+
self.free()
92+
} else {
93+
print("Not freeing APIError \(self.instanceNumber) due to dangle.")
94+
}
95+
}
96+
97+
6898
public func clone() -> APIError {
6999

70100
return APIError(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (origPointer: UnsafePointer<LDKAPIError>) in
71101
APIError_clone(origPointer)
72102
});
73103
}
74104

105+
internal func danglingClone() -> APIError {
106+
let dangledClone = self.clone()
107+
dangledClone.dangling = true
108+
return dangledClone
109+
}
110+
111+
112+
public class func apimisuse_error(err: String) -> APIError {
113+
114+
return APIError(pointer: APIError_apimisuse_error(Bindings.new_LDKStr(string: err)));
115+
}
116+
117+
public class func fee_rate_too_high(err: String, feerate: UInt32) -> APIError {
118+
119+
return APIError(pointer: APIError_fee_rate_too_high(Bindings.new_LDKStr(string: err), feerate));
120+
}
121+
122+
public class func route_error(err: String) -> APIError {
123+
124+
return APIError(pointer: APIError_route_error(Bindings.new_LDKStr(string: err)));
125+
}
126+
127+
public class func channel_unavailable(err: String) -> APIError {
128+
129+
return APIError(pointer: APIError_channel_unavailable(Bindings.new_LDKStr(string: err)));
130+
}
131+
132+
public class func monitor_update_failed() -> APIError {
133+
134+
return APIError(pointer: APIError_monitor_update_failed());
135+
}
136+
137+
public class func incompatible_shutdown_script(script: ShutdownScript) -> APIError {
138+
139+
return APIError(pointer: APIError_incompatible_shutdown_script(script.danglingClone().cOpaqueStruct!));
140+
}
141+
75142
/* OPTION_METHODS_END */
76143

77144

@@ -151,4 +218,22 @@ APIError_clone(origPointer)
151218

152219
}
153220

221+
222+
public class IncompatibleShutdownScript {
223+
224+
225+
var cOpaqueStruct: LDKAPIError_LDKIncompatibleShutdownScript_Body?;
226+
fileprivate init(pointer: LDKAPIError_LDKIncompatibleShutdownScript_Body) {
227+
self.cOpaqueStruct = pointer
228+
}
229+
230+
231+
232+
public func getScript() -> ShutdownScript {
233+
return ShutdownScript(pointer: self.cOpaqueStruct!.script)
234+
}
235+
236+
237+
}
238+
154239
}

bindings/LDK/options/ErrorAction.swift

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
public class ErrorAction {
1+
public class ErrorAction: NativeTypeWrapper {
22

3-
public internal(set) var cOpaqueStruct: LDKErrorAction?;
3+
private static var instanceCounter: UInt = 0
4+
internal let instanceNumber: UInt
5+
6+
public internal(set) var cOpaqueStruct: LDKErrorAction?
47

58

69

710
public init(pointer: LDKErrorAction){
11+
Self.instanceCounter += 1
12+
self.instanceNumber = Self.instanceCounter
813
self.cOpaqueStruct = pointer
14+
super.init(conflictAvoidingVariableName: 0)
915
}
1016

1117
/* OPTION_METHODS_START */
@@ -51,18 +57,60 @@ public class ErrorAction {
5157
}
5258

5359

54-
public func free() -> Void {
60+
internal func free() -> Void {
5561

56-
return ErrorAction_free(self.clone().cOpaqueStruct!);
62+
return ErrorAction_free(self.cOpaqueStruct!);
5763
}
5864

65+
internal func dangle() -> ErrorAction {
66+
self.dangling = true
67+
return self
68+
}
69+
70+
deinit {
71+
if !self.dangling {
72+
print("Freeing ErrorAction \(self.instanceNumber).")
73+
self.free()
74+
} else {
75+
print("Not freeing ErrorAction \(self.instanceNumber) due to dangle.")
76+
}
77+
}
78+
79+
5980
public func clone() -> ErrorAction {
6081

6182
return ErrorAction(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (origPointer: UnsafePointer<LDKErrorAction>) in
6283
ErrorAction_clone(origPointer)
6384
});
6485
}
6586

87+
internal func danglingClone() -> ErrorAction {
88+
let dangledClone = self.clone()
89+
dangledClone.dangling = true
90+
return dangledClone
91+
}
92+
93+
94+
public class func disconnect_peer(msg: ErrorMessage) -> ErrorAction {
95+
96+
return ErrorAction(pointer: ErrorAction_disconnect_peer(msg.danglingClone().cOpaqueStruct!));
97+
}
98+
99+
public class func ignore_error() -> ErrorAction {
100+
101+
return ErrorAction(pointer: ErrorAction_ignore_error());
102+
}
103+
104+
public class func ignore_and_log(a: LDKLevel) -> ErrorAction {
105+
106+
return ErrorAction(pointer: ErrorAction_ignore_and_log(a));
107+
}
108+
109+
public class func send_error_message(msg: ErrorMessage) -> ErrorAction {
110+
111+
return ErrorAction(pointer: ErrorAction_send_error_message(msg.danglingClone().cOpaqueStruct!));
112+
}
113+
66114
/* OPTION_METHODS_END */
67115

68116

0 commit comments

Comments
 (0)