Skip to content

windows: Fix 64-bit Rust #16336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,18 +1142,16 @@ pub mod types {
pub mod os {
pub mod common {
pub mod posix01 {
use types::os::arch::c95::{c_short, time_t, suseconds_t,
c_long};
use types::os::arch::c95::{c_short, time_t, c_long};
use types::os::arch::extra::{int64, time64_t};
use types::os::arch::posix88::{dev_t, ino_t};
use types::os::arch::posix88::mode_t;

// pub Note: this is the struct called stat64 in win32. Not stat,
// nor stati64.
pub struct stat {
pub st_dev: dev_t,
pub st_ino: ino_t,
pub st_mode: mode_t,
pub st_mode: u16,
pub st_nlink: c_short,
pub st_uid: c_short,
pub st_gid: c_short,
Expand All @@ -1171,8 +1169,8 @@ pub mod types {
}

pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: suseconds_t,
pub tv_sec: c_long,
pub tv_usec: c_long,
}

pub struct timespec {
Expand All @@ -1186,7 +1184,7 @@ pub mod types {
pub mod bsd44 {
use types::os::arch::c95::{c_char, c_int, c_uint, size_t};

pub type SOCKET = c_uint;
pub type SOCKET = uint;
pub type socklen_t = c_int;
pub type sa_family_t = u16;
pub type in_port_t = u16;
Expand All @@ -1197,6 +1195,7 @@ pub mod types {
}
pub struct sockaddr_storage {
pub ss_family: sa_family_t,
pub __ss_pad1: [u8, ..6],
pub __ss_align: i64,
pub __ss_pad2: [u8, ..112],
}
Expand Down Expand Up @@ -1293,12 +1292,9 @@ pub mod types {
pub mod posix88 {
pub type off_t = i32;
pub type dev_t = u32;
pub type ino_t = i16;
pub type ino_t = u16;

#[cfg(target_arch = "x86")]
pub type pid_t = i32;
#[cfg(target_arch = "x86_64")]
pub type pid_t = i64;
pub type pid_t = u32;

pub type useconds_t = u32;
pub type mode_t = u16;
Expand Down Expand Up @@ -1415,7 +1411,7 @@ pub mod types {
pub dwPageSize: DWORD,
pub lpMinimumApplicationAddress: LPVOID,
pub lpMaximumApplicationAddress: LPVOID,
pub dwActiveProcessorMask: DWORD,
pub dwActiveProcessorMask: uint,
pub dwNumberOfProcessors: DWORD,
pub dwProcessorType: DWORD,
pub dwAllocationGranularity: DWORD,
Expand Down Expand Up @@ -1950,7 +1946,7 @@ pub mod consts {
}
pub mod extra {
use types::os::arch::c95::c_int;
use types::os::arch::extra::{WORD, DWORD, BOOL};
use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE};

pub static TRUE : BOOL = 1;
pub static FALSE : BOOL = 0;
Expand Down Expand Up @@ -1979,7 +1975,7 @@ pub mod consts {
pub static ERROR_IO_PENDING: c_int = 997;
pub static ERROR_FILE_INVALID : c_int = 1006;
pub static ERROR_NOT_FOUND: c_int = 1168;
pub static INVALID_HANDLE_VALUE : c_int = -1;
pub static INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE;

pub static DELETE : DWORD = 0x00010000;
pub static READ_CONTROL : DWORD = 0x00020000;
Expand Down
12 changes: 12 additions & 0 deletions src/libnative/io/c_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1;
pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40;

#[repr(C)]
#[cfg(target_arch = "x86")]
pub struct WSADATA {
pub wVersion: libc::WORD,
pub wHighVersion: libc::WORD,
Expand All @@ -37,6 +38,17 @@ pub struct WSADATA {
pub iMaxUdpDg: u16,
pub lpVendorInfo: *mut u8,
}
#[repr(C)]
#[cfg(target_arch = "x86_64")]
pub struct WSADATA {
pub wVersion: libc::WORD,
pub wHighVersion: libc::WORD,
pub iMaxSockets: u16,
pub iMaxUdpDg: u16,
pub lpVendorInfo: *mut u8,
pub szDescription: [u8, ..WSADESCRIPTION_LEN + 1],
pub szSystemStatus: [u8, ..WSASYS_STATUS_LEN + 1],
}

pub type LPWSADATA = *mut WSADATA;

Expand Down
6 changes: 3 additions & 3 deletions src/libnative/io/file_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub fn open(path: &CString, fm: rtio::FileMode, fa: rtio::FileAccess)
dwFlagsAndAttributes,
ptr::mut_null())
};
if handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if handle == libc::INVALID_HANDLE_VALUE {
Err(super::last_error())
} else {
let fd = unsafe {
Expand Down Expand Up @@ -368,7 +368,7 @@ pub fn readdir(p: &CString) -> IoResult<Vec<CString>> {
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
let find_handle = libc::FindFirstFileW(path.as_ptr(),
wfd_ptr as libc::HANDLE);
if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
if find_handle != libc::INVALID_HANDLE_VALUE {
let mut paths = vec!();
let mut more_files = 1 as libc::c_int;
while more_files != 0 {
Expand Down Expand Up @@ -440,7 +440,7 @@ pub fn readlink(p: &CString) -> IoResult<CString> {
libc::FILE_ATTRIBUTE_NORMAL,
ptr::mut_null())
};
if handle as int == libc::INVALID_HANDLE_VALUE as int {
if handle == libc::INVALID_HANDLE_VALUE {
return Err(super::last_error())
}
// Specify (sz - 1) because the documentation states that it's the size
Expand Down
10 changes: 5 additions & 5 deletions src/libnative/io/pipe_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl UnixStream {
libc::FILE_FLAG_OVERLAPPED,
ptr::mut_null())
};
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if result != libc::INVALID_HANDLE_VALUE {
return Some(result)
}

Expand All @@ -238,7 +238,7 @@ impl UnixStream {
libc::FILE_FLAG_OVERLAPPED,
ptr::mut_null())
};
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if result != libc::INVALID_HANDLE_VALUE {
return Some(result)
}
}
Expand All @@ -253,7 +253,7 @@ impl UnixStream {
libc::FILE_FLAG_OVERLAPPED,
ptr::mut_null())
};
if result != libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if result != libc::INVALID_HANDLE_VALUE {
return Some(result)
}
}
Expand Down Expand Up @@ -565,7 +565,7 @@ impl UnixListener {
// and such.
let addr_v = try!(to_utf16(addr));
let ret = unsafe { pipe(addr_v.as_ptr(), true) };
if ret == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if ret == libc::INVALID_HANDLE_VALUE {
Err(super::last_error())
} else {
Ok(UnixListener { handle: ret, name: addr.clone() })
Expand Down Expand Up @@ -680,7 +680,7 @@ impl UnixAcceptor {
// create a second server pipe. If this fails, we disconnect the
// connected client and return an error (see comments above).
let new_handle = unsafe { pipe(name.as_ptr(), false) };
if new_handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
if new_handle == libc::INVALID_HANDLE_VALUE {
let ret = Err(super::last_error());
// If our disconnection fails, then there's not really a whole lot
// that we can do, so fail the task.
Expand Down
10 changes: 5 additions & 5 deletions src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ fn spawn_process_os(cfg: ProcessConfig,
libc::OPEN_EXISTING,
0,
ptr::mut_null());
if *slot == INVALID_HANDLE_VALUE as libc::HANDLE {
if *slot == INVALID_HANDLE_VALUE {
return Err(super::last_error())
}
}
Some(ref fd) => {
let orig = get_osfhandle(fd.fd()) as HANDLE;
if orig == INVALID_HANDLE_VALUE as HANDLE {
if orig == INVALID_HANDLE_VALUE {
return Err(super::last_error())
}
if DuplicateHandle(cur_proc, orig, cur_proc, slot,
Expand Down Expand Up @@ -450,9 +450,9 @@ fn zeroed_startupinfo() -> libc::types::os::arch::extra::STARTUPINFO {
wShowWindow: 0,
cbReserved2: 0,
lpReserved2: ptr::mut_null(),
hStdInput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
hStdOutput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
hStdError: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
hStdInput: libc::INVALID_HANDLE_VALUE,
hStdOutput: libc::INVALID_HANDLE_VALUE,
hStdError: libc::INVALID_HANDLE_VALUE,
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/libnative/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ pub fn eof() -> IoError {
}
}

#[cfg(windows)]
pub fn ms_to_timeval(ms: u64) -> libc::timeval {
libc::timeval {
tv_sec: (ms / 1000) as libc::c_long,
tv_usec: ((ms % 1000) * 1000) as libc::c_long,
}
}
#[cfg(not(windows))]
pub fn ms_to_timeval(ms: u64) -> libc::timeval {
libc::timeval {
tv_sec: (ms / 1000) as libc::time_t,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod imp {
libc::FILE_ATTRIBUTE_NORMAL,
ptr::mut_null())
};
if handle as uint == libc::INVALID_HANDLE_VALUE as uint {
if handle == libc::INVALID_HANDLE_VALUE {
fail!("create file error: {}", os::last_os_error());
}
let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
Expand Down
9 changes: 5 additions & 4 deletions src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,10 +1592,11 @@ mod test {
let tmpdir = tmpdir();
let path = tmpdir.join("a");
check!(File::create(&path));

check!(change_file_times(&path, 1000, 2000));
assert_eq!(check!(path.stat()).accessed, 1000);
assert_eq!(check!(path.stat()).modified, 2000);
// These numbers have to be bigger than the time in the day to account for timezones
// Windows in particular will fail in certain timezones with small enough values
check!(change_file_times(&path, 100000, 200000));
assert_eq!(check!(path.stat()).accessed, 100000);
assert_eq!(check!(path.stat()).modified, 200000);
})

iotest!(fn utime_noexist() {
Expand Down