Skip to content

Commit

Permalink
Add couple of clarifying comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danpashin committed Jun 26, 2024
1 parent ec9b324 commit 06b5909
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ final class DpkgProgressNotifier: @unchecked Sendable {
// MARK: - Private methods

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

let dpkg = Unmanaged<DpkgProgressNotifier>.fromOpaque(context).takeUnretainedValue()
let dpkg = Unmanaged<DpkgProgressNotifier>.fromOpaque(context).takeRetainedValue()
dpkg.finishedAll()
}
}
Expand Down
5 changes: 5 additions & 0 deletions twackup-gui/Twackup/Sources/FFI Models/FFILogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ actor FFILogger {
}

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

0 comments on commit 06b5909

Please sign in to comment.