Skip to content

Commit 6a3b23e

Browse files
committed
---
yaml --- r: 53218 b: refs/heads/dist-snap c: c77c5c4 h: refs/heads/master v: v3
1 parent b270930 commit 6a3b23e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+387
-263
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: 9ba2e65fd6892d2200b517d11e95870e4b2ece12
10+
refs/heads/dist-snap: c77c5c4674c92b342132a56bd1b59f86af3d5a63
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/os.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,13 @@ pub fn path_exists(p: &Path) -> bool {
565565
*
566566
* If the given path is relative, return it prepended with the current working
567567
* directory. If the given path is already an absolute path, return it
568-
* as is.
568+
* as is. This is a shortcut for calling os::getcwd().unsafe_join(p)
569569
*/
570570
// NB: this is here rather than in path because it is a form of environment
571571
// querying; what it does depends on the process working directory, not just
572572
// the input paths.
573573
pub fn make_absolute(p: &Path) -> Path {
574-
if p.is_absolute {
575-
copy *p
576-
} else {
577-
getcwd().push_many(p.components)
578-
}
574+
getcwd().unsafe_join(p)
579575
}
580576

581577

branches/dist-snap/src/libcore/path.rs

Lines changed: 143 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub trait GenericPath {
6464
pure fn push_many((&[~str])) -> Self;
6565
pure fn pop() -> Self;
6666

67+
pure fn unsafe_join((&Self)) -> Self;
68+
pure fn is_restricted() -> bool;
69+
6770
pure fn normalize() -> Self;
6871
}
6972

@@ -485,6 +488,19 @@ impl GenericPath for PosixPath {
485488
self.push_many(other.components)
486489
}
487490

491+
pure fn unsafe_join(other: &PosixPath) -> PosixPath {
492+
if other.is_absolute {
493+
PosixPath { is_absolute: true,
494+
components: copy other.components }
495+
} else {
496+
self.push_rel(other)
497+
}
498+
}
499+
500+
pure fn is_restricted() -> bool {
501+
false
502+
}
503+
488504
pure fn push_many(cs: &[~str]) -> PosixPath {
489505
let mut v = copy self.components;
490506
for cs.each |e| {
@@ -685,6 +701,61 @@ impl GenericPath for WindowsPath {
685701
self.push_many(other.components)
686702
}
687703

704+
pure fn unsafe_join(other: &WindowsPath) -> WindowsPath {
705+
/* rhs not absolute is simple push */
706+
if !other.is_absolute {
707+
return self.push_many(other.components);
708+
}
709+
710+
/* if rhs has a host set, then the whole thing wins */
711+
match other.host {
712+
Some(copy host) => {
713+
return WindowsPath {
714+
host: Some(host),
715+
device: copy other.device,
716+
is_absolute: true,
717+
components: copy other.components
718+
};
719+
}
720+
_ => {}
721+
}
722+
723+
/* if rhs has a device set, then a part wins */
724+
match other.device {
725+
Some(copy device) => {
726+
return WindowsPath {
727+
host: None,
728+
device: Some(device),
729+
is_absolute: true,
730+
components: copy other.components
731+
};
732+
}
733+
_ => {}
734+
}
735+
736+
/* fallback: host and device of lhs win, but the
737+
whole path of the right */
738+
WindowsPath {
739+
host: copy self.host,
740+
device: copy self.device,
741+
is_absolute: self.is_absolute || other.is_absolute,
742+
components: copy other.components
743+
}
744+
}
745+
746+
pure fn is_restricted() -> bool {
747+
match self.filestem() {
748+
Some(stem) => {
749+
match stem.to_lower() {
750+
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
751+
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
752+
_ => false
753+
}
754+
},
755+
None => false
756+
}
757+
}
758+
688759
pure fn push_many(cs: &[~str]) -> WindowsPath {
689760
let mut v = copy self.components;
690761
for cs.each |e| {
@@ -725,7 +796,10 @@ impl GenericPath for WindowsPath {
725796
pure fn normalize() -> WindowsPath {
726797
return WindowsPath {
727798
host: copy self.host,
728-
device: copy self.device,
799+
device: match self.device {
800+
None => None,
801+
Some(ref device) => Some(device.to_upper())
802+
},
729803
is_absolute: self.is_absolute,
730804
components: normalize(self.components)
731805
}
@@ -764,13 +838,13 @@ pub mod windows {
764838
765839
pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
766840
if (s.len() > 1 &&
767-
s[0] == '\\' as u8 &&
768-
s[1] == '\\' as u8) {
841+
(s[0] == '\\' as u8 || s[0] == '/' as u8) &&
842+
s[0] == s[1]) {
769843
let mut i = 2;
770844
while i < s.len() {
771-
if s[i] == '\\' as u8 {
845+
if is_sep(s[i]) {
772846
let pre = s.slice(2, i);
773-
let rest = s.slice(i, s.len());
847+
let mut rest = s.slice(i, s.len());
774848
return Some((pre, rest));
775849
}
776850
i += 1;
@@ -916,13 +990,21 @@ mod tests {
916990
#[test]
917991
fn test_extract_unc_prefixes() {
918992
assert windows::extract_unc_prefix("\\\\").is_none();
993+
assert windows::extract_unc_prefix("//").is_none();
919994
assert windows::extract_unc_prefix("\\\\hi").is_none();
995+
assert windows::extract_unc_prefix("//hi").is_none();
920996
assert windows::extract_unc_prefix("\\\\hi\\") ==
921997
Some((~"hi", ~"\\"));
998+
assert windows::extract_unc_prefix("//hi\\") ==
999+
Some((~"hi", ~"\\"));
9221000
assert windows::extract_unc_prefix("\\\\hi\\there") ==
9231001
Some((~"hi", ~"\\there"));
1002+
assert windows::extract_unc_prefix("//hi/there") ==
1003+
Some((~"hi", ~"/there"));
9241004
assert windows::extract_unc_prefix("\\\\hi\\there\\friends.txt") ==
9251005
Some((~"hi", ~"\\there\\friends.txt"));
1006+
assert windows::extract_unc_prefix("//hi\\there\\friends.txt") ==
1007+
Some((~"hi", ~"\\there\\friends.txt"));
9261008
}
9271009

9281010
#[test]
@@ -981,5 +1063,61 @@ mod tests {
9811063
.push_many([~"lib", ~"thingy.dll"])
9821064
.with_filename("librustc.dll")),
9831065
"c:\\program files (x86)\\rust\\lib\\librustc.dll");
1066+
1067+
t(&(WindowsPath("\\\\computer\\share")
1068+
.unsafe_join(&WindowsPath("\\a"))),
1069+
"\\\\computer\\a");
1070+
1071+
t(&(WindowsPath("//computer/share")
1072+
.unsafe_join(&WindowsPath("\\a"))),
1073+
"\\\\computer\\a");
1074+
1075+
t(&(WindowsPath("//computer/share")
1076+
.unsafe_join(&WindowsPath("\\\\computer\\share"))),
1077+
"\\\\computer\\share");
1078+
1079+
t(&(WindowsPath("C:/whatever")
1080+
.unsafe_join(&WindowsPath("//computer/share/a/b"))),
1081+
"\\\\computer\\share\\a\\b");
1082+
1083+
t(&(WindowsPath("C:")
1084+
.unsafe_join(&WindowsPath("D:/foo"))),
1085+
"D:\\foo");
1086+
1087+
t(&(WindowsPath("C:")
1088+
.unsafe_join(&WindowsPath("B"))),
1089+
"C:B");
1090+
1091+
t(&(WindowsPath("C:")
1092+
.unsafe_join(&WindowsPath("/foo"))),
1093+
"C:\\foo");
1094+
1095+
t(&(WindowsPath("C:\\")
1096+
.unsafe_join(&WindowsPath("\\bar"))),
1097+
"C:\\bar");
1098+
1099+
t(&(WindowsPath("")
1100+
.unsafe_join(&WindowsPath(""))),
1101+
"");
1102+
1103+
t(&(WindowsPath("")
1104+
.unsafe_join(&WindowsPath("a"))),
1105+
"a");
1106+
1107+
t(&(WindowsPath("")
1108+
.unsafe_join(&WindowsPath("C:\\a"))),
1109+
"C:\\a");
1110+
1111+
t(&(WindowsPath("c:\\foo")
1112+
.normalize()),
1113+
"C:\\foo");
1114+
}
1115+
1116+
#[test]
1117+
fn test_windows_path_restrictions() {
1118+
assert WindowsPath("hi").is_restricted() == false;
1119+
assert WindowsPath("C:\\NUL").is_restricted() == true;
1120+
assert WindowsPath("C:\\COM1.TXT").is_restricted() == true;
1121+
assert WindowsPath("c:\\prn.exe").is_restricted() == true;
9841122
}
9851123
}

branches/dist-snap/src/libcore/vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,6 @@ pub trait OwnedVector<T> {
18651865
fn consume(self, f: fn(uint, v: T));
18661866
fn filter(self, f: fn(t: &T) -> bool) -> ~[T];
18671867
fn partition(self, f: pure fn(&T) -> bool) -> (~[T], ~[T]);
1868-
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
18691868
}
18701869

18711870
impl<T> OwnedVector<T> for ~[T] {
@@ -1937,11 +1936,6 @@ impl<T> OwnedVector<T> for ~[T] {
19371936
fn partition(self, f: fn(&T) -> bool) -> (~[T], ~[T]) {
19381937
partition(self, f)
19391938
}
1940-
1941-
#[inline]
1942-
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>) {
1943-
grow_fn(self, n, op);
1944-
}
19451939
}
19461940

19471941
impl<T> Mutable for ~[T] {
@@ -1952,6 +1946,7 @@ impl<T> Mutable for ~[T] {
19521946
pub trait OwnedCopyableVector<T: Copy> {
19531947
fn push_all(&mut self, rhs: &[const T]);
19541948
fn grow(&mut self, n: uint, initval: &T);
1949+
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
19551950
fn grow_set(&mut self, index: uint, initval: &T, val: T);
19561951
}
19571952

@@ -1966,6 +1961,11 @@ impl<T: Copy> OwnedCopyableVector<T> for ~[T] {
19661961
grow(self, n, initval);
19671962
}
19681963

1964+
#[inline]
1965+
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>) {
1966+
grow_fn(self, n, op);
1967+
}
1968+
19691969
#[inline]
19701970
fn grow_set(&mut self, index: uint, initval: &T, val: T) {
19711971
grow_set(self, index, initval, val);

branches/dist-snap/src/librustc/front/core_inject.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ fn inject_libcore_ref(sess: Session,
4545
fold_crate: |crate, span, fld| {
4646
let n1 = sess.next_node_id();
4747
let vi1 = @ast::view_item {
48-
node: ast::view_item_extern_mod(
49-
sess.ident_of(~"core"), ~[], n1),
48+
node: ast::view_item_use(sess.ident_of(~"core"), ~[], n1),
5049
attrs: ~[
5150
spanned(ast::attribute_ {
5251
style: ast::attr_inner,
@@ -87,7 +86,7 @@ fn inject_libcore_ref(sess: Session,
8786
};
8887

8988
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
90-
let vi2 = @ast::view_item { node: ast::view_item_use(~[vp]),
89+
let vi2 = @ast::view_item { node: ast::view_item_import(~[vp]),
9190
attrs: ~[],
9291
vis: ast::private,
9392
span: dummy_sp() };

branches/dist-snap/src/librustc/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
266266
let mi = nospan(mi);
267267
let id_std = cx.sess.ident_of(~"std");
268268
let vi = if is_std(cx) {
269-
ast::view_item_use(
269+
ast::view_item_import(
270270
~[@nospan(ast::view_path_simple(id_std,
271271
path_node(~[id_std]),
272272
ast::type_value_ns,
273273
cx.sess.next_node_id()))])
274274
} else {
275-
ast::view_item_extern_mod(id_std, ~[@mi],
275+
ast::view_item_use(id_std, ~[@mi],
276276
cx.sess.next_node_id())
277277
};
278278
let vi = ast::view_item {

branches/dist-snap/src/librustc/metadata/creader.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,10 @@ fn visit_crate(e: @mut Env, c: ast::crate) {
142142

143143
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
144144
match /*bad*/copy i.node {
145-
ast::view_item_extern_mod(ident, meta_items, id) => {
146-
debug!("resolving extern mod stmt. ident: %?, meta: %?",
147-
ident, meta_items);
145+
ast::view_item_use(ident, meta_items, id) => {
146+
debug!("resolving use stmt. ident: %?, meta: %?", ident, meta_items);
148147
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
149-
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
148+
cstore::add_use_stmt_cnum(e.cstore, id, cnum);
150149
}
151150
_ => ()
152151
}

branches/dist-snap/src/librustc/metadata/cstore.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ pub type crate_metadata = @{name: ~str,
4040

4141
pub struct CStore {
4242
priv metas: oldmap::HashMap<ast::crate_num, crate_metadata>,
43-
priv extern_mod_crate_map: extern_mod_crate_map,
43+
priv use_crate_map: use_crate_map,
4444
priv used_crate_files: ~[Path],
4545
priv used_libraries: ~[~str],
4646
priv used_link_args: ~[~str],
4747
intr: @ident_interner
4848
}
4949

50-
// Map from node_id's of local extern mod statements to crate numbers
51-
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
50+
// Map from node_id's of local use statements to crate numbers
51+
type use_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
5252

5353
pub fn mk_cstore(intr: @ident_interner) -> CStore {
5454
let meta_cache = oldmap::HashMap();
5555
let crate_map = oldmap::HashMap();
5656
return CStore {
5757
metas: meta_cache,
58-
extern_mod_crate_map: crate_map,
58+
use_crate_map: crate_map,
5959
used_crate_files: ~[],
6060
used_libraries: ~[],
6161
used_link_args: ~[],
@@ -127,18 +127,18 @@ pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
127127
return /*bad*/copy cstore.used_link_args;
128128
}
129129

130-
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
131-
emod_id: ast::node_id,
132-
cnum: ast::crate_num) {
133-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
134-
extern_mod_crate_map.insert(emod_id, cnum);
130+
pub fn add_use_stmt_cnum(cstore: @mut CStore,
131+
use_id: ast::node_id,
132+
cnum: ast::crate_num) {
133+
let use_crate_map = cstore.use_crate_map;
134+
use_crate_map.insert(use_id, cnum);
135135
}
136136

137-
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
138-
emod_id: ast::node_id)
137+
pub fn find_use_stmt_cnum(cstore: @mut CStore,
138+
use_id: ast::node_id)
139139
-> Option<ast::crate_num> {
140-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
141-
extern_mod_crate_map.find(&emod_id)
140+
let use_crate_map = cstore.use_crate_map;
141+
use_crate_map.find(&use_id)
142142
}
143143

144144
// returns hashes of crates directly used by this crate. Hashes are
@@ -147,8 +147,8 @@ pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
147147
type crate_hash = {name: ~str, hash: ~str};
148148
let mut result = ~[];
149149

150-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
151-
for extern_mod_crate_map.each_value |&cnum| {
150+
let use_crate_map = cstore.use_crate_map;
151+
for use_crate_map.each_value |&cnum| {
152152
let cdata = cstore::get_crate_data(cstore, cnum);
153153
let hash = decoder::get_crate_hash(cdata.data);
154154
debug!("Add hash[%s]: %s", cdata.name, hash);

0 commit comments

Comments
 (0)