Merge pull request #2413 from erickt/master

a couple misc changes
This commit is contained in:
Brian Anderson 2012-05-21 17:32:12 -07:00
commit b4da0364f9
6 changed files with 42 additions and 9 deletions

View File

@ -18,13 +18,7 @@ import vec;
import std::getopts;
import getopts::{optflag, optopt, opt_present};
enum _src {
/* Break cycles in package <-> source */
_source(source),
}
type package = {
// source: _src,
name: str,
uuid: str,
url: str,
@ -293,7 +287,6 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
};
vec::grow(src.packages, 1u, {
// source: _source(src),
name: name,
uuid: uuid,
url: url,

View File

@ -161,6 +161,24 @@ impl reader_util for reader {
while !self.eof() { buf += self.read_bytes(2048u); }
buf
}
fn each_byte(it: fn(int) -> bool) {
while !self.eof() {
if !it(self.read_byte()) { break; }
}
}
fn each_char(it: fn(char) -> bool) {
while !self.eof() {
if !it(self.read_char()) { break; }
}
}
fn each_line(it: fn(str) -> bool) {
while !self.eof() {
if !it(self.read_line()) { break; }
}
}
}
// Reader implementations

View File

@ -1,7 +1,7 @@
#[doc ="
An implementation of the SHA-1 cryptographic hash.
First create a `sha1` object using the `mk_sha1` constructor, then
First create a `sha1` object using the `sha1` constructor, then
feed it input using the `input` or `input_str` methods, which may be
called any number of times.

View File

@ -7,6 +7,7 @@ export
get_time,
precise_time_ns,
precise_time_s,
tzset,
tm,
empty_tm,
now,
@ -20,6 +21,7 @@ native mod rustrt {
fn get_time(&sec: i64, &nsec: i32);
fn precise_time_ns(&ns: u64);
fn rust_tzset();
// FIXME: The i64 values can be passed by-val when #2064 is fixed.
fn rust_gmtime(&&sec: i64, &&nsec: i32, &&result: tm);
fn rust_localtime(&&sec: i64, &&nsec: i32, &&result: tm);
@ -59,6 +61,10 @@ fn precise_time_s() -> float {
ret (precise_time_ns() as float) / 1000000000.;
}
fn tzset() {
rustrt::rust_tzset();
}
type tm = {
tm_sec: i32, // seconds after the minute [0-60]
tm_min: i32, // minutes after the hour [0-59]
@ -869,6 +875,7 @@ mod tests {
#[test]
fn test_at_utc() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let utc = at_utc(time);
@ -890,10 +897,13 @@ mod tests {
#[test]
fn test_at() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let local = at(time);
#error("time_at: %?", local);
assert local.tm_sec == 30_i32;
assert local.tm_min == 31_i32;
assert local.tm_hour == 15_i32;
@ -916,6 +926,7 @@ mod tests {
#[test]
fn test_to_timespec() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let utc = at_utc(time);
@ -927,6 +938,7 @@ mod tests {
#[test]
fn test_conversions() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let utc = at_utc(time);
@ -943,6 +955,7 @@ mod tests {
#[test]
fn test_strptime() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
alt strptime("", "") {
ok(tm) {
@ -1088,11 +1101,14 @@ mod tests {
#[test]
fn test_ctime() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let utc = at_utc(time);
let local = at(time);
#error("test_ctime: %? %?", utc.ctime(), local.ctime());
assert utc.ctime() == "Fri Feb 13 23:31:30 2009";
assert local.ctime() == "Fri Feb 13 15:31:30 2009";
}
@ -1100,6 +1116,7 @@ mod tests {
#[test]
fn test_strftime() {
os::setenv("TZ", "America/Los_Angeles");
tzset();
let time = { sec: 1234567890_i64, nsec: 54321_i32 };
let utc = at_utc(time);

View File

@ -529,6 +529,11 @@ struct tm* LOCALTIME(const time_t *clock, tm *result) {
#define TIMEGM(result) timegm(result)
#endif
extern "C" CDECL void
rust_tzset() {
TZSET();
}
extern "C" CDECL void
rust_gmtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
tm tm;
@ -541,7 +546,6 @@ rust_gmtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
extern "C" CDECL void
rust_localtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
tm tm;
TZSET();
time_t s = *sec;
LOCALTIME(&s, &tm);

View File

@ -12,6 +12,7 @@ debug_abi_2
get_port_id
get_task_id
get_time
rust_tzset
rust_gmtime
rust_localtime
rust_timegm