1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[dlltool] Make memory buffer ownership less weird.

There's no reason to destroy them in a global destructor.

llvm-svn: 311287
This commit is contained in:
Benjamin Kramer 2017-08-20 13:03:32 +00:00
parent bf0706a056
commit e0313d3bd2

View File

@ -56,21 +56,16 @@ public:
} // namespace
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
// Opens a file. Path has to be resolved already.
// Newly created memory buffers are owned by this driver.
Optional<MemoryBufferRef> openFile(StringRef Path) {
static std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) {
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
if (std::error_code EC = MB.getError()) {
llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";
return None;
return nullptr;
}
MemoryBufferRef MBRef = MB.get()->getMemBufferRef();
OwningMBs.push_back(std::move(MB.get())); // take ownership
return MBRef;
return std::move(*MB);
}
static MachineTypes getEmulation(StringRef S) {
@ -82,7 +77,7 @@ static MachineTypes getEmulation(StringRef S) {
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
}
static std::string getImplibPath(std::string Path) {
static std::string getImplibPath(StringRef Path) {
SmallString<128> Out = StringRef("lib");
Out.append(Path);
sys::path::replace_extension(Out, ".a");
@ -122,7 +117,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
return 1;
}
Optional<MemoryBufferRef> MB = openFile(Args.getLastArg(OPT_d)->getValue());
std::unique_ptr<MemoryBuffer> MB =
openFile(Args.getLastArg(OPT_d)->getValue());
if (!MB)
return 1;