Skip to content

Commit

Permalink
Remove unnecessary allocations flagged by lint from fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed May 21, 2013
1 parent d4724c1 commit 70222b7
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum test_mode { tm_converge, tm_run, }
pub struct Context { mode: test_mode } // + rng

pub fn write_file(filename: &Path, content: &str) {
result::get(&io::file_writer(filename, ~[io::Create, io::Truncate]))
result::get(&io::file_writer(filename, [io::Create, io::Truncate]))
.write_str(content);
}

Expand All @@ -47,12 +47,12 @@ pub fn contains(haystack: &str, needle: &str) -> bool {
}

pub fn find_rust_files(files: &mut ~[Path], path: &Path) {
if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") {
if path.filetype() == Some(~".rs") && !contains(path.to_str(), "utf8") {
// ignoring "utf8" tests because something is broken
files.push(path.clone());
} else if os::path_is_dir(path)
&& !contains(path.to_str(), ~"compile-fail")
&& !contains(path.to_str(), ~"build") {
&& !contains(path.to_str(), "compile-fail")
&& !contains(path.to_str(), "build") {
for os::list_dir_path(path).each |p| {
find_rust_files(&mut *files, *p);
}
Expand Down Expand Up @@ -406,34 +406,34 @@ pub fn check_whole_compiler(code: &str,

pub fn removeIfExists(filename: &Path) {
// So sketchy!
assert!(!contains(filename.to_str(), ~" "));
run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]);
assert!(!contains(filename.to_str(), " "));
run::program_output("bash", [~"-c", ~"rm " + filename.to_str()]);
}

pub fn removeDirIfExists(filename: &Path) {
// So sketchy!
assert!(!contains(filename.to_str(), ~" "));
run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]);
assert!(!contains(filename.to_str(), " "));
run::program_output("bash", [~"-c", ~"rm -r " + filename.to_str()]);
}

pub fn check_running(exe_filename: &Path) -> happiness {
let p = run::program_output(
~"/Users/jruderman/scripts/timed_run_rust_program.py",
~[exe_filename.to_str()]);
"/Users/jruderman/scripts/timed_run_rust_program.py",
[exe_filename.to_str()]);
let comb = p.out + ~"\n" + p.err;
if str::len(comb) > 1u {
error!("comb comb comb: %?", comb);
}

if contains(comb, ~"Assertion failed:") {
if contains(comb, "Assertion failed:") {
failed(~"C++ assertion failure")
} else if contains(comb, ~"leaked memory in rust main loop") {
} else if contains(comb, "leaked memory in rust main loop") {
// might also use exit code 134
//failed("Leaked")
known_bug(~"https://github.com/mozilla/rust/issues/910")
} else if contains(comb, ~"src/rt/") {
} else if contains(comb, "src/rt/") {
failed(~"Mentioned src/rt/")
} else if contains(comb, ~"malloc") {
} else if contains(comb, "malloc") {
failed(~"Mentioned malloc")
} else {
match p.status {
Expand All @@ -457,26 +457,26 @@ pub fn check_running(exe_filename: &Path) -> happiness {

pub fn check_compiling(filename: &Path) -> happiness {
let p = run::program_output(
~"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
stage1/bin/rustc",
~[filename.to_str()]);
[filename.to_str()]);

//error!("Status: %d", p.status);
if p.status == 0 {
passed
} else if p.err != ~"" {
if contains(p.err, ~"error:") {
if contains(p.err, "error:") {
cleanly_rejected(~"rejected with span_error")
} else {
error!("Stderr: %?", p.err);
failed(~"Unfamiliar error message")
}
} else if contains(p.out, ~"Assertion") && contains(p.out, ~"failed") {
} else if contains(p.out, "Assertion") && contains(p.out, "failed") {
error!("Stdout: %?", p.out);
failed(~"Looks like an llvm assertion failure")
} else if contains(p.out, ~"internal compiler error unimplemented") {
} else if contains(p.out, "internal compiler error unimplemented") {
known_bug(~"Something unimplemented")
} else if contains(p.out, ~"internal compiler error") {
} else if contains(p.out, "internal compiler error") {
error!("Stdout: %?", p.out);
failed(~"internal compiler error")

Expand Down Expand Up @@ -603,8 +603,8 @@ pub fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
error!("Did not converge after %u iterations!", i);
write_file(&Path("round-trip-a.rs"), *oldv);
write_file(&Path("round-trip-b.rs"), *newv);
run::run_program(~"diff",
~[~"-w", ~"-u", ~"round-trip-a.rs",
run::run_program("diff",
[~"-w", ~"-u", ~"round-trip-a.rs",
~"round-trip-b.rs"]);
fail!("Mismatch");
}
Expand Down Expand Up @@ -635,7 +635,7 @@ pub fn check_variants(files: &[Path], cx: Context) {
}

let s = @result::get(&io::read_whole_file_str(file));
if contains(*s, ~"#") {
if contains(*s, "#") {
loop; // Macros are confusing
}
if cx.mode == tm_converge && content_might_not_converge(*s) {
Expand Down

1 comment on commit 70222b7

@thestinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.