unique_ptrify RuntimeDyldImpl::loadObject
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 3 Sep 2014 21:34:34 +0000 (21:34 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 3 Sep 2014 21:34:34 +0000 (21:34 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217081 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

index 1f326d8c4787fd1ac6fa18188b473b4ee5790c50..895ba05bccd8da2240c32e463bd72a2b35b6a1ae 100644 (file)
@@ -137,10 +137,10 @@ static std::error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
   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(ObjectImage *InputObject) {
   // 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<ObjectFile> InputObject) {
   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<ObjectBuffer> InputBuffer) {
   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) {
index d2c58eb0a64b49b96f68544d906dc4d5876e0a4a..53ea370196d734bebc78a9d2d65dceb30b10db3d 100644 (file)
@@ -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.