Skip to content

Commit 717d2dd

Browse files
committed
Use less size_t casts in libstd since it's now defined as usize
1 parent e51190c commit 717d2dd

File tree

8 files changed

+32
-38
lines changed

8 files changed

+32
-38
lines changed

src/libstd/primitive_docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod prim_unit { }
229229
///
230230
/// fn main() {
231231
/// unsafe {
232-
/// let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>() as libc::size_t) as *mut i32;
232+
/// let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>()) as *mut i32;
233233
/// if my_num.is_null() {
234234
/// panic!("failed to allocate memory");
235235
/// }

src/libstd/sys/unix/fd.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![unstable(reason = "not public", issue = "0", feature = "fd")]
1212

1313
use io::{self, Read};
14-
use libc::{self, c_int, size_t, c_void};
14+
use libc::{self, c_int, c_void};
1515
use mem;
1616
use sync::atomic::{AtomicBool, Ordering};
1717
use sys::cvt;
@@ -40,7 +40,7 @@ impl FileDesc {
4040
let ret = cvt(unsafe {
4141
libc::read(self.fd,
4242
buf.as_mut_ptr() as *mut c_void,
43-
buf.len() as size_t)
43+
buf.len())
4444
})?;
4545
Ok(ret as usize)
4646
}
@@ -54,7 +54,7 @@ impl FileDesc {
5454
let ret = cvt(unsafe {
5555
libc::write(self.fd,
5656
buf.as_ptr() as *const c_void,
57-
buf.len() as size_t)
57+
buf.len())
5858
})?;
5959
Ok(ret as usize)
6060
}

src/libstd/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ pub fn readlink(p: &Path) -> io::Result<PathBuf> {
669669

670670
loop {
671671
let buf_read = cvt(unsafe {
672-
libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity() as libc::size_t)
672+
libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity())
673673
})? as usize;
674674

675675
unsafe { buf.set_len(buf_read); }

src/libstd/sys/unix/memchr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
1818
libc::memchr(
1919
haystack.as_ptr() as *const libc::c_void,
2020
needle as libc::c_int,
21-
haystack.len() as libc::size_t)
21+
haystack.len())
2222
};
2323
if p.is_null() {
2424
None
@@ -39,7 +39,7 @@ pub fn memrchr(needle: u8, haystack: &[u8]) -> Option<usize> {
3939
libc::memrchr(
4040
haystack.as_ptr() as *const libc::c_void,
4141
needle as libc::c_int,
42-
haystack.len() as libc::size_t)
42+
haystack.len())
4343
};
4444
if p.is_null() {
4545
None

src/libstd/sys/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn init() {
8383
unsafe {
8484
libc::write(libc::STDERR_FILENO,
8585
msg.as_ptr() as *const libc::c_void,
86-
msg.len() as libc::size_t);
86+
msg.len());
8787
intrinsics::abort();
8888
}
8989
}

src/libstd/sys/unix/os.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn error_string(errno: i32) -> String {
9494

9595
let p = buf.as_mut_ptr();
9696
unsafe {
97-
if strerror_r(errno as c_int, p, buf.len() as libc::size_t) < 0 {
97+
if strerror_r(errno as c_int, p, buf.len()) < 0 {
9898
panic!("strerror_r failure");
9999
}
100100

@@ -108,7 +108,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
108108
loop {
109109
unsafe {
110110
let ptr = buf.as_mut_ptr() as *mut libc::c_char;
111-
if !libc::getcwd(ptr, buf.capacity() as libc::size_t).is_null() {
111+
if !libc::getcwd(ptr, buf.capacity()).is_null() {
112112
let len = CStr::from_ptr(buf.as_ptr() as *const libc::c_char).to_bytes().len();
113113
buf.set_len(len);
114114
buf.shrink_to_fit();
@@ -200,21 +200,20 @@ pub fn current_exe() -> io::Result<PathBuf> {
200200
libc::KERN_PROC as c_int,
201201
libc::KERN_PROC_PATHNAME as c_int,
202202
-1 as c_int];
203-
let mut sz: libc::size_t = 0;
203+
let mut sz = 0;
204204
cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
205-
ptr::null_mut(), &mut sz, ptr::null_mut(),
206-
0 as libc::size_t))?;
205+
ptr::null_mut(), &mut sz, ptr::null_mut(), 0))?;
207206
if sz == 0 {
208207
return Err(io::Error::last_os_error())
209208
}
210-
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
209+
let mut v: Vec<u8> = Vec::with_capacity(sz);
211210
cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
212211
v.as_mut_ptr() as *mut libc::c_void, &mut sz,
213-
ptr::null_mut(), 0 as libc::size_t))?;
212+
ptr::null_mut(), 0))?;
214213
if sz == 0 {
215214
return Err(io::Error::last_os_error());
216215
}
217-
v.set_len(sz as usize - 1); // chop off trailing NUL
216+
v.set_len(sz - 1); // chop off trailing NUL
218217
Ok(PathBuf::from(OsString::from_vec(v)))
219218
}
220219
}
@@ -488,7 +487,7 @@ pub fn home_dir() -> Option<PathBuf> {
488487
buf: &mut Vec<c_char>) -> Option<()> {
489488
let mut result = ptr::null_mut();
490489
match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
491-
buf.capacity() as libc::size_t,
490+
buf.capacity(),
492491
&mut result) {
493492
0 if !result.is_null() => Some(()),
494493
_ => None
@@ -501,7 +500,7 @@ pub fn home_dir() -> Option<PathBuf> {
501500
// getpwuid_r semantics is different on Illumos/Solaris:
502501
// http://illumos.org/man/3c/getpwuid_r
503502
let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
504-
buf.capacity() as libc::size_t);
503+
buf.capacity());
505504
if result.is_null() { None } else { Some(()) }
506505
}
507506

src/libstd/sys/unix/rand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ mod imp {
9797
// full entropy pool
9898
let reader = File::open("/dev/urandom").expect("Unable to open /dev/urandom");
9999
let mut reader_rng = ReaderRng::new(reader);
100-
reader_rng.fill_bytes(& mut v[read..]);
101-
read += v.len() as usize;
100+
reader_rng.fill_bytes(&mut v[read..]);
101+
read += v.len();
102102
} else {
103103
panic!("unexpected getrandom error: {}", err);
104104
}
@@ -281,7 +281,7 @@ mod imp {
281281
}
282282
fn fill_bytes(&mut self, v: &mut [u8]) {
283283
let ret = unsafe {
284-
SecRandomCopyBytes(kSecRandomDefault, v.len() as size_t,
284+
SecRandomCopyBytes(kSecRandomDefault, v.len(),
285285
v.as_mut_ptr())
286286
};
287287
if ret == -1 {

src/libstd/sys/unix/thread.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Thread {
5353

5454
let stack_size = cmp::max(stack, min_stack_size(&attr));
5555
match pthread_attr_setstacksize(&mut attr,
56-
stack_size as libc::size_t) {
56+
stack_size) {
5757
0 => {}
5858
n => {
5959
assert_eq!(n, libc::EINVAL);
@@ -64,7 +64,6 @@ impl Thread {
6464
let page_size = os::page_size();
6565
let stack_size = (stack_size + page_size - 1) &
6666
(-(page_size as isize - 1) as usize - 1);
67-
let stack_size = stack_size as libc::size_t;
6867
assert_eq!(libc::pthread_attr_setstacksize(&mut attr,
6968
stack_size), 0);
7069
}
@@ -264,12 +263,8 @@ pub mod guard {
264263
// Rellocate the last page of the stack.
265264
// This ensures SIGBUS will be raised on
266265
// stack overflow.
267-
let result = mmap(stackaddr,
268-
psize as libc::size_t,
269-
PROT_NONE,
270-
MAP_PRIVATE | MAP_ANON | MAP_FIXED,
271-
-1,
272-
0);
266+
let result = mmap(stackaddr, psize, PROT_NONE,
267+
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
273268

274269
if result != stackaddr || result == MAP_FAILED {
275270
panic!("failed to allocate a guard page");
@@ -293,8 +288,8 @@ pub mod guard {
293288

294289
#[cfg(target_os = "macos")]
295290
pub unsafe fn current() -> Option<usize> {
296-
Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as libc::size_t -
297-
libc::pthread_get_stacksize_np(libc::pthread_self())) as usize)
291+
Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize -
292+
libc::pthread_get_stacksize_np(libc::pthread_self())))
298293
}
299294

300295
#[cfg(any(target_os = "openbsd", target_os = "bitrig"))]
@@ -306,10 +301,10 @@ pub mod guard {
306301
let extra = if cfg!(target_os = "bitrig") {3} else {1} * os::page_size();
307302
Some(if libc::pthread_main_np() == 1 {
308303
// main thread
309-
current_stack.ss_sp as usize - current_stack.ss_size as usize + extra
304+
current_stack.ss_sp as usize - current_stack.ss_size + extra
310305
} else {
311306
// new thread
312-
current_stack.ss_sp as usize - current_stack.ss_size as usize
307+
current_stack.ss_sp as usize - current_stack.ss_size
313308
})
314309
}
315310

@@ -335,11 +330,11 @@ pub mod guard {
335330
&mut size), 0);
336331

337332
ret = if cfg!(target_os = "freebsd") {
338-
Some(stackaddr as usize - guardsize as usize)
333+
Some(stackaddr as usize - guardsize)
339334
} else if cfg!(target_os = "netbsd") {
340335
Some(stackaddr as usize)
341336
} else {
342-
Some(stackaddr as usize + guardsize as usize)
337+
Some(stackaddr as usize + guardsize)
343338
};
344339
}
345340
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
@@ -358,8 +353,8 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize {
358353
weak!(fn __pthread_get_minstack(*const libc::pthread_attr_t) -> libc::size_t);
359354

360355
match __pthread_get_minstack.get() {
361-
None => libc::PTHREAD_STACK_MIN as usize,
362-
Some(f) => unsafe { f(attr) as usize },
356+
None => libc::PTHREAD_STACK_MIN,
357+
Some(f) => unsafe { f(attr) },
363358
}
364359
}
365360

@@ -368,7 +363,7 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize {
368363
#[cfg(all(not(target_os = "linux"),
369364
not(target_os = "netbsd")))]
370365
fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
371-
libc::PTHREAD_STACK_MIN as usize
366+
libc::PTHREAD_STACK_MIN
372367
}
373368

374369
#[cfg(target_os = "netbsd")]

0 commit comments

Comments
 (0)