Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use values, not references, when passing callbacks #108

Merged
merged 1 commit into from
Jan 21, 2024

Conversation

lukhnos
Copy link
Collaborator

@lukhnos lukhnos commented Jan 20, 2024

Before this commit, the callbacks that are passed to KeyHandler have been by-reference. The problem is that, if a callback is owned by a candidate object, and the key handler invokes the StateCallback with a committing state, the commit will cause the candidate panel to reset, destroying the candidate object. At that point the callback reference is no longer valid, and further use of the callback (still within the key handler) is therefore no longer sound.

This becomes problematic when a StateCallback is used multiple times and when the commiting state is involved. To make the code safer, we therefore update the public functions to take callbacks as values, not via references.

This doesn't change the private functions of KeyHandler as those are already referring to the callback object via the value received from the public functions.

Before this commit, the callbacks that are passed to KeyHandler have
been by-reference. The problem is that, if a callback is owned by a
candidate object, and the key handler invokes the StateCallback with a
committing state, the commit will cause the candidate panel to reset,
destroying the candidate object. At that point the callback reference is
no longer valid, and further use of the callback (still within the key
handler) is therefore no longer sound.

This becomes problematic when a StateCallback is used multiple times and
when the commiting state is involved. To make the code safer, we
therefore update the public functions to take callbacks as values, not
via references.

This doesn't change the private functions of KeyHandler as those are
already referring to the callback object via the value received from the
public functions.
@zonble zonble merged commit d1bb925 into master Jan 21, 2024
6 checks passed
@lukhnos lukhnos deleted the dev/fix-dangling-objects branch January 21, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants