Skip to content

Commit 0056dbe

Browse files
committed
Auto merge of rust-lang#516 - binarycrusader:master, r=alexcrichton
Correct solaris libc definitions: * pthread_t is defined as uint_t, so must be c_uint, not uintptr_t, just as pthread_key_t is already defined * fd_set is defined as long, so must be i32/i64 based on target_pointer_width; this also fixes an indirect endianness issue encountered on sparc * FD_SETSIZE should be defined as 65536 when target_pointer_width = 64 Fixes rust-lang#515
2 parents 6813109 + 86b0cab commit 0056dbe

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/unix/solaris/mod.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use dox::mem;
2+
13
pub type c_char = i8;
24
pub type c_long = i64;
35
pub type c_ulong = u64;
@@ -27,7 +29,7 @@ pub type off_t = i64;
2729
pub type useconds_t = ::c_uint;
2830
pub type socklen_t = u32;
2931
pub type sa_family_t = u8;
30-
pub type pthread_t = ::uintptr_t;
32+
pub type pthread_t = ::c_uint;
3133
pub type pthread_key_t = ::c_uint;
3234
pub type blksize_t = u32;
3335
pub type fflags_t = u32;
@@ -123,6 +125,9 @@ s! {
123125
}
124126

125127
pub struct fd_set {
128+
#[cfg(target_pointer_width = "64")]
129+
fds_bits: [i64; FD_SETSIZE / 64],
130+
#[cfg(target_pointer_width = "32")]
126131
fds_bits: [i32; FD_SETSIZE / 32],
127132
}
128133

@@ -448,7 +453,13 @@ pub const SIG_SETMASK: ::c_int = 3;
448453
pub const IPV6_MULTICAST_LOOP: ::c_int = 0x8;
449454
pub const IPV6_V6ONLY: ::c_int = 0x27;
450455

451-
pub const FD_SETSIZE: usize = 1024;
456+
cfg_if! {
457+
if #[cfg(target_pointer_width = "64")] {
458+
pub const FD_SETSIZE: usize = 65536;
459+
} else {
460+
pub const FD_SETSIZE: usize = 1024;
461+
}
462+
}
452463

453464
pub const ST_RDONLY: ::c_ulong = 1;
454465
pub const ST_NOSUID: ::c_ulong = 2;
@@ -946,19 +957,22 @@ pub const RTLD_CONFGEN: ::c_int = 0x10000;
946957

947958
f! {
948959
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
960+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
949961
let fd = fd as usize;
950-
(*set).fds_bits[fd / 32] &= !(1 << (fd % 32));
962+
(*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
951963
return
952964
}
953965

954966
pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
967+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
955968
let fd = fd as usize;
956-
return ((*set).fds_bits[fd / 32] & (1 << (fd % 32))) != 0
969+
return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0
957970
}
958971

959972
pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
973+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
960974
let fd = fd as usize;
961-
(*set).fds_bits[fd / 32] |= 1 << (fd % 32);
975+
(*set).fds_bits[fd / bits] |= 1 << (fd % bits);
962976
return
963977
}
964978

0 commit comments

Comments
 (0)