Skip to content

Commit 2dc2ac1

Browse files
committed
liblibc: don't use int/uint for intptr_t/uintptr_t
int/uint aren't considered FFI safe, replace them with the actual type they represent (i64/u64 or i32/u32). This is a breaking change, but at most a cast to `uint` or `int` needs to be added. [breaking-change]
1 parent 0cffa32 commit 2dc2ac1

15 files changed

+74
-71
lines changed

src/liblibc/lib.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ pub mod types {
507507
pub mod c99 {
508508
pub type c_longlong = i64;
509509
pub type c_ulonglong = u64;
510-
pub type intptr_t = int;
511-
pub type uintptr_t = uint;
510+
pub type intptr_t = i32;
511+
pub type uintptr_t = u32;
512512
}
513513
#[cfg(target_arch = "x86")]
514514
#[cfg(target_arch = "mips")]
@@ -702,8 +702,8 @@ pub mod types {
702702
pub mod c99 {
703703
pub type c_longlong = i64;
704704
pub type c_ulonglong = u64;
705-
pub type intptr_t = int;
706-
pub type uintptr_t = uint;
705+
pub type intptr_t = i64;
706+
pub type uintptr_t = u64;
707707
}
708708
pub mod posix88 {
709709
pub type off_t = i64;
@@ -911,8 +911,8 @@ pub mod types {
911911
pub mod c99 {
912912
pub type c_longlong = i64;
913913
pub type c_ulonglong = u64;
914-
pub type intptr_t = int;
915-
pub type uintptr_t = uint;
914+
pub type intptr_t = i64;
915+
pub type uintptr_t = u64;
916916
}
917917
pub mod posix88 {
918918
pub type off_t = i64;
@@ -1124,8 +1124,8 @@ pub mod types {
11241124
pub mod c99 {
11251125
pub type c_longlong = i64;
11261126
pub type c_ulonglong = u64;
1127-
pub type intptr_t = int;
1128-
pub type uintptr_t = uint;
1127+
pub type intptr_t = i64;
1128+
pub type uintptr_t = u64;
11291129
}
11301130
pub mod posix88 {
11311131
pub type off_t = i64;
@@ -1243,9 +1243,10 @@ pub mod types {
12431243
}
12441244

12451245
pub mod bsd44 {
1246-
use types::os::arch::c95::{c_char, c_int, c_uint, size_t, uintptr_t};
1246+
use types::os::arch::c95::{c_char, c_int, c_uint, size_t};
1247+
use types::os::arch::c99::uintptr_t;
12471248

1248-
pub type SOCKET = uint;
1249+
pub type SOCKET = uintptr_t;
12491250
pub type socklen_t = c_int;
12501251
pub type sa_family_t = u16;
12511252
pub type in_port_t = u16;
@@ -1356,8 +1357,8 @@ pub mod types {
13561357
pub mod c99 {
13571358
pub type c_longlong = i64;
13581359
pub type c_ulonglong = u64;
1359-
pub type intptr_t = int;
1360-
pub type uintptr_t = uint;
1360+
pub type intptr_t = i32;
1361+
pub type uintptr_t = u32;
13611362
}
13621363

13631364
pub mod posix88 {
@@ -1486,7 +1487,7 @@ pub mod types {
14861487
pub dwPageSize: DWORD,
14871488
pub lpMinimumApplicationAddress: LPVOID,
14881489
pub lpMaximumApplicationAddress: LPVOID,
1489-
pub dwActiveProcessorMask: uint,
1490+
pub dwActiveProcessorMask: uintptr_t,
14901491
pub dwNumberOfProcessors: DWORD,
14911492
pub dwProcessorType: DWORD,
14921493
pub dwAllocationGranularity: DWORD,
@@ -1720,8 +1721,8 @@ pub mod types {
17201721
pub mod c99 {
17211722
pub type c_longlong = i64;
17221723
pub type c_ulonglong = u64;
1723-
pub type intptr_t = int;
1724-
pub type uintptr_t = uint;
1724+
pub type intptr_t = i32;
1725+
pub type uintptr_t = u32;
17251726
}
17261727
pub mod posix88 {
17271728
pub type off_t = i64;
@@ -1821,8 +1822,8 @@ pub mod types {
18211822
pub mod c99 {
18221823
pub type c_longlong = i64;
18231824
pub type c_ulonglong = u64;
1824-
pub type intptr_t = int;
1825-
pub type uintptr_t = uint;
1825+
pub type intptr_t = i64;
1826+
pub type uintptr_t = u64;
18261827
}
18271828
pub mod posix88 {
18281829
pub type off_t = i64;
@@ -4401,7 +4402,7 @@ pub mod funcs {
44014402
pub fn glob(pattern: *const c_char,
44024403
flags: c_int,
44034404
errfunc: ::Nullable<extern "C" fn(epath: *const c_char,
4404-
errno: int) -> int>,
4405+
errno: c_int) -> int>,
44054406
pglob: *mut glob_t);
44064407
pub fn globfree(pglob: *mut glob_t);
44074408
}

src/libnative/io/c_unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ mod signal {
235235
pub type sigset_t = u32;
236236
#[cfg(target_os = "freebsd")]
237237
#[cfg(target_os = "dragonfly")]
238+
#[repr(C)]
238239
pub struct sigset_t {
239240
bits: [u32, ..4],
240241
}

src/librustc/lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ impl LintPass for CTypes {
369369

370370
if !ty::is_ffi_safe(cx.tcx, tty) {
371371
cx.span_lint(CTYPES, ty.span,
372-
"found enum type without foreign-function-safe
372+
"found type without foreign-function-safe
373373
representation annotation in foreign module, consider \
374-
adding a #[repr(...)] attribute to the enumeration");
374+
adding a #[repr(...)] attribute to the type");
375375
}
376376
}
377377
_ => ()

src/librustuv/uvll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ pub unsafe fn free_req(v: *mut c_void) {
378378
#[test]
379379
fn handle_sanity_check() {
380380
unsafe {
381-
assert_eq!(UV_HANDLE_TYPE_MAX as uint, rust_uv_handle_type_max());
381+
assert_eq!(UV_HANDLE_TYPE_MAX as libc::uintptr_t, rust_uv_handle_type_max());
382382
}
383383
}
384384

385385
#[test]
386386
fn request_sanity_check() {
387387
unsafe {
388-
assert_eq!(UV_REQ_TYPE_MAX as uint, rust_uv_req_type_max());
388+
assert_eq!(UV_REQ_TYPE_MAX as libc::uintptr_t, rust_uv_req_type_max());
389389
}
390390
}
391391

src/libstd/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use libc::c_char;
5959
/// Get the number of cores available
6060
pub fn num_cpus() -> uint {
6161
unsafe {
62-
return rust_get_num_cpus();
62+
return rust_get_num_cpus() as uint;
6363
}
6464

6565
extern {

src/test/auxiliary/extern-crosscrate-source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub mod rustrt {
2424
}
2525
}
2626

27-
pub fn fact(n: uint) -> uint {
27+
pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
2828
unsafe {
2929
println!("n = {}", n);
3030
rustrt::rust_dbg_call(cb, n)
3131
}
3232
}
3333

3434
pub extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
35-
if data == 1u {
35+
if data == 1 {
3636
data
3737
} else {
38-
fact(data - 1u) * data
38+
fact(data - 1) * data
3939
}
4040
}

src/test/compile-fail/issue-14309.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
#![deny(ctypes)]
1212
#![allow(dead_code)]
1313

14-
struct A { //~ NOTE consider adding `#[repr(C)]` to this type
15-
x: int
14+
struct A {
15+
x: i32
1616
}
1717

1818
#[repr(C, packed)]
1919
struct B {
20-
x: int,
20+
x: i32,
2121
y: A
2222
}
2323

2424
#[repr(C)]
2525
struct C {
26-
x: int
26+
x: i32
2727
}
2828

2929
type A2 = A;
@@ -37,13 +37,13 @@ struct D {
3737
}
3838

3939
extern "C" {
40-
fn foo(x: A); //~ ERROR found struct without FFI-safe representation used in FFI
41-
fn bar(x: B); //~ ERROR FFI-safe
40+
fn foo(x: A); //~ ERROR found type without foreign-function-safe
41+
fn bar(x: B); //~ ERROR foreign-function-safe
4242
fn baz(x: C);
43-
fn qux(x: A2); //~ ERROR FFI-safe
44-
fn quux(x: B2); //~ ERROR FFI-safe
43+
fn qux(x: A2); //~ ERROR foreign-function-safe
44+
fn quux(x: B2); //~ ERROR foreign-function-safe
4545
fn corge(x: C2);
46-
fn fred(x: D); //~ ERROR FFI-safe
46+
fn fred(x: D); //~ ERROR foreign-function-safe
4747
}
4848

4949
fn main() { }

src/test/compile-fail/lint-ctypes-enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ enum T { E, F, G }
1818

1919
extern {
2020
fn zf(x: Z);
21-
fn uf(x: U);
22-
fn bf(x: B); //~ ERROR found enum without FFI-safe
23-
fn tf(x: T); //~ ERROR found enum without FFI-safe
21+
fn uf(x: U); //~ ERROR found type without foreign-function-safe
22+
fn bf(x: B); //~ ERROR found type without foreign-function-safe
23+
fn tf(x: T); //~ ERROR found type without foreign-function-safe
2424
}
2525

2626
pub fn main() { }

src/test/run-pass/extern-call-deep.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ mod rustrt {
2222
}
2323

2424
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
25-
if data == 1u {
25+
if data == 1 {
2626
data
2727
} else {
28-
count(data - 1u) + 1u
28+
count(data - 1) + 1
2929
}
3030
}
3131

32-
fn count(n: uint) -> uint {
32+
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
3333
unsafe {
3434
println!("n = {}", n);
3535
rustrt::rust_dbg_call(cb, n)
3636
}
3737
}
3838

3939
pub fn main() {
40-
let result = count(1000u);
40+
let result = count(1000);
4141
println!("result = {}", result);
42-
assert_eq!(result, 1000u);
42+
assert_eq!(result, 1000);
4343
}

src/test/run-pass/extern-call-deep2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ mod rustrt {
2323
}
2424

2525
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
26-
if data == 1u {
26+
if data == 1 {
2727
data
2828
} else {
29-
count(data - 1u) + 1u
29+
count(data - 1) + 1
3030
}
3131
}
3232

33-
fn count(n: uint) -> uint {
33+
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
3434
unsafe {
3535
println!("n = {}", n);
3636
rustrt::rust_dbg_call(cb, n)
@@ -41,8 +41,8 @@ pub fn main() {
4141
// Make sure we're on a task with small Rust stacks (main currently
4242
// has a large stack)
4343
task::spawn(proc() {
44-
let result = count(1000u);
44+
let result = count(1000);
4545
println!("result = {}", result);
46-
assert_eq!(result, 1000u);
46+
assert_eq!(result, 1000);
4747
});
4848
}

src/test/run-pass/extern-call-indirect.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ mod rustrt {
2222
}
2323

2424
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
25-
if data == 1u {
25+
if data == 1 {
2626
data
2727
} else {
28-
fact(data - 1u) * data
28+
fact(data - 1) * data
2929
}
3030
}
3131

32-
fn fact(n: uint) -> uint {
32+
fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
3333
unsafe {
3434
println!("n = {}", n);
3535
rustrt::rust_dbg_call(cb, n)
3636
}
3737
}
3838

3939
pub fn main() {
40-
let result = fact(10u);
40+
let result = fact(10);
4141
println!("result = {}", result);
42-
assert_eq!(result, 3628800u);
42+
assert_eq!(result, 3628800);
4343
}

src/test/run-pass/extern-call-scrub.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ mod rustrt {
2727
}
2828

2929
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
30-
if data == 1u {
30+
if data == 1 {
3131
data
3232
} else {
33-
count(data - 1u) + count(data - 1u)
33+
count(data - 1) + count(data - 1)
3434
}
3535
}
3636

37-
fn count(n: uint) -> uint {
37+
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
3838
unsafe {
3939
println!("n = {}", n);
4040
rustrt::rust_dbg_call(cb, n)
@@ -45,8 +45,8 @@ pub fn main() {
4545
// Make sure we're on a task with small Rust stacks (main currently
4646
// has a large stack)
4747
task::spawn(proc() {
48-
let result = count(12u);
48+
let result = count(12);
4949
println!("result = {}", result);
50-
assert_eq!(result, 2048u);
50+
assert_eq!(result, 2048);
5151
});
5252
}

src/test/run-pass/extern-crosscrate.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
//aux-build:extern-crosscrate-source.rs
1212

1313
extern crate externcallback;
14+
extern crate libc;
1415

15-
fn fact(n: uint) -> uint {
16+
fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
1617
unsafe {
1718
println!("n = {}", n);
1819
externcallback::rustrt::rust_dbg_call(externcallback::cb, n)
1920
}
2021
}
2122

2223
pub fn main() {
23-
let result = fact(10u);
24+
let result = fact(10);
2425
println!("result = {}", result);
25-
assert_eq!(result, 3628800u);
26+
assert_eq!(result, 3628800);
2627
}

src/test/run-pass/extern-stress.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ mod rustrt {
2626
}
2727

2828
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
29-
if data == 1u {
29+
if data == 1 {
3030
data
3131
} else {
3232
task::deschedule();
33-
count(data - 1u) + count(data - 1u)
33+
count(data - 1) + count(data - 1)
3434
}
3535
}
3636

37-
fn count(n: uint) -> uint {
37+
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
3838
unsafe {
3939
rustrt::rust_dbg_call(cb, n)
4040
}
4141
}
4242

4343
pub fn main() {
44-
for _ in range(0, 100u) {
44+
for _ in range(0u, 100) {
4545
task::spawn(proc() {
46-
assert_eq!(count(5u), 16u);
46+
assert_eq!(count(5), 16);
4747
});
4848
}
4949
}

0 commit comments

Comments
 (0)