GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Stabilize subprocess pipe descriptor fixtures · RustPython/RustPython@a1aae8f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/host_env/src
    • posix.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/host_env/src/posix.rs‎

Copy file name to clipboardExpand all lines: crates/host_env/src/posix.rs
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,21 @@ impl IntParser {
23332333
mod subprocess_raw_fd_tests {
23342334
use super::*;
23352335

2336+
fn pipe_above_stdio() -> (OwnedFd, OwnedFd) {
2337+
let duplicate = |fd: OwnedFd, minimum| {
2338+
let raw =
2339+
nix::fcntl::fcntl(&fd, nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(minimum)).unwrap();
2340+
// SAFETY: F_DUPFD_CLOEXEC returned a fresh descriptor owned by this test.
2341+
unsafe { OwnedFd::from_raw_fd(raw) }
2342+
};
2343+
let (reader, writer) = nix::unistd::pipe().unwrap();
2344+
// pipe() orders endpoints by direction, not descriptor number. Allocate
2345+
// the fixture above stderr and in the order required by the keep list.
2346+
let reader = duplicate(reader, 3);
2347+
let writer = duplicate(writer, reader.as_raw_fd() + 1);
2348+
(reader, writer)
2349+
}
2350+
23362351
#[test]
23372352
fn invalid_raw_descriptors_return_ebadf() {
23382353
for err in [
@@ -2353,7 +2368,7 @@ mod subprocess_raw_fd_tests {
23532368

23542369
#[test]
23552370
fn raw_and_borrowed_keep_lists_select_the_same_descriptors() {
2356-
let (reader, writer) = nix::unistd::pipe().unwrap();
2371+
let (reader, writer) = pipe_above_stdio();
23572372
let raw = [reader.as_raw_fd(), writer.as_raw_fd()];
23582373
assert!(raw[0] > 2 && raw[1] > raw[0]);
23592374
let borrowed = [reader.as_fd(), writer.as_fd()];
@@ -2369,7 +2384,7 @@ mod subprocess_raw_fd_tests {
23692384

23702385
#[test]
23712386
fn raw_helpers_preserve_pipe_ownership_and_flags() {
2372-
let (reader, writer) = nix::unistd::pipe().unwrap();
2387+
let (reader, writer) = pipe_above_stdio();
23732388
assert!(reader.as_raw_fd() > 2 && writer.as_raw_fd() > 2);
23742389
let high = nix::fcntl::fcntl(&writer, nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(64)).unwrap();
23752390
// SAFETY: F_DUPFD_CLOEXEC returned a fresh descriptor owned by this test.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.