Skip to content

Commit 33e831a

Browse files
committed
---
yaml --- r: 30047 b: refs/heads/incoming c: aa024ac h: refs/heads/master i: 30045: 34fd95d 30043: d6cd3ff 30039: 9e91b6e 30031: 29ae7aa 30015: cbf6e98 v: v3
1 parent 336e681 commit 33e831a

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
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 2dc9be7a142e68550a71086104f7dc5104c1dbf9
9+
refs/heads/incoming: aa024acae3912d7d58e38fdd8185a115f2ab4e8f
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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
}

branches/incoming/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
};

branches/incoming/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

branches/incoming/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)