forked from Smithay/udev-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "hack" from Smithay#14 by using a real
udev
context object
Summary --- This introduces an internal (`pub(crate)`) struct `Udev`, which wraps the libudev `struct udev*` in almost the same way that `Enumerator` wraps `udev_enumerate*`. This is then used by `Enumerator::new`, `Builder::new`, and `Device::from_syspath` to ensure enumerators, monitors, and devices always have a valid `udev` context. Any `Device` instances discovered via `Enumerator` or `Builder` will share the same `Udev` instance as the `Enumerator` or `Builder` they came from, so the overhead associated with this change should be minimal. Tests --- The existing unit tests did not reproduce this problem when running in Debian 8 "jessie". I can't explain why, although I assume that the fact that the enumerate test limits the results to "hidraw" subsystem may be a factor. I added another test to enumerate all devices. Note that the `list_devices` example program _did_ segfault on Debian "jessie". I've also added a test for the new `Udev` struct which exercises the `clone`/`drop` implementation by making sure the same instance is used each time. I ran these tests under `valgrind` to confirm there were no memory leaks. Compatibility --- I've tried to keep the compatibility issues to a minimum, however one breaking change was unavoidable: `Enumerator`, `Builder`, and `Device` no longer implement `FromRaw`, because their structs now maintain not only the `struct udev_enumerate*` but also the Rust `Udev` struct which contains the context with which that `Enumerator`/`Builder`/`Device` was created. This is required to keep the `struct udev*` instance alive for the duration of other structs' lifetimes. Ideally the `FromRaw` trait would have been crate-internal anyway, but since it wasn't before this change I'm not attempting to change its visibility now. However any code that depends on `Enumerator`, `Builder`, or `Device` implementing `FromRaw` will break with this change, therefore this probably needs to be published to crates.io with an incremented version number. Closes Smithay#18
- Loading branch information
Showing
5 changed files
with
188 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.