egui-winit: Fix unsafe API of Clipboard::new#2765
Merged
emilk merged 6 commits intoemilk:masterfrom Mar 30, 2023
Merged
Conversation
The old API allowed passing an arbitrary pointer. The new API still breaks safety by allowing the object to outlive the input, but is at least safer.
emilk
reviewed
Feb 26, 2023
emilk
reviewed
Feb 26, 2023
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
emilk
reviewed
Feb 28, 2023
emilk
reviewed
Feb 28, 2023
Owner
emilk
left a comment
There was a problem hiding this comment.
Looks good!
I think it would be good to document in crates/egui-winit/Cargo.toml that the wayland feature is required to get the clipboard working on wayland.
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Contributor
Author
|
Without the |
Owner
|
needs |
Owner
|
|
Contributor
Author
|
Updated. Wasn't expecting you to push to my branch, 😆 . |
Clipboard::new
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So,
window_clipboardis not (very actively) maintained and I had a look around...copypastais maintained, supports the "primary" clipboard, but makes no attempt to provide a Wayland-X11 abstractionarboardis maintained, supports HTML and uncompressed RGBA images, but makes no attempt to provide a Wayland-X11 abstractionegui-winitdoes have this abstraction, but with an unsafe APIsmithay_clipboard::Clipboard::new notes:
This change addresses the first point (prevents calling
Clipboard::newwith an arbitrary pointer).Addressing the second point with Rust's lifetimes would probably be very frustrating. I haven't tried. Addressing it by marking
Clipboard::newandState::newasunsafewould be another approach, but would result in all code withinState::newbeing compiled inunsafemode, would violate your#[forbid(unsafe)]policy and is probably needlessly onerous (given that observing broken behaviour is unlikely), so I opted merely to add documentation here.I ran
sh/checkbutegui-glowfailscargo check --all-features(on X11). Nothing to do with me.