Skip to content

Commit 9ab8910

Browse files
committed
---
yaml --- r: 79517 b: refs/heads/snap-stage3 c: c891fa3 h: refs/heads/master i: 79515: 2bf79d0 v: v3
1 parent 5bcf702 commit 9ab8910

File tree

4 files changed

+63
-53
lines changed

4 files changed

+63
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 124eb2119c78651cfaaa7a046a101fa2e20f83ca
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 25f3b29c61122bcf160d273348327723cd783419
4+
refs/heads/snap-stage3: c891fa326d28818582a653e588463c45f82e5795
55
refs/heads/try: ac820906c0e53eab79a98ee64f7231f57c3887b4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/rust.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,9 +3385,11 @@ The path to a module consists of the crate name, any parent modules,
33853385
then the module itself, all separated by double colons (`::`). The
33863386
optional log level can be appended to the module path with an equals
33873387
sign (`=`) followed by the log level, from 1 to 4, inclusive. Level 1
3388-
is the error level, 2 is warning, 3 info, and 4 debug. Any logs
3389-
less than or equal to the specified level will be output. If not
3390-
specified then log level 4 is assumed.
3388+
is the error level, 2 is warning, 3 info, and 4 debug. You can also
3389+
use the symbolic constants `error`, `warn`, `info`, and `debug`. Any
3390+
logs less than or equal to the specified level will be output. If not
3391+
specified then log level 4 is assumed. However, debug messages are
3392+
only available if `--cfg=debug` is passed to `rustc`.
33913393

33923394
As an example, to see all the logs generated by the compiler, you would set
33933395
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `link`

branches/snap-stage3/src/libstd/num/strconv.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -552,18 +552,8 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+
552552
// Detect overflow by comparing to last value, except
553553
// if we've not seen any non-zero digits.
554554
if last_accum != _0 {
555-
if accum_positive && accum <= last_accum { return NumStrConv::inf(); }
556-
if !accum_positive && accum >= last_accum { return NumStrConv::neg_inf(); }
557-
558-
// Detect overflow by reversing the shift-and-add proccess
559-
if accum_positive &&
560-
(last_accum != ((accum - cast(digit as int))/radix_gen.clone())) {
561-
return NumStrConv::inf();
562-
}
563-
if !accum_positive &&
564-
(last_accum != ((accum + cast(digit as int))/radix_gen.clone())) {
565-
return NumStrConv::neg_inf();
566-
}
555+
if accum_positive && accum <= last_accum { return None; }
556+
if !accum_positive && accum >= last_accum { return None; }
567557
}
568558
last_accum = accum.clone();
569559
}
@@ -607,8 +597,8 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+
607597
}
608598

609599
// Detect overflow by comparing to last value
610-
if accum_positive && accum < last_accum { return NumStrConv::inf(); }
611-
if !accum_positive && accum > last_accum { return NumStrConv::neg_inf(); }
600+
if accum_positive && accum < last_accum { return None; }
601+
if !accum_positive && accum > last_accum { return None; }
612602
last_accum = accum.clone();
613603
}
614604
None => match c {
@@ -712,23 +702,6 @@ mod test {
712702
ExpNone, false, false);
713703
assert_eq!(n, None);
714704
}
715-
716-
#[test]
717-
fn from_str_issue7588() {
718-
let u : Option<u8> = from_str_common("1000", 10, false, false, false,
719-
ExpNone, false, false);
720-
assert_eq!(u, None);
721-
let s : Option<i16> = from_str_common("80000", 10, false, false, false,
722-
ExpNone, false, false);
723-
assert_eq!(s, None);
724-
let f : Option<f32> = from_str_common(
725-
"10000000000000000000000000000000000000000", 10, false, false, false,
726-
ExpNone, false, false);
727-
assert_eq!(f, NumStrConv::inf())
728-
let fe : Option<f32> = from_str_common("1e40", 10, false, false, false,
729-
ExpDec, false, false);
730-
assert_eq!(fe, NumStrConv::inf())
731-
}
732705
}
733706

734707
#[cfg(test)]

branches/snap-stage3/src/libstd/rt/logging.rs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
use cast::transmute;
1111
use either::*;
1212
use libc::{c_void, uintptr_t, c_char, exit, STDERR_FILENO};
13-
use option::{Some, None};
13+
use option::{Some, None, Option};
1414
use rt::util::dumb_println;
1515
use str::StrSlice;
1616
use str::raw::from_c_str;
1717
use u32;
18+
use u32::{min};
1819
use unstable::raw::Closure;
1920
use vec::ImmutableVector;
2021

@@ -30,7 +31,6 @@ struct ModEntry{
3031
log_level: *mut u32
3132
}
3233

33-
static MAX_LOG_DIRECTIVES: u32 = 255;
3434
static MAX_LOG_LEVEL: u32 = 255;
3535
static DEFAULT_LOG_LEVEL: u32 = 1;
3636

@@ -68,42 +68,68 @@ fn iter_crate_map(map: *u8, f: &fn(*mut ModEntry)) {
6868
data: *c_void);
6969
}
7070
}
71+
static log_level_names : &'static[&'static str] = &'static["error", "warn", "info", "debug"];
72+
73+
/// Parse an individual log level that is either a number or a symbolic log level
74+
fn parse_log_level(level: &str) -> Option<u32> {
75+
let num = u32::from_str(level);
76+
let mut log_level;
77+
match (num) {
78+
Some(num) => {
79+
if num < MAX_LOG_LEVEL {
80+
log_level = Some(num);
81+
} else {
82+
log_level = Some(MAX_LOG_LEVEL);
83+
}
84+
}
85+
_ => {
86+
let position = log_level_names.iter().position(|&name| name == level);
87+
match (position) {
88+
Some(position) => {
89+
log_level = Some(min(MAX_LOG_LEVEL, (position + 1) as u32))
90+
},
91+
_ => {
92+
log_level = None;
93+
}
94+
}
95+
}
96+
}
97+
log_level
98+
}
99+
71100

72101
/// Parse a logging specification string (e.g: "crate1,crate2::mod3,crate3::x=1")
73102
/// and return a vector with log directives.
74-
/// Valid log levels are 0-255, with the most likely ones being 0-3 (defined in std::).
103+
/// Valid log levels are 0-255, with the most likely ones being 1-4 (defined in std::).
104+
/// Also supports string log levels of error, warn, info, and debug
105+
75106
fn parse_logging_spec(spec: ~str) -> ~[LogDirective]{
76107
let mut dirs = ~[];
77108
for s in spec.split_iter(',') {
78109
let parts: ~[&str] = s.split_iter('=').collect();
79-
let mut loglevel;
110+
let mut log_level;
80111
match parts.len() {
81-
1 => loglevel = MAX_LOG_LEVEL,
112+
1 => log_level = MAX_LOG_LEVEL,
82113
2 => {
83-
let num = u32::from_str(parts[1]);
84-
match (num) {
114+
let possible_log_level = parse_log_level(parts[1]);
115+
match possible_log_level {
85116
Some(num) => {
86-
if num < MAX_LOG_LEVEL {
87-
loglevel = num;
88-
} else {
89-
loglevel = MAX_LOG_LEVEL;
90-
}
91-
}
117+
log_level = num;
118+
},
92119
_ => {
93-
dumb_println(fmt!("warning: invalid logging spec \
94-
'%s', ignoring it", s));
95-
loop;
120+
dumb_println(fmt!("warning: invalid logging spec \
121+
'%s', ignoring it", parts[1]));
122+
loop;
96123
}
97124
}
98-
if loglevel > MAX_LOG_LEVEL { loglevel = MAX_LOG_LEVEL}
99125
},
100126
_ => {
101127
dumb_println(fmt!("warning: invalid logging spec '%s',\
102128
ignoring it", s));
103129
loop;
104130
}
105131
}
106-
let dir = LogDirective {name: parts[0].to_owned(), level: loglevel};
132+
let dir = LogDirective {name: parts[0].to_owned(), level: log_level};
107133
dirs.push(dir);
108134
}
109135
return dirs;
@@ -268,6 +294,15 @@ fn parse_logging_spec_invalid_log_level() {
268294
assert_eq!(dirs[0].level, 4);
269295
}
270296
297+
#[test]
298+
fn parse_logging_spec_string_log_level() {
299+
// test parse_logging_spec with 'warn' as log level
300+
let dirs: ~[LogDirective] = parse_logging_spec(~"crate1::mod1=wrong,crate2=warn");
301+
assert_eq!(dirs.len(), 1);
302+
assert!(dirs[0].name == ~"crate2");
303+
assert_eq!(dirs[0].level, 2);
304+
}
305+
271306
// Tests for update_entry
272307
#[test]
273308
fn update_entry_match_full_path() {

0 commit comments

Comments
 (0)