Skip to content

Commit

Permalink
rustc: Get LLVM error message safely
Browse files Browse the repository at this point in the history
On Windows, `LLVMRustGetLastError()` may return non-utf8 mojibake string
if system uses non-English locale. It caused ICE when llvm fails.
This patch doesn't fix the real problem, but just make rustc not die.
  • Loading branch information
klutzy committed Mar 6, 2014
1 parent 0a7b06e commit f6afd40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use util::common::time;
use util::ppaux;
use util::sha2::{Digest, Sha256};

use std::c_str::ToCStr;
use std::c_str::{ToCStr, CString};
use std::char;
use std::os::consts::{macos, freebsd, linux, android, win32};
use std::ptr;
Expand Down Expand Up @@ -61,7 +61,9 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
if cstr == ptr::null() {
sess.fatal(msg);
} else {
sess.fatal(msg + ": " + str::raw::from_c_str(cstr));
let err = CString::new(cstr, false);
let err = str::from_utf8_lossy(err.as_bytes());
sess.fatal(msg + ": " + err.as_slice());
}
}
}
Expand Down

5 comments on commit f6afd40

@bors
Copy link
Contributor

@bors bors commented on f6afd40 Mar 6, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at klutzy@f6afd40

@bors
Copy link
Contributor

@bors bors commented on f6afd40 Mar 6, 2014

Choose a reason for hiding this comment

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

merging klutzy/rust/this-is-windows = f6afd40 into auto

@bors
Copy link
Contributor

@bors bors commented on f6afd40 Mar 6, 2014

Choose a reason for hiding this comment

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

klutzy/rust/this-is-windows = f6afd40 merged ok, testing candidate = 987de29

@bors
Copy link
Contributor

@bors bors commented on f6afd40 Mar 6, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on f6afd40 Mar 6, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 987de29

Please sign in to comment.