std: change time::timeval to be {sec: i64, usec: i32}.

It's possible to have negative times if expressing time before 1970, so
we should use signed types. Other platforms can return times at a higher
resolution, so we should use 64 bits.
This commit is contained in:
Erick Tryzelaar 2012-04-02 20:38:43 -07:00
parent 12d3d4f125
commit 7aae7320db
3 changed files with 11 additions and 11 deletions

View File

@ -1,19 +1,19 @@
#[abi = "cdecl"]
native mod rustrt {
fn get_time(&sec: u32, &usec: u32);
fn get_time(&sec: i64, &usec: i32);
fn precise_time_ns(&ns: u64);
}
#[doc = "A record specifying a time value in seconds and microseconds."]
type timeval = {sec: u32, usec: u32};
type timeval = {sec: i64, usec: i32};
#[doc = "
Returns the current time as a `timeval` containing the seconds and
microseconds since 1970-01-01T00:00:00Z.
"]
fn get_time() -> timeval {
let mut sec = 0u32;
let mut usec = 0u32;
let mut sec = 0i64;
let mut usec = 0i32;
rustrt::get_time(sec, usec);
ret {sec: sec, usec: usec};
}
@ -42,15 +42,15 @@ mod tests {
#[test]
fn test_get_time() {
const some_recent_date: u32 = 1325376000u32; // 2012-01-01T00:00:00Z
const some_future_date: u32 = 1577836800u32; // 2020-01-01T00:00:00Z
const some_recent_date: i64 = 1325376000i64; // 2012-01-01T00:00:00Z
const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
let tv1 = get_time();
log(debug, "tv1=" + uint::str(tv1.sec as uint) + " sec + "
+ uint::str(tv1.usec as uint) + " usec");
assert tv1.sec > some_recent_date;
assert tv1.usec < 1000000u32;
assert tv1.usec < 1000000i32;
let tv2 = get_time();
log(debug, "tv2=" + uint::str(tv2.sec as uint) + " sec + "
@ -58,7 +58,7 @@ fn test_get_time() {
assert tv2.sec >= tv1.sec;
assert tv2.sec < some_future_date;
assert tv2.usec < 1000000u32;
assert tv2.usec < 1000000i32;
if tv2.sec == tv1.sec {
assert tv2.usec >= tv1.usec;
}

View File

@ -408,7 +408,7 @@ rust_ptr_eq(type_desc *t, rust_box *a, rust_box *b) {
#if defined(__WIN32__)
extern "C" CDECL void
get_time(uint32_t *sec, uint32_t *usec) {
get_time(int64_t *sec, int32_t *usec) {
FILETIME fileTime;
GetSystemTimeAsFileTime(&fileTime);
@ -427,7 +427,7 @@ get_time(uint32_t *sec, uint32_t *usec) {
}
#else
extern "C" CDECL void
get_time(uint32_t *sec, uint32_t *usec) {
get_time(int64_t *sec, int32_t *usec) {
struct timeval tv;
gettimeofday(&tv, NULL);
*sec = tv.tv_sec;

View File

@ -4056,7 +4056,7 @@ fn trans_fn(ccx: @crate_ctxt,
id: ast::node_id) {
let do_time = ccx.sess.opts.stats;
let start = if do_time { time::get_time() }
else { {sec: 0u32, usec: 0u32} };
else { {sec: 0i64, usec: 0i32} };
let _icx = ccx.insn_ctxt("trans_fn");
trans_closure(ccx, path, decl, body, llfndecl, ty_self,
param_substs, id, {|fcx|