-
Notifications
You must be signed in to change notification settings - Fork 191
DRAFT: Support Buffer
on &mut MaybeUninit<T>
#1413
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
base: main
Are you sure you want to change the base?
Conversation
This returns an output of `Option<&mut T>`: `Some` for `.assume_init(1)`, and `None` for `.assume_init(0)`. This is a draft because it's not clear yet whether `Option` is the best possible return value. For syscalls that will *always* initialize the buffer if they return successfully, this isn't ideal, because it requires handling an `Ok(None)` case that'll never happen. However, for syscalls that *can* return zero output successfully, like `read`, we'd need some way to handle that case.
Which system calls are you envisioning using this with? |
@sunfishcode Anything where you're getting back a single data structure and don't want to unnecessarily initialize it. By way of example, suppose we added I drafted this because it seems more convenient than using Suggestions welcome for better ways to structure this. |
What if we introduced a separate trait for those cases? Perhaps something like: pub trait OptionalOut<T> {
type Output;
fn as_mut_ptr() -> Option<NonNull<T>>;
unsafe fn assume_init() -> Self::Output;
} This would more precisely capture the subtleties here: for this use case: the |
Then we could have: pub fn wait4<Out: OptionalOut<Rusage>>(
pid: Option<Pid>,
waitopts: WaitOptions,
rusage: Out
) -> Result<Option<Out::Output>> The But seeing that written out, I wonder if this wouldn't be better to just have separate functions, one that doesn't return the |
@sunfishcode I've been assuming that we'll only offer The reason for the |
Also, to answer another aspect of your point... I would like the solution for e.g.
If we accept It may be that I should give up on one or the other of those two points. It would certainly be easier to either initialize the RUsage struct or return it by value. (Of the two, I think the latter would be easier.) And if the function is inlined and the optimizer does a good enough job, in theory that should elide the copy and act as if it was allocated in the caller, such that if you just read a couple of fields out of it you don't end up copying the rest of the structure. So, maybe the right answer for pub fn wait4(pid: Option<Pid>, waitopts: WaitOptions) -> Result<Option<(Pid, WaitStatus, RUsage)>> |
This returns an output of
Option<&mut T>
:Some
for.assume_init(1)
,and
None
for.assume_init(0)
.This is a draft because it's not clear yet whether
Option
is the bestpossible return value. For syscalls that will always initialize the
buffer if they return successfully, this isn't ideal, because it
requires handling an
Ok(None)
case that'll never happen. However, forsyscalls that can return zero output successfully, like
read
, we'dneed some way to handle that case.