Skip to content

Commit e6ee1fc

Browse files
jamortonbrson
authored andcommitted
---
yaml --- r: 12285 b: refs/heads/master c: 632a4c9 h: refs/heads/master i: 12283: fe84ec8 v: v3
1 parent 928a006 commit e6ee1fc

Some content is hidden

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

99 files changed

+787
-1121
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: bef72447e75b7e37f43d3a82ce40e419c7f747d2
2+
refs/heads/master: 632a4c9326561de2bd9d9ded19a82f22678a0cf4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Stefan Plantikow <[email protected]>
7171
Taras Shpot <[email protected]>
7272
Ted Horst <[email protected]>
7373
Tim Chevalier <[email protected]>
74+
7475
Tomoki Aonuma <[email protected]>
7576
Tycho Sci <[email protected]>
7677
Wade Mealing <[email protected]>

trunk/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ for the parameter list, as in `{|| ...}`.
919919
Partial application is done using the `bind` keyword in Rust.
920920

921921
~~~~
922-
let daynum = bind vec::position_elem(["mo", "tu", "we", "do",
922+
let daynum = bind vec::position_elem(["mo", "tu", "we", "th",
923923
"fr", "sa", "su"], _);
924924
~~~~
925925

@@ -1551,7 +1551,7 @@ programs that just can't be typed.
15511551

15521552
~~~~
15531553
let n = option::none;
1554-
# option::may(n, fn&(&&x:int) {})
1554+
# option::with_option_do(n, fn&(&&x:int) {})
15551555
~~~~
15561556

15571557
If you never do anything else with `n`, the compiler will not be able

trunk/mk/rt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ RUNTIME_CS_$(1) := \
6464
rt/rust_port_selector.cpp \
6565
rt/circular_buffer.cpp \
6666
rt/isaac/randport.cpp \
67-
rt/rust_srv.cpp \
6867
rt/rust_kernel.cpp \
6968
rt/rust_shape.cpp \
7069
rt/rust_abi.cpp \

trunk/src/cargo/cargo.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,13 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
478478
(exec_suffix == "" && !str::starts_with(path::basename(ct),
479479
"lib")) {
480480
#debug(" bin: %s", ct);
481-
// FIXME: need libstd os::copy or something (Issue #1983)
482-
run::run_program("cp", [ct, c.bindir]);
481+
copy_warn(ct, c.bindir);
483482
if c.opts.mode == system_mode {
484483
install_one_crate_to_sysroot(ct, "bin");
485484
}
486485
} else {
487486
#debug(" lib: %s", ct);
488-
run::run_program("cp", [ct, c.libdir]);
487+
copy_warn(ct, c.bindir);
489488
if c.opts.mode == system_mode {
490489
install_one_crate_to_sysroot(ct, libdir());
491490
}
@@ -499,10 +498,7 @@ fn install_one_crate_to_sysroot(ct: str, target: str) {
499498
let path = [_path, "..", target];
500499
check vec::is_not_empty(path);
501500
let target_dir = path::normalize(path::connect_many(path));
502-
let p = run::program_output("cp", [ct, target_dir]);
503-
if p.status != 0 {
504-
warn(#fmt["Copying %s to %s is failed", ct, target_dir]);
505-
}
501+
copy_warn(ct, target_dir);
506502
}
507503
none { }
508504
}
@@ -772,7 +768,7 @@ fn sync_one(c: cargo, name: str, src: source) {
772768
info(#fmt["no signature for source %s", name]);
773769
}
774770
}
775-
run::run_program("cp", [pkgfile, destpkgfile]);
771+
copy_warn(pkgfile, destpkgfile);
776772
}
777773

778774
fn cmd_sync(c: cargo) {
@@ -812,7 +808,7 @@ fn cmd_init(c: cargo) {
812808
} else {
813809
info(#fmt["signature ok for sources.json"]);
814810
}
815-
run::run_program("cp", [srcfile, destsrcfile]);
811+
copy_warn(srcfile, destsrcfile);
816812

817813
info(#fmt["Initialized .cargo in %s", c.root]);
818814
}
@@ -853,6 +849,12 @@ fn cmd_search(c: cargo) {
853849
info(#fmt["Found %d packages.", n]);
854850
}
855851

852+
fn copy_warn(src: str, dest: str) {
853+
if !os::copy_file(src, dest) {
854+
warn(#fmt["Copying %s to %s failed", src, dest]);
855+
}
856+
}
857+
856858
fn cmd_usage() {
857859
print("Usage: cargo <verb> [options] [args...]" +
858860
"

trunk/src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn load_props(testfile: str) -> test_props {
4040
pp_exact = parse_pp_exact(ln, testfile);
4141
}
4242

43-
option::may(parse_aux_build(ln)) {|ab|
43+
option::with_option_do(parse_aux_build(ln)) {|ab|
4444
aux_builds += [ab];
4545
}
4646
};

trunk/src/etc/snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def scrub(b):
3434
"lib/libcore-*.dylib",
3535
"lib/libstd-*.dylib",
3636
"lib/librustc-*.dylib",
37-
"lib/librustsyntax-*.so",
37+
"lib/librustsyntax-*.dylib",
3838
"lib/librustrt.dylib",
3939
"lib/librustllvm.dylib"],
4040
"winnt": ["bin/rustc.exe",

trunk/src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<A> of iterable<A> for [A] {
2929

3030
impl<A> of iterable<A> for option<A> {
3131
fn iter(blk: fn(A)) {
32-
option::may(self, blk)
32+
option::with_option_do(self, blk)
3333
}
3434
}
3535

trunk/src/libcore/libc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,9 @@ mod funcs {
11551155
fn CreateDirectoryW(lpPathName: LPCWSTR,
11561156
lpSecurityAttributes:
11571157
LPSECURITY_ATTRIBUTES) -> BOOL;
1158+
fn CopyFileW(lpExistingFileName: LPCWSTR,
1159+
lpNewFileName: LPCWSTR,
1160+
bFailIfExists: BOOL) -> BOOL;
11581161
fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
11591162
fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
11601163
fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;

trunk/src/libcore/option.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ pure fn is_some<T>(opt: option<T>) -> bool {
5252
!is_none(opt)
5353
}
5454

55-
pure fn from_maybe<T: copy>(opt: option<T>, def: T) -> T {
55+
pure fn get_or_default<T: copy>(opt: option<T>, def: T) -> T {
5656
#[doc = "Returns the contained value or a default"];
5757

5858
alt opt { some(x) { x } none { def } }
5959
}
6060

61-
fn maybe<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U {
61+
fn with_option<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U {
6262
#[doc = "Applies a function to the contained value or returns a default"];
6363

6464
alt opt { none { def } some(t) { f(t) } }
6565
}
6666

67-
fn may<T>(opt: option<T>, f: fn(T)) {
67+
fn with_option_do<T>(opt: option<T>, f: fn(T)) {
6868
#[doc = "Performs an operation on the contained value or does nothing"];
6969

7070
alt opt { none { } some(t) { f(t); } }
@@ -94,11 +94,12 @@ impl extensions<T:copy> for option<T> {
9494
"]
9595
fn chain<U>(f: fn(T) -> option<U>) -> option<U> { chain(self, f) }
9696
#[doc = "Returns the contained value or a default"]
97-
fn from_maybe(def: T) -> T { from_maybe(self, def) }
97+
fn get_or_default(def: T) -> T { get_or_default(self, def) }
9898
#[doc = "Applies a function to the contained value or returns a default"]
99-
fn maybe<U: copy>(def: U, f: fn(T) -> U) -> U { maybe(self, def, f) }
99+
fn with_option<U: copy>(def: U, f: fn(T) -> U) -> U
100+
{ with_option(self, def, f) }
100101
#[doc = "Performs an operation on the contained value or does nothing"]
101-
fn may(f: fn(T)) { may(self, f) }
102+
fn with_option_do(f: fn(T)) { with_option_do(self, f) }
102103
#[doc = "
103104
Gets the value out of an option
104105

trunk/src/libcore/os.rs

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export env, getenv, setenv, fdopen, pipe;
3030
export getcwd, dll_filename, self_exe_path;
3131
export exe_suffix, dll_suffix, sysname;
3232
export homedir, list_dir, list_dir_path, path_is_dir, path_exists,
33-
make_absolute, make_dir, remove_dir, change_dir, remove_file;
33+
make_absolute, make_dir, remove_dir, change_dir, remove_file,
34+
copy_file;
3435

3536
// FIXME: move these to str perhaps?
3637
export as_c_charp, fill_charp_buf;
@@ -534,13 +535,76 @@ fn change_dir(p: path) -> bool {
534535
}
535536
}
536537

538+
#[doc = "Copies a file from one location to another"]
539+
fn copy_file(from: path, to: path) -> bool {
540+
ret do_copy_file(from, to);
541+
542+
#[cfg(target_os = "win32")]
543+
fn do_copy_file(from: path, to: path) -> bool {
544+
// FIXME: remove imports when export globs work properly.
545+
import libc::funcs::extra::kernel32::*;
546+
import libc::types::os::arch::extra::*;
547+
import win32::*;
548+
ret as_utf16_p(from) {|fromp|
549+
as_utf16_p(to) {|top|
550+
CopyFileW(fromp, top, (0 as BOOL)) != (0 as BOOL)
551+
}
552+
}
553+
}
554+
555+
#[cfg(target_os = "linux")]
556+
#[cfg(target_os = "macos")]
557+
#[cfg(target_os = "freebsd")]
558+
fn do_copy_file(from: path, to: path) -> bool unsafe {
559+
let istream = as_c_charp(from) {|fromp|
560+
as_c_charp("rb") {|modebuf|
561+
libc::fopen(fromp, modebuf)
562+
}
563+
};
564+
if istream as uint == 0u {
565+
ret false;
566+
}
567+
let ostream = as_c_charp(to) {|top|
568+
as_c_charp("w+b") {|modebuf|
569+
libc::fopen(top, modebuf)
570+
}
571+
};
572+
if ostream as uint == 0u {
573+
fclose(istream);
574+
ret false;
575+
}
576+
let mut buf : [mut u8] = [mut];
577+
let bufsize = 8192u;
578+
vec::reserve(buf, bufsize);
579+
let mut done = false;
580+
let mut ok = true;
581+
while !done {
582+
vec::as_mut_buf(buf) {|b|
583+
let nread = libc::fread(b as *mut c_void, 1u, bufsize, istream);
584+
if nread > 0 as size_t {
585+
if libc::fwrite(b as *c_void, 1u, nread, ostream) != nread {
586+
ok = false;
587+
done = true;
588+
}
589+
} else {
590+
done = true;
591+
}
592+
}
593+
}
594+
fclose(istream);
595+
fclose(ostream);
596+
ret ok;
597+
}
598+
}
599+
537600
#[doc = "Deletes an existing file"]
538601
fn remove_file(p: path) -> bool {
539602
ret unlink(p);
540603

541604
#[cfg(target_os = "win32")]
542605
fn unlink(p: path) -> bool {
543606
// FIXME: remove imports when export globs work properly.
607+
// (similar to Issue #2006)
544608
import libc::funcs::extra::kernel32::*;
545609
import libc::types::os::arch::extra::*;
546610
import win32::*;
@@ -702,7 +766,7 @@ mod tests {
702766
setenv("HOME", "");
703767
assert os::homedir() == none;
704768

705-
option::may(oldhome, {|s| setenv("HOME", s)});
769+
option::with_option_do(oldhome, {|s| setenv("HOME", s)});
706770
}
707771

708772
#[test]
@@ -732,8 +796,9 @@ mod tests {
732796
setenv("USERPROFILE", "/home/PaloAlto");
733797
assert os::homedir() == some("/home/MountainView");
734798

735-
option::may(oldhome, {|s| setenv("HOME", s)});
736-
option::may(olduserprofile, {|s| setenv("USERPROFILE", s)});
799+
option::with_option_do(oldhome, {|s| setenv("HOME", s)});
800+
option::with_option_do(olduserprofile,
801+
{|s| setenv("USERPROFILE", s)});
737802
}
738803

739804
// Issue #712
@@ -761,4 +826,42 @@ mod tests {
761826
assert (!os::path_exists("test/nonexistent-bogus-path"));
762827
}
763828

829+
#[test]
830+
fn copy_file_does_not_exist() {
831+
assert !os::copy_file("test/nonexistent-bogus-path",
832+
"test/other-bogus-path");
833+
assert !os::path_exists("test/other-bogus-path");
834+
}
835+
836+
#[test]
837+
fn copy_file_ok() {
838+
let tempdir = getcwd(); // would like to use $TMPDIR,
839+
// doesn't seem to work on Linux
840+
assert (str::len(tempdir) > 0u);
841+
let in = tempdir + path::path_sep() + "in.txt";
842+
let out = tempdir + path::path_sep() + "out.txt";
843+
844+
/* Write the temp input file */
845+
let ostream = as_c_charp(in) {|fromp|
846+
as_c_charp("w+b") {|modebuf|
847+
libc::fopen(fromp, modebuf)
848+
}
849+
};
850+
assert (ostream as uint != 0u);
851+
let s = "hello";
852+
let mut buf = str::bytes(s) + [0 as u8];
853+
vec::as_mut_buf(buf) {|b|
854+
assert (libc::fwrite(b as *c_void, 1u, str::len(s) + 1u, ostream) ==
855+
buf.len())};
856+
assert (libc::fclose(ostream) == (0u as c_int));
857+
let rs = os::copy_file(in, out);
858+
if (!os::path_exists(in)) {
859+
fail (#fmt("%s doesn't exist", in));
860+
}
861+
assert(rs);
862+
let rslt = run::run_program("diff", [in, out]);
863+
assert (rslt == 0);
864+
assert (remove_file(in));
865+
assert (remove_file(out));
866+
}
764867
}

trunk/src/libcore/result.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ If the result is an error
2020
pure fn get<T: copy, U>(res: result<T, U>) -> T {
2121
alt res {
2222
ok(t) { t }
23-
err(_) {
24-
// FIXME: Serialize the error value
25-
// and include it in the fail message (maybe just note it)
26-
fail "get called on error result";
23+
err(the_err) {
24+
// FIXME: have a run-fail test for this
25+
unchecked{ fail #fmt("get called on error result: %?", the_err); }
2726
}
2827
}
2928
}

0 commit comments

Comments
 (0)