Skip to content
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

Remove libc from more tests #124072

Merged
merged 2 commits into from
Apr 18, 2024
Merged
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
14 changes: 6 additions & 8 deletions tests/ui/abi/segfault-no-out-of-stack.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
//@ run-pass

#![allow(unused_imports)]
//@ ignore-wasm32 can't run commands
//@ ignore-sgx no processes
//@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
#![feature(rustc_private)]

extern crate libc;
#![feature(rustc_private)]

use std::env;
use std::ffi::c_char;
use std::process::{Command, ExitStatus};

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
fn rust_get_null_ptr() -> *mut ::libc::c_char;
fn rust_get_null_ptr() -> *mut c_char;
}

#[cfg(unix)]
fn check_status(status: std::process::ExitStatus) {
use libc;
fn check_status(status: ExitStatus) {
extern crate libc;
use std::os::unix::process::ExitStatusExt;

assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS));
}

#[cfg(not(unix))]
fn check_status(status: std::process::ExitStatus) {
fn check_status(status: ExitStatus) {
assert!(!status.success());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
// processes with and without the attribute. Search for
// `unix_sigpipe_attr_specified()` in the code base to learn more.

#![feature(rustc_private)]
#![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))]

extern crate libc;
extern crate sigpipe_utils;

use sigpipe_utils::*;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/extern-flag/auxiliary/panic_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Rust programs link necessary system libraries via `#[link()]`
// attributes in the `libc` crate. `libc` is a dependency of `std`,
// but as we are `#![no_std]`, we need to include it manually.
// Except on windows-msvc.
#![feature(rustc_private)]
#[cfg(not(all(windows, target_env = "msvc")))]
extern crate libc;

#[panic_handler]
Expand Down
29 changes: 13 additions & 16 deletions tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014-2.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
// Test that println! to a closed stdout does not panic.
// On Windows, close via SetStdHandle to 0.
//@ run-pass
#![allow(dead_code)]

#![feature(rustc_private)]

extern crate libc;

type DWORD = u32;
type HANDLE = *mut u8;
type BOOL = i32;

#[cfg(windows)]
extern "system" {
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
}

#[cfg(windows)]
fn close_stdout() {
type DWORD = u32;
type HANDLE = *mut u8;
type BOOL = i32;

extern "system" {
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
}

const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); }
}

#[cfg(windows)]
#[cfg(not(windows))]
fn close_stdout() {}

fn main() {
close_stdout();
println!("hello");
println!("world");
}

#[cfg(not(windows))]
fn main() {}
23 changes: 11 additions & 12 deletions tests/ui/rfcs/rfc-1014-stdout-existential-crisis/rfc-1014.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// Test that println! to a closed stdout does not panic.
// On Windows, close via CloseHandle.
//@ run-pass
#![allow(dead_code)]
//@ ignore-sgx no libc

#![feature(rustc_private)]

extern crate libc;

type DWORD = u32;
type HANDLE = *mut u8;

#[cfg(windows)]
extern "system" {
fn GetStdHandle(which: DWORD) -> HANDLE;
fn CloseHandle(handle: HANDLE) -> i32;
}

#[cfg(windows)]
fn close_stdout() {
type DWORD = u32;
type HANDLE = *mut u8;

extern "system" {
fn GetStdHandle(which: DWORD) -> HANDLE;
fn CloseHandle(handle: HANDLE) -> i32;
}

const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); }
}

#[cfg(not(windows))]
fn close_stdout() {
extern crate libc;
unsafe { libc::close(1); }
}

Expand Down
Loading