-
Notifications
You must be signed in to change notification settings - Fork 19
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
Accept BorrowedFd
in public API methods instead of RawFd
#27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks like the rest of device.rs
already uses OwnedFd
/BorrowedFd
correctly to note ownership transfers.
src/device.rs
Outdated
let fds = [ | ||
buffers[0].as_raw_fd(), | ||
buffers[1].as_raw_fd(), | ||
buffers[2].as_raw_fd(), | ||
buffers[3].as_raw_fd(), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw BorrowedFd
is repr(transparent)
to have the same layout as RawFd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this should be equivalent to an unsafe
mem::transmute
. The compiler hopefully will recognize this and generate the same code. It could be changed, but my inclination is generally to stick with safe code.
It would also be possible to define gbm_import_fd_modifier_data
to use a lifetime bound and BorrowedFd
, but that's not so practical when the struct is in a generated file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually, I suppose this should accept [Option<BorrowedFd<'_>>; 4]
, or you can't pass less than four file descriptors. I kind of wish something like arrayvec
were in std
...
Should still transmute, with None
mapping to -1
, I think. Presumably passing -1 in place of an fd to GBM will return an error, but is safe.
I guess a more idiomatic way to define something like import_buffer_object_from_dma_buf_with_modifiers
would be a builder pattern with a method to add planes? And an error if you add more than 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, and looks like you also discovered that .map()
on a sized array gives back an array of the same size 👍
This should help ensure these function calls aren't used in unsound ways. This is a breaking API change.
This should help ensure these function calls aren't used in unsound ways.
This is a breaking API change.