Skip to content

Commit 7b3db9f

Browse files
committed
---
yaml --- r: 23447 b: refs/heads/master c: aa024ac h: refs/heads/master i: 23445: b8b4bc9 23443: edc259a 23439: 76f177e v: v3
1 parent 5ef4149 commit 7b3db9f

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2dc9be7a142e68550a71086104f7dc5104c1dbf9
2+
refs/heads/master: aa024acae3912d7d58e38fdd8185a115f2ab4e8f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libstd/time.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[forbid(deprecated_mode)];
2-
#[forbid(deprecated_pattern)];
3-
41
import libc::{c_char, c_int, c_long, size_t, time_t};
52
import io::Reader;
63
import result::{result, ok, err};
@@ -131,7 +128,7 @@ fn now() -> tm {
131128
}
132129

133130
/// Parses the time from the string according to the format string.
134-
fn strptime(s: &str, format: &str) -> result<tm, ~str> {
131+
fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
135132
type tm_mut = {
136133
mut tm_sec: i32,
137134
mut tm_min: i32,
@@ -147,7 +144,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
147144
mut tm_nsec: i32,
148145
};
149146

150-
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
147+
fn match_str(s: ~str, pos: uint, needle: ~str) -> bool {
151148
let mut i = pos;
152149
for str::each(needle) |ch| {
153150
if s[i] != ch {
@@ -158,14 +155,14 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
158155
return true;
159156
}
160157

161-
fn match_strs(ss: &str, pos: uint, strs: &[(~str, i32)])
158+
fn match_strs(s: ~str, pos: uint, strs: ~[(~str, i32)])
162159
-> option<(i32, uint)> {
163160
let mut i = 0u;
164161
let len = vec::len(strs);
165162
while i < len {
166163
let (needle, value) = strs[i];
167164

168-
if match_str(ss, pos, needle) {
165+
if match_str(s, pos, needle) {
169166
return some((value, pos + str::len(needle)));
170167
}
171168
i += 1u;
@@ -174,14 +171,14 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
174171
none
175172
}
176173

177-
fn match_digits(ss: &str, pos: uint, digits: uint, ws: bool)
174+
fn match_digits(s: ~str, pos: uint, digits: uint, ws: bool)
178175
-> option<(i32, uint)> {
179176
let mut pos = pos;
180177
let mut value = 0_i32;
181178

182179
let mut i = 0u;
183180
while i < digits {
184-
let {ch, next} = str::char_range_at(str::from_slice(ss), pos);
181+
let {ch, next} = str::char_range_at(s, pos);
185182
pos = next;
186183

187184
match ch {
@@ -197,7 +194,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
197194
some((value, pos))
198195
}
199196

200-
fn parse_char(s: &str, pos: uint, c: char) -> result<uint, ~str> {
197+
fn parse_char(s: ~str, pos: uint, c: char) -> result<uint, ~str> {
201198
let {ch, next} = str::char_range_at(s, pos);
202199

203200
if c == ch {
@@ -209,7 +206,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
209206
}
210207
}
211208

212-
fn parse_type(s: &str, pos: uint, ch: char, tm: &tm_mut)
209+
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
213210
-> result<uint, ~str> {
214211
match ch {
215212
'A' => match match_strs(s, pos, ~[
@@ -519,7 +516,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
519516
}
520517
}
521518

522-
do io::with_str_reader(str::from_slice(format)) |rdr| {
519+
do io::with_str_reader(format) |rdr| {
523520
let tm = {
524521
mut tm_sec: 0_i32,
525522
mut tm_min: 0_i32,
@@ -542,7 +539,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
542539
let {ch, next} = str::char_range_at(s, pos);
543540

544541
match rdr.read_char() {
545-
'%' => match parse_type(s, pos, rdr.read_char(), &tm) {
542+
'%' => match parse_type(s, pos, rdr.read_char(), tm) {
546543
ok(next) => pos = next,
547544
err(e) => { result = err(e); break; }
548545
},
@@ -572,8 +569,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
572569
}
573570
}
574571

575-
fn strftime(format: &str, +tm: tm) -> ~str {
576-
fn parse_type(ch: char, tm: &tm) -> ~str {
572+
fn strftime(format: ~str, tm: tm) -> ~str {
573+
fn parse_type(ch: char, tm: tm) -> ~str {
577574
//FIXME (#2350): Implement missing types.
578575
let die = || #fmt("strftime: can't understand this format %c ",
579576
ch);
@@ -728,10 +725,10 @@ fn strftime(format: &str, +tm: tm) -> ~str {
728725
729726
let mut buf = ~"";
730727

731-
do io::with_str_reader(str::from_slice(format)) |rdr| {
728+
do io::with_str_reader(format) |rdr| {
732729
while !rdr.eof() {
733730
match rdr.read_char() {
734-
'%' => buf += parse_type(rdr.read_char(), &tm),
731+
'%' => buf += parse_type(rdr.read_char(), tm),
735732
ch => str::push_char(buf, ch)
736733
}
737734
}
@@ -769,7 +766,7 @@ impl tm {
769766
fn ctime() -> ~str { self.strftime(~"%c") }
770767
771768
/// Formats the time according to the format string.
772-
fn strftime(format: &str) -> ~str { strftime(format, self) }
769+
fn strftime(format: ~str) -> ~str { strftime(format, self) }
773770
774771
/**
775772
* Returns a time string formatted according to RFC 822.
@@ -986,9 +983,9 @@ mod tests {
986983
}
987984
}
988985

989-
fn test(s: &str, format: &str) -> bool {
986+
fn test(s: ~str, format: ~str) -> bool {
990987
match strptime(s, format) {
991-
ok(tm) => tm.strftime(format) == str::from_slice(s),
988+
ok(tm) => tm.strftime(format) == s,
992989
err(e) => fail e
993990
}
994991
}

trunk/src/libsyntax/ast.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ fn deserialize_span<D>(_d: D) -> span {
3030
#[auto_serialize]
3131
type spanned<T> = {node: T, span: span};
3232

33+
34+
/* can't import macros yet, so this is copied from token.rs. See its comment
35+
* there. */
36+
macro_rules! interner_key (
37+
() => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
38+
(-3 as uint, 0u)))
39+
)
40+
3341
fn serialize_ident<S: serializer>(s: S, i: ident) {
34-
let intr = match unsafe{task::local_data_get(parse::token::interner_key)}{
42+
let intr = match unsafe{task::local_data_get(interner_key!())}{
3543
none => fail ~"serialization: TLS interner not set up",
3644
some(intr) => intr
3745
};
3846

3947
s.emit_str(*(*intr).get(i));
4048
}
4149
fn deserialize_ident<D: deserializer>(d: D) -> ident {
42-
let intr = match unsafe{task::local_data_get(parse::token::interner_key)}{
50+
let intr = match unsafe{task::local_data_get(interner_key!())}{
4351
none => fail ~"deserialization: TLS interner not set up",
4452
some(intr) => intr
4553
};

trunk/src/libsyntax/parse/token.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,14 @@ mod special_idents {
325325
type ident_interner = util::interner::interner<@~str>;
326326

327327
/** Key for thread-local data for sneaking interner information to the
328-
* serializer/deserializer. It sounds like a hack because it is one. */
329-
fn interner_key(+_x: @@ident_interner) { }
328+
* serializer/deserializer. It sounds like a hack because it is one.
329+
* Bonus ultra-hack: functions as keys don't work across crates,
330+
* so we have to use a unique number. See taskgroup_key! in task.rs
331+
* for another case of this. */
332+
macro_rules! interner_key (
333+
() => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
334+
(-3 as uint, 0u)))
335+
)
330336

331337
fn mk_ident_interner() -> ident_interner {
332338
/* the indices here must correspond to the numbers in special_idents */
@@ -343,8 +349,8 @@ fn mk_ident_interner() -> ident_interner {
343349
|x,y| str::eq(*x, *y), init_vec);
344350

345351
/* having multiple interners will just confuse the serializer */
346-
unsafe{ assert task::local_data_get(interner_key) == none };
347-
unsafe{ task::local_data_set(interner_key, @rv) };
352+
unsafe{ assert task::local_data_get(interner_key!()) == none };
353+
unsafe{ task::local_data_set(interner_key!(), @rv) };
348354
rv
349355
}
350356

trunk/src/rustdoc/extract.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import doc::item_utils;
55

66
export from_srv, extract, to_str, interner;
77

8+
9+
/* can't import macros yet, so this is copied from token.rs. See its comment
10+
* there. */
11+
macro_rules! interner_key (
12+
() => (unsafe::transmute::<(uint, uint),
13+
&fn(+@@syntax::parse::token::ident_interner)>((-3 as uint, 0u)))
14+
)
15+
816
// Hack; rather than thread an interner through everywhere, rely on
917
// thread-local data
1018
fn to_str(id: ast::ident) -> ~str {
11-
let intr = unsafe{ task::local_data_get(
12-
syntax::parse::token::interner_key) };
19+
let intr = unsafe{ task::local_data_get(interner_key!()) };
1320

1421
return *(*intr.get()).get(id);
1522
}
1623

1724
fn interner() -> syntax::parse::token::ident_interner {
18-
return *(unsafe{ task::local_data_get(
19-
syntax::parse::token::interner_key) }).get();
25+
return *(unsafe{ task::local_data_get(interner_key!()) }).get();
2026
}
2127

2228
fn from_srv(

0 commit comments

Comments
 (0)