Skip to content

Commit 06b5909

Browse files
committed
Add couple of clarifying comments
1 parent ec9b324 commit 06b5909

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

twackup-gui/Twackup/Sources/FFI Models/DpkgProgressNotifier.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ final class DpkgProgressNotifier: @unchecked Sendable {
4141
// MARK: - Private methods
4242

4343
private func initFuncs() {
44-
ffiFunctions.context = Unmanaged.passUnretained(self).toOpaque()
44+
// Temporarily make a leak and consume it in finished_all func
45+
ffiFunctions.context = Unmanaged.passRetained(self).toOpaque()
4546
ffiFunctions.started_processing = { context, package in
4647
guard let context, let ffiPackage = FFIPackage(package) else {
4748
tw_package_release(package.inner)
@@ -66,7 +67,7 @@ final class DpkgProgressNotifier: @unchecked Sendable {
6667
ffiFunctions.finished_all = { context in
6768
guard let context else { return }
6869

69-
let dpkg = Unmanaged<DpkgProgressNotifier>.fromOpaque(context).takeUnretainedValue()
70+
let dpkg = Unmanaged<DpkgProgressNotifier>.fromOpaque(context).takeRetainedValue()
7071
dpkg.finishedAll()
7172
}
7273
}

twackup-gui/Twackup/Sources/FFI Models/FFILogger.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ actor FFILogger {
5656
}
5757

5858
var funcs = TwLogFunctions()
59+
// Intented leak since logger can be deinited in Swift but pointer will be saved by Rust struct
60+
// and it will crash in some of this C-style handlers
61+
//
62+
// Maybe there should be some kind of `deinit` func which will balance RC
63+
// but Rust log crate doesn't support deiniting yet
5964
funcs.context = Unmanaged<FFILogger>.passRetained(self).toOpaque()
6065
funcs.log = { context, ffiMsg, level in
6166
guard let context,

0 commit comments

Comments
 (0)