diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-29 00:02:26 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-29 00:02:26 +0000 |
commit | 07dc57c38ac3b933860380c0d8c3fc7b9a830662 (patch) | |
tree | 69370e650f372431d726305e1dfdad696c21da9d | |
parent | bf2b27cfdee1e564016a2808a23f22b406989ae3 (diff) | |
download | llvm-07dc57c38ac3b933860380c0d8c3fc7b9a830662.tar.gz llvm-07dc57c38ac3b933860380c0d8c3fc7b9a830662.tar.bz2 llvm-07dc57c38ac3b933860380c0d8c3fc7b9a830662.tar.xz |
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
-rw-r--r-- | include/llvm/Object/ObjectFile.h | 10 | ||||
-rw-r--r-- | lib/Object/Binary.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-ar/llvm-ar.cpp | 3 |
3 files changed, 10 insertions, 5 deletions
diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 806de34e76..7533d625b1 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -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(); diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index a2f4ec9a0b..63898d277f 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -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: diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 944cce408f..8917cd3801 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -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(); |