mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-15 00:16:42 +00:00
[dlltool] Make memory buffer ownership less weird.
There's no reason to destroy them in a global destructor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311287 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4a05fa1f1b
commit
1c8117b2ed
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user