Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/std/src/sys/process/unix/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ pub struct Command {
setsid: bool,
}

// passed to do_exec() with configuration of what the child stdio should look
// like
// passed to do_exec() with configuration of what the child stdio should look like
#[cfg_attr(target_os = "vita", allow(dead_code))]
pub struct ChildPipes {
pub stdin: ChildStdio,
pub stdout: ChildStdio,
pub stderr: ChildStdio,
}

// SAFETY: ChildPipes does not involve heap memory allocations
pub enum ChildStdio {
Inherit,
Explicit(c_int),
Expand Down
10 changes: 5 additions & 5 deletions library/std/src/sys/process/unix/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ impl Command {
// For this reason, the block of code below should contain 0
// invocations of either malloc of free (or their related friends).
//
// As an example of not having malloc/free traffic, we don't close
// this file descriptor by dropping the FileDesc (which contains an
// allocation). Instead we just close it manually. This will never
// have the drop glue anyway because this code never returns (the
// child will either exec() or invoke libc::exit)
#[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
unsafe fn do_exec(
&mut self,
Expand All @@ -292,6 +287,11 @@ impl Command {
cvt_r(|| libc::dup2(fd, libc::STDERR_FILENO))?;
}

// SAFETY: Dropping `stdio` (ChildPipes) is safe here since ChildPipes
// does not involve heap memory allocations
debug_assert!(size_of::<ChildPipes>() <= 24);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intension is make sure ChildPipes does not involve heap allocations,
mem::needs_drop does not work here, since ChildPipes -> ChildStdio -> FileDesc,
and FileDesc impl Drop.

any better way to achieve the assertion?

drop(stdio);

#[cfg(not(target_os = "l4re"))]
{
if let Some(_g) = self.get_groups() {
Expand Down
Loading