Skip to content

Commit

Permalink
Remove libc from more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Apr 17, 2024
1 parent 1dea922 commit e7cb951
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 134 deletions.
6 changes: 1 addition & 5 deletions tests/ui/abi/anon-extern-mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
//@ run-pass
//@ pretty-expanded FIXME #23616

#![feature(rustc_private)]

extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
fn rust_get_test_int() -> libc::intptr_t;
fn rust_get_test_int() -> isize;
}

pub fn main() {
Expand Down
6 changes: 1 addition & 5 deletions tests/ui/abi/c-stack-as-value.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
//@ run-pass
//@ pretty-expanded FIXME #23616

#![feature(rustc_private)]

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> isize;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![crate_name = "anonexternmod"]
#![feature(rustc_private)]

extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> isize;
}
17 changes: 6 additions & 11 deletions tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#![crate_name = "externcallback"]
#![crate_type = "lib"]
#![feature(rustc_private)]

extern crate libc;

pub mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t,
) -> libc::uintptr_t;
cb: extern "C" fn(usize) -> usize,
data: usize,
) -> usize;
}
}

pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn fact(n: usize) -> usize {
unsafe {
println!("n = {}", n);
println!("n = {:?}", n);
rustrt::rust_dbg_call(cb, n)
}
}

pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
pub extern "C" fn cb(data: usize) -> usize {
if data == 1 { data } else { fact(data - 1) * data }
}
18 changes: 6 additions & 12 deletions tests/ui/abi/extern/extern-call-deep.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
//@ run-pass
//@ ignore-emscripten blows the JS stack

#![feature(rustc_private)]

extern crate libc;

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t,
) -> libc::uintptr_t;
cb: extern "C" fn(usize) -> usize,
data: usize,
) -> usize;
}
}

extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
extern "C" fn cb(data: usize) -> usize {
if data == 1 { data } else { count(data - 1) + 1 }
}

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: usize) -> usize {
unsafe {
println!("n = {}", n);
println!("n = {:?}", n);
rustrt::rust_dbg_call(cb, n)
}
}
Expand Down
23 changes: 9 additions & 14 deletions tests/ui/abi/extern/extern-call-deep2.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
//@ run-pass
#![allow(unused_must_use)]
//@ needs-threads
#![feature(rustc_private)]

extern crate libc;
use std::thread;

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t,
) -> libc::uintptr_t;
cb: extern "C" fn(usize) -> usize,
data: usize,
) -> usize;
}
}

extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 { data } else { count(data - 1) + 1 }
extern "C" fn cb(data: usize) -> usize {
if data == 1 { data } else { count(data - 1 ) + 1 }
}

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: usize) -> usize {
unsafe {
println!("n = {}", n);
println!("n = {:?}", n);
rustrt::rust_dbg_call(cb, n)
}
}
Expand All @@ -34,8 +29,8 @@ pub fn main() {
// has a large stack)
thread::spawn(move || {
let result = count(1000);
println!("result = {}", result);
println!("result = {:?}", result);
assert_eq!(result, 1000);
})
.join();
.join().unwrap();
}
16 changes: 5 additions & 11 deletions tests/ui/abi/extern/extern-call-indirect.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
//@ run-pass

#![feature(rustc_private)]

extern crate libc;

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t,
) -> libc::uintptr_t;
cb: extern "C" fn(usize) -> usize,
data: usize,
) -> usize;
}
}

extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
extern "C" fn cb(data: usize) -> usize {
if data == 1 { data } else { fact(data - 1) * data }
}

fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
fn fact(n: usize) -> usize {
unsafe {
println!("n = {}", n);
rustrt::rust_dbg_call(cb, n)
Expand Down
20 changes: 7 additions & 13 deletions tests/ui/abi/extern/extern-call-scrub.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
//@ run-pass
#![allow(unused_must_use)]
//@ needs-threads
// This time we're testing repeatedly going up and down both stacks to
// make sure the stack pointers are maintained properly in both
// directions

//@ needs-threads
#![feature(rustc_private)]

extern crate libc;
use std::thread;

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t,
) -> libc::uintptr_t;
cb: extern "C" fn(usize) -> usize,
data: usize,
) -> usize;
}
}

extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
extern "C" fn cb(data: usize) -> usize {
if data == 1 { data } else { count(data - 1) + count(data - 1) }
}

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: usize) -> usize {
unsafe {
println!("n = {}", n);
rustrt::rust_dbg_call(cb, n)
Expand All @@ -41,5 +35,5 @@ pub fn main() {
println!("result = {}", result);
assert_eq!(result, 2048);
})
.join();
.join().unwrap();
}
7 changes: 2 additions & 5 deletions tests/ui/abi/extern/extern-crosscrate.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//@ run-pass
//@ aux-build:extern-crosscrate-source.rs

#![feature(rustc_private)]

extern crate externcallback;
extern crate libc;

fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
fn fact(n: usize) -> usize {
unsafe {
println!("n = {}", n);
println!("n = {:?}", n);
externcallback::rustrt::rust_dbg_call(externcallback::cb, n)
}
}
Expand Down
11 changes: 3 additions & 8 deletions tests/ui/abi/foreign/auxiliary/foreign_lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#![crate_name = "foreign_lib"]
#![feature(rustc_private)]

pub mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> isize;
}
}

pub mod rustrt2 {
extern crate libc;

extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> isize;
}
}

Expand All @@ -32,6 +27,6 @@ pub fn local_uses() {
unsafe {
let x = rustrt::rust_get_test_int();
assert_eq!(x, rustrt2::rust_get_test_int());
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
assert_eq!(x as *const u8, rustrt3::rust_get_test_int());
}
}
13 changes: 5 additions & 8 deletions tests/ui/abi/foreign/foreign-call-no-runtime.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//@ run-pass
//@ needs-threads

#![feature(rustc_private)]

extern crate libc;

use std::ffi::c_void;
use std::mem;
use std::thread;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), data: libc::uintptr_t) -> libc::uintptr_t;
fn rust_dbg_call(cb: extern "C" fn(*const c_void), data: *const c_void) -> *const c_void;
}

pub fn main() {
Expand Down Expand Up @@ -38,21 +35,21 @@ pub fn main() {
}
}

extern "C" fn callback_isize(data: libc::uintptr_t) {
extern "C" fn callback_isize(data: *const c_void) {
unsafe {
let data = data as *const isize;
assert_eq!(*data, 100);
}
}

extern "C" fn callback_i64(data: libc::uintptr_t) {
extern "C" fn callback_i64(data: *const c_void) {
unsafe {
let data = data as *const i64;
assert_eq!(*data, 100);
}
}

extern "C" fn callback_i32(data: libc::uintptr_t) {
extern "C" fn callback_i32(data: *const c_void) {
unsafe {
let data = data as *const i32;
assert_eq!(*data, 100);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/foreign/foreign-dupe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub fn main() {
unsafe {
let x = foreign_lib::rustrt::rust_get_test_int();
assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int());
assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int());
assert_eq!(x as *const u8, foreign_lib::rustrt3::rust_get_test_int());
}
}
6 changes: 1 addition & 5 deletions tests/ui/abi/foreign/foreign-no-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

//@ pretty-expanded FIXME #23616

#![feature(rustc_private)]

mod rustrt {
extern crate libc;

#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> isize;
}
}

Expand Down
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
Loading

0 comments on commit e7cb951

Please sign in to comment.