Skip to content
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

Use passing by-value in gmtime, mktime #6766

Merged
merged 2 commits into from
May 28, 2013
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
19 changes: 9 additions & 10 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -22,11 +22,11 @@ pub mod rustrt {
pub unsafe fn precise_time_ns(ns: &mut u64);

pub unsafe fn rust_tzset();
// FIXME: The i64 values can be passed by-val when #2064 is fixed.

pub unsafe fn rust_gmtime(sec: i64, nsec: i32, result: &mut Tm);
pub unsafe fn rust_localtime(sec: i64, nsec: i32, result: &mut Tm);
pub unsafe fn rust_timegm(tm: &Tm, sec: &mut i64);
pub unsafe fn rust_mktime(tm: &Tm, sec: &mut i64);
pub unsafe fn rust_timegm(tm: &Tm) -> i64;
pub unsafe fn rust_mktime(tm: &Tm) -> i64;
}
}

Expand Down Expand Up @@ -177,12 +177,11 @@ pub impl Tm {
/// Convert time to the seconds from January 1, 1970
fn to_timespec(&self) -> Timespec {
unsafe {
let mut sec = 0i64;
if self.tm_gmtoff == 0_i32 {
rustrt::rust_timegm(self, &mut sec);
} else {
rustrt::rust_mktime(self, &mut sec);
}
let sec = match self.tm_gmtoff {
0_i32 => rustrt::rust_timegm(self),
_ => rustrt::rust_mktime(self)
};

Timespec::new(sec, self.tm_nsec)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,18 +459,18 @@ rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
tm_to_rust_tm(&tm, timeptr, gmtoff, zone, nsec);
}

extern "C" CDECL void
rust_timegm(rust_tm* timeptr, int64_t *out) {
extern "C" CDECL int64_t
rust_timegm(rust_tm* timeptr) {
tm t;
rust_tm_to_tm(timeptr, &t);
*out = TIMEGM(&t);
return TIMEGM(&t);
}

extern "C" CDECL void
rust_mktime(rust_tm* timeptr, int64_t *out) {
extern "C" CDECL int64_t
rust_mktime(rust_tm* timeptr) {
tm t;
rust_tm_to_tm(timeptr, &t);
*out = mktime(&t);
return mktime(&t);
}

extern "C" CDECL rust_sched_id
Expand Down