[llvm] r217081 - unique_ptrify RuntimeDyldImpl::loadObject

David Blaikie dblaikie at gmail.com
Wed Sep 3 14:34:35 PDT 2014


Author: dblaikie
Date: Wed Sep  3 16:34:34 2014
New Revision: 217081

URL: http://llvm.org/viewvc/llvm-project?rev=217081&view=rev
Log:
unique_ptrify RuntimeDyldImpl::loadObject

I'm not sure this is a particularly helpful API (to pass ownership and
then return it unconditionally) rather than just pass the underlying
object by non-const reference, but this was the original API so I'll
just make it more safe/stable and anyone else is free to adjust that at
their whim, of course.

Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=217081&r1=217080&r2=217081&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Wed Sep  3 16:34:34 2014
@@ -137,10 +137,10 @@ static std::error_code getOffset(const S
   return object_error::success;
 }
 
-ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
+std::unique_ptr<ObjectImage>
+RuntimeDyldImpl::loadObject(std::unique_ptr<ObjectImage> Obj) {
   MutexGuard locked(lock);
 
-  std::unique_ptr<ObjectImage> Obj(InputObject);
   if (!Obj)
     return nullptr;
 
@@ -250,7 +250,7 @@ ObjectImage *RuntimeDyldImpl::loadObject
   // Give the subclasses a chance to tie-up any loose ends.
   finalizeLoad(*Obj, LocalSections);
 
-  return Obj.release();
+  return Obj;
 }
 
 // A helper method for computeTotalAllocSize.
@@ -816,8 +816,7 @@ RuntimeDyld::loadObject(std::unique_ptr<
   if (!Dyld->isCompatibleFile(&Obj))
     report_fatal_error("Incompatible object format!");
 
-  Dyld->loadObject(InputImage.get());
-  return InputImage;
+  return Dyld->loadObject(std::move(InputImage));
 }
 
 std::unique_ptr<ObjectImage>
@@ -865,8 +864,7 @@ RuntimeDyld::loadObject(std::unique_ptr<
   if (!Dyld->isCompatibleFormat(InputBufferPtr))
     report_fatal_error("Incompatible object format!");
 
-  Dyld->loadObject(InputImage.get());
-  return InputImage;
+  return Dyld->loadObject(std::move(InputImage));
 }
 
 void *RuntimeDyld::getSymbolAddress(StringRef Name) {

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h?rev=217081&r1=217080&r2=217081&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h Wed Sep  3 16:34:34 2014
@@ -373,7 +373,8 @@ public:
     this->Checker = Checker;
   }
 
-  ObjectImage *loadObject(ObjectImage *InputObject);
+  std::unique_ptr<ObjectImage>
+  loadObject(std::unique_ptr<ObjectImage> InputObject);
 
   uint8_t* getSymbolAddress(StringRef Name) {
     // FIXME: Just look up as a function for now. Overly simple of course.





More information about the llvm-commits mailing list