Make createObjectFile's signature a bit less error prone.

This will be better with c++11, but right now file_magic converts to bool,
which makes the api really easy to misuse.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200357 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-01-29 00:02:26 +00:00
parent bf2b27cfde
commit 07dc57c38a
3 changed files with 10 additions and 5 deletions

View File

@ -378,9 +378,13 @@ public:
/// return true.
/// @brief Create ObjectFile from path.
static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
static ErrorOr<ObjectFile *>
createObjectFile(MemoryBuffer *Object, bool BufferOwned = true,
sys::fs::file_magic Type = sys::fs::file_magic::unknown);
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object,
bool BufferOwned,
sys::fs::file_magic Type);
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object) {
return createObjectFile(Object, true, sys::fs::file_magic::unknown);
}
static inline bool classof(const Binary *v) {
return v->isObject();

View File

@ -67,7 +67,7 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source,
case sys::fs::file_magic::coff_object:
case sys::fs::file_magic::coff_import_library:
case sys::fs::file_magic::pecoff_executable:
return ObjectFile::createObjectFile(scopedSource.take(), Type);
return ObjectFile::createObjectFile(scopedSource.take(), true, Type);
case sys::fs::file_magic::macho_universal_binary:
return MachOUniversalBinary::create(scopedSource.take());
case sys::fs::file_magic::unknown:

View File

@ -703,7 +703,8 @@ static void writeSymbolTable(
I != E; ++I, ++MemberNum) {
MemoryBuffer *MemberBuffer = Buffers[MemberNum];
ErrorOr<object::ObjectFile *> ObjOrErr =
object::ObjectFile::createObjectFile(MemberBuffer, false);
object::ObjectFile::createObjectFile(MemberBuffer, false,
sys::fs::file_magic::unknown);
if (!ObjOrErr)
continue; // FIXME: check only for "not an object file" errors.
object::ObjectFile *Obj = ObjOrErr.get();