Skip to content

Commit 2ac5cc4

Browse files
committed
Fix (and extend) src/test/run-pass/foreign-call-no-runtime.rs
While going over various problems signaled by valgrind when running `make check` on a build configured with `--enable-valgrind`, I discovered a bug in this test case. Namely, the test case was previously creating an `i32` (originally an `int` aka `isize` but then we changed the name and the fallback rules), and then reading from a `*const isize`. Valgrind rightly complains about this, since we are reading an 8 byte value on 64-bit systems, but in principle only 4 bytes have been initialized. (I wish this was the only valgrind unclean test, but unfortunately there are a bunch more. This was just the easiest/first one that I dissected.)
1 parent a91f19f commit 2ac5cc4

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/test/run-pass/foreign-call-no-runtime.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,39 @@ extern {
2525
pub fn main() {
2626
unsafe {
2727
thread::spawn(move|| {
28-
let i = 100;
29-
rust_dbg_call(callback, mem::transmute(&i));
30-
}).join();
28+
let i: isize = 100;
29+
rust_dbg_call(callback_isize, mem::transmute(&i));
30+
}).join().unwrap();
31+
32+
thread::spawn(move|| {
33+
let i: i32 = 100;
34+
rust_dbg_call(callback_i32, mem::transmute(&i));
35+
}).join().unwrap();
36+
37+
thread::spawn(move|| {
38+
let i: i64 = 100;
39+
rust_dbg_call(callback_i64, mem::transmute(&i));
40+
}).join().unwrap();
3141
}
3242
}
3343

34-
extern fn callback(data: libc::uintptr_t) {
44+
extern fn callback_isize(data: libc::uintptr_t) {
3545
unsafe {
3646
let data: *const isize = mem::transmute(data);
3747
assert_eq!(*data, 100);
3848
}
3949
}
50+
51+
extern fn callback_i64(data: libc::uintptr_t) {
52+
unsafe {
53+
let data: *const i64 = mem::transmute(data);
54+
assert_eq!(*data, 100);
55+
}
56+
}
57+
58+
extern fn callback_i32(data: libc::uintptr_t) {
59+
unsafe {
60+
let data: *const i32 = mem::transmute(data);
61+
assert_eq!(*data, 100);
62+
}
63+
}

0 commit comments

Comments
 (0)