Skip to content

Commit

Permalink
llvm::mk_object_file should really return an option, since the underl…
Browse files Browse the repository at this point in the history
…ying LLVM function can fail. Fixes a crash on OS X when rust has bad dylibs within eyeshot.
  • Loading branch information
jwise authored and marijnh committed Nov 7, 2011
1 parent ba57ec2 commit 07bab92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/comp/lib/llvm.rs
@@ -1,4 +1,4 @@
import std::{vec, str};
import std::{vec, str, option};
import std::str::sbuf;

import llvm::{ModuleRef, ContextRef, TypeRef, TypeHandleRef, ValueRef,
Expand Down Expand Up @@ -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. */
Expand Down
5 changes: 4 additions & 1 deletion src/comp/metadata/creader.rs
Expand Up @@ -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);
Expand Down

0 comments on commit 07bab92

Please sign in to comment.