Skip to content

confusing Safety comment for Device::udev_device #76

@m4rch3n1ng

Description

@m4rch3n1ng

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions