Skip to content

Commit

Permalink
Unrolled build for rust-lang#124096
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#124096 - saethlin:rust-dbg-call, r=Nilstrieb

Clean up users of rust_dbg_call

`rust_dbg_call` is a C test helper that until this PR was declared in C with `void*` arguments and used in Rust _mostly_ with `libc::uintptr_t` arguments. Nearly every user just wants to pass integers around, so I've changed all users to `uint64_t` or `u64`.

The single test that actually used the pointer-ness of the argument is a test for ensuring that Rust can make extern calls outside of tasks. Rust hasn't had tasks for quite a few years now, so I'm deleting that test under the same logic as the test deleted in rust-lang#124073
  • Loading branch information
rust-timer authored May 12, 2024
2 parents 78a7751 + b91c1aa commit cb570a6
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 157 deletions.
6 changes: 3 additions & 3 deletions tests/auxiliary/rust_test_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ rust_dbg_extern_identity_u8(char u) {
return u;
}

typedef void *(*dbg_callback)(void*);
typedef uint64_t (*dbg_callback)(uint64_t);

void *
rust_dbg_call(dbg_callback cb, void *data) {
uint64_t
rust_dbg_call(dbg_callback cb, uint64_t data) {
return cb(data);
}

Expand Down
25 changes: 9 additions & 16 deletions tests/ui/abi/extern/auxiliary/extern-crosscrate-source.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#![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;
}
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}

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

pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
pub extern "C" fn cb(data: u64) -> u64 {
if data == 1 { data } else { fact(data - 1) * data }
}
28 changes: 10 additions & 18 deletions tests/ui/abi/extern/extern-call-deep.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
//@ 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;
}
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}

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

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: u64) -> u64 {
unsafe {
println!("n = {}", n);
rustrt::rust_dbg_call(cb, n)
rust_dbg_call(cb, n)
}
}

pub fn main() {
let result = count(1000);
println!("result = {}", result);
println!("result = {:?}", result);
assert_eq!(result, 1000);
}
29 changes: 11 additions & 18 deletions tests/ui/abi/extern/extern-call-deep2.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
//@ 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;
}
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}

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: u64) -> u64 {
if data == 1 { data } else { count(data - 1 ) + 1 }
}

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: u64) -> u64 {
unsafe {
println!("n = {}", n);
rustrt::rust_dbg_call(cb, n)
rust_dbg_call(cb, n)
}
}

Expand All @@ -37,5 +30,5 @@ pub fn main() {
println!("result = {}", result);
assert_eq!(result, 1000);
})
.join();
.join().unwrap();
}
26 changes: 9 additions & 17 deletions tests/ui/abi/extern/extern-call-indirect.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
//@ 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;
}
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}

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

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

Expand Down
30 changes: 11 additions & 19 deletions tests/ui/abi/extern/extern-call-scrub.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
//@ 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;
}
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn rust_dbg_call(
cb: extern "C" fn(u64) -> u64,
data: u64,
) -> u64;
}

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

fn count(n: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: u64) -> u64 {
unsafe {
println!("n = {}", n);
rustrt::rust_dbg_call(cb, n)
rust_dbg_call(cb, n)
}
}

Expand All @@ -41,5 +33,5 @@ pub fn main() {
println!("result = {}", result);
assert_eq!(result, 2048);
})
.join();
.join().unwrap();
}
9 changes: 3 additions & 6 deletions tests/ui/abi/extern/extern-crosscrate.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//@ 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: u64) -> u64 {
unsafe {
println!("n = {}", n);
externcallback::rustrt::rust_dbg_call(externcallback::cb, n)
println!("n = {:?}", n);
externcallback::rust_dbg_call(externcallback::cb, n)
}
}

Expand Down
60 changes: 0 additions & 60 deletions tests/ui/abi/foreign/foreign-call-no-runtime.rs

This file was deleted.

0 comments on commit cb570a6

Please sign in to comment.