[llvm] r264473 - [Object] Make createMachOObjectFile return Expected<...> rather than
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 25 16:11:52 PDT 2016
Author: lhames
Date: Fri Mar 25 18:11:52 2016
New Revision: 264473
URL: http://llvm.org/viewvc/llvm-project?rev=264473&view=rev
Log:
[Object] Make createMachOObjectFile return Expected<...> rather than
ErrorOr<...>.
Modified:
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/lib/Object/MachOUniversal.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=264473&r1=264472&r2=264473&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Fri Mar 25 18:11:52 2016
@@ -296,7 +296,7 @@ public:
static ErrorOr<std::unique_ptr<ObjectFile>>
createELFObjectFile(MemoryBufferRef Object);
- static ErrorOr<std::unique_ptr<MachOObjectFile>>
+ static Expected<std::unique_ptr<MachOObjectFile>>
createMachOObjectFile(MemoryBufferRef Object);
};
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=264473&r1=264472&r2=264473&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Mar 25 18:11:52 2016
@@ -2421,21 +2421,18 @@ bool MachOObjectFile::isRelocatableObjec
return getHeader().filetype == MachO::MH_OBJECT;
}
-ErrorOr<std::unique_ptr<MachOObjectFile>>
+Expected<std::unique_ptr<MachOObjectFile>>
ObjectFile::createMachOObjectFile(MemoryBufferRef Buffer) {
StringRef Magic = Buffer.getBuffer().slice(0, 4);
if (Magic == "\xFE\xED\xFA\xCE")
- return expectedToErrorOr(
- MachOObjectFile::create(Buffer, false, false));
+ return MachOObjectFile::create(Buffer, false, false);
else if (Magic == "\xCE\xFA\xED\xFE")
- return expectedToErrorOr(
- MachOObjectFile::create(Buffer, true, false));
+ return MachOObjectFile::create(Buffer, true, false);
else if (Magic == "\xFE\xED\xFA\xCF")
- return expectedToErrorOr(
- MachOObjectFile::create(Buffer, false, true));
+ return MachOObjectFile::create(Buffer, false, true);
else if (Magic == "\xCF\xFA\xED\xFE")
- return expectedToErrorOr(
- MachOObjectFile::create(Buffer, true, true));
+ return MachOObjectFile::create(Buffer, true, true);
//else
- return object_error::parse_failed;
+ return malformedError(Buffer.getBufferIdentifier(),
+ "Unrecognized MachO magic number");
}
Modified: llvm/trunk/lib/Object/MachOUniversal.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOUniversal.cpp?rev=264473&r1=264472&r2=264473&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOUniversal.cpp (original)
+++ llvm/trunk/lib/Object/MachOUniversal.cpp Fri Mar 25 18:11:52 2016
@@ -76,7 +76,7 @@ MachOUniversalBinary::ObjectForArch::get
StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
StringRef ObjectName = Parent->getFileName();
MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
- return ObjectFile::createMachOObjectFile(ObjBuffer);
+ return expectedToErrorOr(ObjectFile::createMachOObjectFile(ObjBuffer));
}
ErrorOr<std::unique_ptr<Archive>>
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=264473&r1=264472&r2=264473&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Fri Mar 25 18:11:52 2016
@@ -96,7 +96,7 @@ ObjectFile::createObjectFile(MemoryBuffe
case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
case sys::fs::file_magic::macho_dsym_companion:
case sys::fs::file_magic::macho_kext_bundle:
- return createMachOObjectFile(Object);
+ return expectedToErrorOr(createMachOObjectFile(Object));
case sys::fs::file_magic::coff_object:
case sys::fs::file_magic::coff_import_library:
case sys::fs::file_magic::pecoff_executable:
More information about the llvm-commits
mailing list