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

confusing Safety comment for Device::udev_device #76

Open
m4rch3n1ng opened this issue Oct 28, 2024 · 0 comments
Open

confusing Safety comment for Device::udev_device #76

m4rch3n1ng opened this issue Oct 28, 2024 · 0 comments

Comments

@m4rch3n1ng
Copy link

the Device::udev_device method has a safety comment saying you have to make sure that you pass in the same udev Context as the one that you used to create the libinput one.

input.rs/src/device.rs

Lines 351 to 366 in 40b31d3

/// # Safety
///
/// The result of this function is not definied if the passed udev `Context`
/// is not the same as the one the libinput `Context` was created from.
#[cfg(feature = "udev")]
pub unsafe fn udev_device(&self) -> Option<UdevDevice> {
let dev: *mut udev_device = ffi::libinput_device_get_udev_device(self.ffi) as *mut _;
if dev.is_null() {
None
} else {
// We have to ref the returned udev context as udev_device_get_udev does not
// increase the ref_count but dropping a UdevDevice will unref it
let ctx: *mut udev_context = udev_ref(udev_device_get_udev(dev));
Some(UdevDevice::from_raw_with_context(ctx, dev))
}
}

but that context hasn't been passed in since ea8e779, so i wanted to know: does that function still need to be unsafe? if yes, what do i, as the caller, have to ensure so i don't cause undefined behaviour?

thanks

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

No branches or pull requests

1 participant