aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Barnoy2010-09-06 13:31:27 +0000
committerYotam Barnoy2010-09-06 13:31:27 +0000
commitc2cafe426e8216d46a70b479ff0071a8b66b9327 (patch)
tree223dd11370e86b75984cf13b3c6bd72d200b9d61
parentb77fd21969eba7e30dfc1b959746af6dfcb3f328 (diff)
downloadscummvm-rg350-c2cafe426e8216d46a70b479ff0071a8b66b9327.tar.gz
scummvm-rg350-c2cafe426e8216d46a70b479ff0071a8b66b9327.tar.bz2
scummvm-rg350-c2cafe426e8216d46a70b479ff0071a8b66b9327.zip
PLUGINS: used variation of ScopedPtr to clean up load() function
svn-id: r52592
-rw-r--r--backends/plugins/elf/elf-loader.cpp36
-rw-r--r--common/ptr.h20
2 files changed, 32 insertions, 24 deletions
diff --git a/backends/plugins/elf/elf-loader.cpp b/backends/plugins/elf/elf-loader.cpp
index f4226b4187..32eae2cba8 100644
--- a/backends/plugins/elf/elf-loader.cpp
+++ b/backends/plugins/elf/elf-loader.cpp
@@ -30,6 +30,7 @@
#include "common/debug.h"
#include "common/file.h"
#include "common/fs.h"
+#include "common/ptr.h"
DLObject::DLObject() :
_file(0),
@@ -303,8 +304,6 @@ void DLObject::relocateSymbols(ptrdiff_t offset) {
bool DLObject::load() {
Elf32_Ehdr ehdr;
Elf32_Phdr phdr;
- Elf32_Shdr *shdr;
- bool ret = true;
if (readElfHeader(&ehdr) == false)
return false;
@@ -319,29 +318,26 @@ bool DLObject::load() {
return false;
}
- shdr = loadSectionHeaders(&ehdr);
+ Common::ScopedPtrC<Elf32_Shdr> shdr(loadSectionHeaders(&ehdr));
if (!shdr)
return false;
- if (ret && ((_symtab_sect = loadSymbolTable(&ehdr, shdr)) < 0))
- ret = false;
-
- if (ret && !loadStringTable(shdr))
- ret = false;
-
- if (ret) {
- // Offset by our segment allocated address
- // must use _segmentVMA here for multiple segments (MIPS)
- _segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
- relocateSymbols(_segmentOffset);
- }
-
- if (ret && !relocateRels(&ehdr, shdr))
- ret = false;
+ _symtab_sect = loadSymbolTable(&ehdr, shdr);
+ if (_symtab_sect < 0)
+ return false;
+
+ if (!loadStringTable(shdr))
+ return false;
+
+ // Offset by our segment allocated address
+ // must use _segmentVMA here for multiple segments (MIPS)
+ _segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
+ relocateSymbols(_segmentOffset);
- free(shdr);
+ if (!relocateRels(&ehdr, shdr))
+ return false;
- return ret;
+ return true;
}
bool DLObject::open(const char *path) {
diff --git a/common/ptr.h b/common/ptr.h
index 7307038936..524879652c 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -235,6 +235,7 @@ public:
ReferenceType operator*() const { return *_pointer; }
PointerType operator->() const { return _pointer; }
operator PointerType() const { return _pointer; }
+
/**
* Implicit conversion operator to bool for convenience, to make
@@ -242,15 +243,17 @@ public:
*/
operator bool() const { return _pointer != 0; }
+ void deletePointer() { delete _pointer; }
+
~ScopedPtr() {
- delete _pointer;
+ deletePointer();
}
/**
* Resets the pointer with the new value. Old object will be destroyed
*/
void reset(PointerType o = 0) {
- delete _pointer;
+ deletePointer();
_pointer = o;
}
@@ -273,10 +276,19 @@ public:
return r;
}
-private:
- PointerType _pointer;
+protected:
+ PointerType _pointer;
};
+template<typename T>
+class ScopedPtrC : public ScopedPtr<T> {
+public:
+ typedef T *PointerType;
+
+ explicit ScopedPtrC(PointerType o = 0) : ScopedPtr<T>(o) {}
+
+ void deletePointer() { free(ScopedPtr<T>::_pointer); }
+};
} // End of namespace Common