llvm::mk_object_file should really return an option, since the underlying LLVM function can fail. Fixes a crash on OS X when rust has bad dylibs within eyeshot.
This commit is contained in:
parent
ba57ec24ea
commit
07bab92970
2 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
import std::{vec, str};
|
||||
import std::{vec, str, option};
|
||||
import std::str::sbuf;
|
||||
|
||||
import llvm::{ModuleRef, ContextRef, TypeRef, TypeHandleRef, ValueRef,
|
||||
|
@ -1057,9 +1057,10 @@ resource object_file_res(ObjectFile: ObjectFileRef) {
|
|||
|
||||
type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
|
||||
|
||||
fn mk_object_file(llmb: MemoryBufferRef) -> object_file {
|
||||
fn mk_object_file(llmb: MemoryBufferRef) -> option::t<object_file> {
|
||||
let llof = llvm::LLVMCreateObjectFile(llmb);
|
||||
ret {llof: llof, dtor: @object_file_res(llof)};
|
||||
if llof as int == 0 { ret option::none::<object_file>; }
|
||||
ret option::some::<object_file>({llof: llof, dtor: @object_file_res(llof)});
|
||||
}
|
||||
|
||||
/* Memory-managed interface to section iterators. */
|
||||
|
|
|
@ -175,7 +175,10 @@ fn get_metadata_section(sess: session::session,
|
|||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
});
|
||||
if mb as int == 0 { ret option::none::<@[u8]>; }
|
||||
let of = mk_object_file(mb);
|
||||
let of = alt mk_object_file(mb) {
|
||||
option::some(of) { of }
|
||||
_ { ret option::none::<@[u8]>; }
|
||||
};
|
||||
let si = mk_section_iter(of.llof);
|
||||
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
|
||||
let name_buf = llvm::LLVMGetSectionName(si.llsi);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue