Preserve references for full-transfer object parameters
This commit is contained in:
parent
2422737865
commit
14072c5df6
7 changed files with 153 additions and 22 deletions
|
|
@ -52,4 +52,23 @@ struct GtkSmokeTests {
|
|||
#expect(adjustment.value == 7)
|
||||
#expect(adjustment.getValue() == 7)
|
||||
}
|
||||
|
||||
@Test("A transfer-full object parameter keeps the Swift wrapper's reference balanced")
|
||||
func transferFullParameterDoesNotOverRelease() throws {
|
||||
// `gtk_shortcut_set_action` is annotated `(transfer full)`: it consumes
|
||||
// one reference. The generated binding must add one before the call, or
|
||||
// the `NamedAction` wrapper's `deinit` releases a reference it no longer
|
||||
// owns, GTK finalizes the action while the shortcut still points at it,
|
||||
// and reading it back trips `g_object_unref: assertion 'G_IS_OBJECT
|
||||
// (object)' failed` plus a use-after-free.
|
||||
let shortcut = Shortcut(trigger: nil, action: nil)
|
||||
do {
|
||||
let action = NamedAction(name: "app.quit")
|
||||
shortcut.setAction(action: action)
|
||||
}
|
||||
// The wrapper is gone; the action must still be alive inside `shortcut`.
|
||||
let stored = shortcut.getAction()
|
||||
#expect(stored != nil)
|
||||
#expect(stored?.toString().contains("app.quit") == true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue