Fix memory leaks
All checks were successful
Deploy Docs / publish (push) Successful in 21m49s
SwiftLint / SwiftLint (push) Successful in 5s

This commit is contained in:
david-swift 2024-10-31 23:00:50 +01:00
parent 6bf6df0c6f
commit 6229b85f46
59 changed files with 82 additions and 105 deletions

View File

@ -31,7 +31,7 @@ let package = Package(
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"), .package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"),
.package( .package(
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations", url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
from: "0.1.0" branch: "main"
), ),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1") .package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1")
], ],

View File

@ -351,6 +351,7 @@ extension AnyView {
provider?.opaque(), provider?.opaque(),
.init(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION) .init(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
) )
g_object_unref(provider)
} }
} }

View File

@ -14,6 +14,7 @@ gtui_filedialog_save_finish (uint64_t dialog, uint64_t result, uint64_t data)
GFile *file = gtk_file_dialog_save_finish (dialog, result, NULL); GFile *file = gtk_file_dialog_save_finish (dialog, result, NULL);
const char *path = g_file_get_path (file); const char *path = g_file_get_path (file);
filedialog_on_save_cb (dialog, path, data); filedialog_on_save_cb (dialog, path, data);
g_object_unref (file);
} }
static void static void

View File

@ -119,7 +119,9 @@ public struct AboutDialog: AdwaitaWidget {
adw_dialog_set_content_height(dialog?.cast(), -1) adw_dialog_set_content_height(dialog?.cast(), -1)
} else { } else {
if storage.content[dialogID]?.first != nil { if storage.content[dialogID]?.first != nil {
adw_dialog_close(storage.content[dialogID]?.first?.opaquePointer?.cast()) let dialog = storage.content[dialogID]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
} }
} }
} }

View File

@ -135,10 +135,7 @@ public struct AlertDialog: AdwaitaWidget {
let old = storage.fields[Self.responsesID + id] as? [Response] ?? [] let old = storage.fields[Self.responsesID + id] as? [Response] ?? []
old.identifiableTransform( old.identifiableTransform(
to: responses, to: responses,
functions: .init { index, element in functions: .init { index in
adw_alert_dialog_remove_response(pointer?.cast(), responseID(old[safe: index]?.id))
adw_alert_dialog_add_response(pointer?.cast(), responseID(element.id), element.title)
} delete: { index in
adw_alert_dialog_remove_response(pointer?.cast(), responseID(old[safe: index]?.id)) adw_alert_dialog_remove_response(pointer?.cast(), responseID(old[safe: index]?.id))
} insert: { _, element in } insert: { _, element in
adw_alert_dialog_add_response(pointer?.cast(), responseID(element.id), element.title) adw_alert_dialog_add_response(pointer?.cast(), responseID(element.id), element.title)
@ -160,7 +157,9 @@ public struct AlertDialog: AdwaitaWidget {
} }
} else { } else {
if storage.content[Self.dialogID + id]?.first != nil { if storage.content[Self.dialogID + id]?.first != nil {
adw_dialog_close(storage.content[Self.dialogID + id]?.first?.opaquePointer?.cast()) let dialog = storage.content[Self.dialogID + id]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
} }
} }
} }

View File

@ -111,7 +111,9 @@ public struct Dialog: AdwaitaWidget {
} }
} else { } else {
if storage.content[dialogID + id]?.first != nil { if storage.content[dialogID + id]?.first != nil {
adw_dialog_close(storage.content[dialogID + id]?.first?.opaquePointer?.cast()) let dialog = storage.content[dialogID + id]?.first?.opaquePointer
adw_dialog_close(dialog?.cast())
g_object_unref(dialog?.cast())
} }
} }
} }

View File

@ -101,14 +101,17 @@ public struct FileDialog: AdwaitaWidget {
gtk_file_filter_add_suffix(filter, name) gtk_file_filter_add_suffix(filter, name)
} }
gtk_file_dialog_set_default_filter(pointer, filter) gtk_file_dialog_set_default_filter(pointer, filter)
g_object_unref(filter?.cast())
} else { } else {
gtk_file_dialog_set_default_filter(pointer, nil) gtk_file_dialog_set_default_filter(pointer, nil)
} }
if let initialFolder { if let initialFolder {
gtk_file_dialog_set_initial_folder(pointer, g_file_new_for_path(initialFolder.absoluteString)) let file = g_file_new_for_path(initialFolder.absoluteString)
gtk_file_dialog_set_initial_folder(pointer, file)
g_object_unref(file?.cast())
} }
let callbacks = AdwaitaFileDialog() let callbacks = AdwaitaFileDialog()
callbacks.onResult = { (storage.fields["result"] as? (URL) -> Void)?($0) } callbacks.onResult = { (storage.fields["result"] as? (URL) -> Void)?($0); g_object_unref(pointer?.cast()) }
callbacks.onCancel = { (storage.fields["cancel"] as? () -> Void)?() } callbacks.onCancel = { (storage.fields["cancel"] as? () -> Void)?() }
callbacks.reset = { storage.fields["callbacks"] = nil } callbacks.reset = { storage.fields["callbacks"] = nil }
storage.fields["callbacks"] = callbacks storage.fields["callbacks"] = callbacks

View File

@ -58,18 +58,10 @@ public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
let widget: UnsafeMutablePointer<GtkBox>? = storage.opaquePointer?.cast() let widget: UnsafeMutablePointer<GtkBox>? = storage.opaquePointer?.cast()
old.identifiableTransform( old.identifiableTransform(
to: elements, to: elements,
functions: .init { index, element in functions: .init { index in
let child = content(element).storage(data: data, type: type) let child = contentStorage[safe: index]?.opaquePointer
gtk_box_remove(widget, contentStorage[safe: index]?.opaquePointer?.cast()) gtk_box_remove(widget, child?.cast())
gtk_box_insert_child_after( g_object_unref(child?.cast())
widget,
child.opaquePointer?.cast(),
contentStorage[safe: index - 1]?.opaquePointer?.cast()
)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
gtk_box_remove(widget, contentStorage[safe: index]?.opaquePointer?.cast())
contentStorage.remove(at: index) contentStorage.remove(at: index)
} insert: { index, element in } insert: { index, element in
let child = content(element).storage(data: data, type: type) let child = content(element).storage(data: data, type: type)

View File

@ -59,10 +59,7 @@ extension ComboRow {
let old = storage.fields[Self.values] as? [Element] ?? [] let old = storage.fields[Self.values] as? [Element] ?? []
old.identifiableTransform( old.identifiableTransform(
to: values, to: values,
functions: .init { index, element in functions: .init { index in
gtk_string_list_remove(list, .init(index))
gtk_string_list_append(list, element.description)
} delete: { index in
gtk_string_list_remove(list, .init(index)) gtk_string_list_remove(list, .init(index))
} insert: { _, element in } insert: { _, element in
gtk_string_list_append(list, element.description) gtk_string_list_append(list, element.description)

View File

@ -2,7 +2,7 @@
// ActionRow.swift // ActionRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// AspectFrame.swift // AspectFrame.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Avatar.swift // Avatar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Banner.swift // Banner.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Bin.swift // Bin.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Box.swift // Box.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Button.swift // Button.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ButtonContent.swift // ButtonContent.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Carousel.swift // Carousel.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw
@ -124,13 +124,7 @@ public struct Carousel<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? [] let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform( old.identifiableTransform(
to: elements, to: elements,
functions: .init { index, element in functions: .init { index in
let child = content(element).storage(data: data, type: type)
adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt))
adw_carousel_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt)) adw_carousel_remove(widget, adw_carousel_get_nth_page(widget, UInt(index).cInt))
contentStorage.remove(at: index) contentStorage.remove(at: index)
} insert: { index, element in } insert: { index, element in

View File

@ -2,7 +2,7 @@
// CenterBox.swift // CenterBox.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// CheckButton.swift // CheckButton.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Clamp.swift // Clamp.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ComboRow.swift // ComboRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// EntryRow.swift // EntryRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ExpanderRow.swift // ExpanderRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Fixed.swift // Fixed.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// FlowBox.swift // FlowBox.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw
@ -236,13 +236,7 @@ public struct FlowBox<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? [] let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform( old.identifiableTransform(
to: elements, to: elements,
functions: .init { index, element in functions: .init { index in
let child = content(element).storage(data: data, type: type)
gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast())
gtk_flow_box_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast()) gtk_flow_box_remove(widget, gtk_flow_box_get_child_at_index(widget, index.cInt)?.cast())
contentStorage.remove(at: index) contentStorage.remove(at: index)
} insert: { index, element in } insert: { index, element in

View File

@ -2,7 +2,7 @@
// HeaderBar.swift // HeaderBar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Label.swift // Label.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// LevelBar.swift // LevelBar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// LinkButton.swift // LinkButton.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ListBox.swift // ListBox.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw
@ -218,13 +218,7 @@ public struct ListBox<Element>: AdwaitaWidget where Element: Identifiable {
let old = storage.fields["element"] as? [Element] ?? [] let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform( old.identifiableTransform(
to: elements, to: elements,
functions: .init { index, element in functions: .init { index in
let child = content(element).storage(data: data, type: type)
gtk_list_box_remove(widget, gtk_list_box_get_row_at_index(widget, index.cInt)?.cast())
gtk_list_box_insert(widget, child.opaquePointer?.cast(), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
gtk_list_box_remove(widget, gtk_list_box_get_row_at_index(widget, index.cInt)?.cast()) gtk_list_box_remove(widget, gtk_list_box_get_row_at_index(widget, index.cInt)?.cast())
contentStorage.remove(at: index) contentStorage.remove(at: index)
} insert: { index, element in } insert: { index, element in

View File

@ -2,7 +2,7 @@
// Menu.swift // Menu.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// NavigationView.swift // NavigationView.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Overlay.swift // Overlay.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// OverlaySplitView.swift // OverlaySplitView.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// PasswordEntryRow.swift // PasswordEntryRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Picture.swift // Picture.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Popover.swift // Popover.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesGroup.swift // PreferencesGroup.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesPage.swift // PreferencesPage.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// PreferencesRow.swift // PreferencesRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ProgressBar.swift // ProgressBar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ScrolledWindow.swift // ScrolledWindow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// SearchBar.swift // SearchBar.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// SearchEntry.swift // SearchEntry.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Separator.swift // Separator.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// SpinRow.swift // SpinRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// Spinner.swift // Spinner.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// SplitButton.swift // SplitButton.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// StatusPage.swift // StatusPage.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// SwitchRow.swift // SwitchRow.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ToastOverlay.swift // ToastOverlay.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ToggleButton.swift // ToggleButton.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// ToolbarView.swift // ToolbarView.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -2,7 +2,7 @@
// WindowTitle.swift // WindowTitle.swift
// Adwaita // Adwaita
// //
// Created by auto-generation on 26.10.24. // Created by auto-generation on 31.10.24.
// //
import CAdw import CAdw

View File

@ -32,6 +32,9 @@ extension Picture {
g_bytes_new(ptr.baseAddress, .init(data.count)) g_bytes_new(ptr.baseAddress, .init(data.count))
} }
let texture = gdk_texture_new_from_bytes(bytes, nil) let texture = gdk_texture_new_from_bytes(bytes, nil)
if let paintable = gtk_picture_get_paintable(pointer) {
g_object_unref(paintable.cast())
}
gtk_picture_set_paintable(pointer, texture) gtk_picture_set_paintable(pointer, texture)
storage.fields[oldData] = data storage.fields[oldData] = data
} }

View File

@ -22,7 +22,11 @@ extension Text {
/// - Parameter ellipsize: Whether it should ellipsize. /// - Parameter ellipsize: Whether it should ellipsize.
/// - Returns: The text widget. /// - Returns: The text widget.
public func ellipsize(_ ellipsize: Bool = true) -> AnyView { public func ellipsize(_ ellipsize: Bool = true) -> AnyView {
inspect { storage, _ in gtk_label_set_ellipsize(storage.opaquePointer, PANGO_ELLIPSIZE_END) } inspect { storage, update in
if update {
gtk_label_set_ellipsize(storage.opaquePointer, PANGO_ELLIPSIZE_END)
}
}
} }
} }

View File

@ -97,10 +97,7 @@ public struct ViewSwitcher<Element>: AdwaitaWidget where Element: ViewSwitcherOp
} }
((switcher.previousState as? Self)?.elements ?? []).map { $0.title }.transform( ((switcher.previousState as? Self)?.elements ?? []).map { $0.title }.transform(
to: elements.map { $0.title }, to: elements.map { $0.title },
functions: .init { index, title in functions: .init { index in
remove(index)
insert(title)
} delete: { index in
remove(index) remove(index)
} insert: { _, title in } insert: { _, title in
insert(title) insert(title)

View File

@ -228,13 +228,7 @@ extension Class {
let old = storage.fields["element"] as? [Element] ?? [] let old = storage.fields["element"] as? [Element] ?? []
old.identifiableTransform( old.identifiableTransform(
to: elements, to: elements,
functions: .init { index, element in functions: .init { index in
\(child)
\(dynamicWidget.remove)(\(widget), \(dynamicWidget.getElement))
\(dynamicWidget.insert)(\(widget), \(pointer), index.cInt)
contentStorage.remove(at: index)
contentStorage.insert(child, at: index)
} delete: { index in
\(dynamicWidget.remove)(\(widget), \(dynamicWidget.getElement)) \(dynamicWidget.remove)(\(widget), \(dynamicWidget.getElement))
contentStorage.remove(at: index) contentStorage.remove(at: index)
} insert: { index, element in } insert: { index, element in