From 1e321bba6e1b51965406764653f69c846dc0573a Mon Sep 17 00:00:00 2001 From: Dylan Noblesmith Date: Mon, 25 Aug 2014 00:58:18 +0000 Subject: [PATCH] ExecutionEngine: unique_ptr-ify NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/ExecutionEngine.cpp | 32 ++++++++++--------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index f112e08b42b..b31814a1753 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -256,19 +256,9 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { namespace { class ArgvArray { - char *Array; - std::vector Values; + std::unique_ptr Array; + std::vector> Values; public: - ArgvArray() : Array(nullptr) {} - ~ArgvArray() { clear(); } - void clear() { - delete[] Array; - Array = nullptr; - for (size_t I = 0, E = Values.size(); I != E; ++I) { - delete[] Values[I]; - } - Values.clear(); - } /// Turn a vector of strings into a nice argv style array of pointers to null /// terminated strings. void *reset(LLVMContext &C, ExecutionEngine *EE, @@ -277,32 +267,34 @@ public: } // anonymous namespace void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE, const std::vector &InputArgv) { - clear(); // Free the old contents. + Values.clear(); // Free the old contents. + Values.reserve(InputArgv.size()); unsigned PtrSize = EE->getDataLayout()->getPointerSize(); - Array = new char[(InputArgv.size()+1)*PtrSize]; + Array = make_unique((InputArgv.size()+1)*PtrSize); - DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array << "\n"); + DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n"); Type *SBytePtr = Type::getInt8PtrTy(C); for (unsigned i = 0; i != InputArgv.size(); ++i) { unsigned Size = InputArgv[i].size()+1; - char *Dest = new char[Size]; - Values.push_back(Dest); + auto DestOwner = make_unique(Size); + char *Dest = DestOwner.get(); + Values.push_back(std::move(DestOwner)); DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest << "\n"); std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest); Dest[Size-1] = 0; // Endian safe: Array[i] = (PointerTy)Dest; - EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Array+i*PtrSize), + EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(&Array[i*PtrSize]), SBytePtr); } // Null terminate it EE->StoreValueToMemory(PTOGV(nullptr), - (GenericValue*)(Array+InputArgv.size()*PtrSize), + (GenericValue*)(&Array[InputArgv.size()*PtrSize]), SBytePtr); - return Array; + return Array.get(); } void ExecutionEngine::runStaticConstructorsDestructors(Module &module,