PLUGINS: used variation of ScopedPtr to clean up load() function
svn-id: r52592
This commit is contained in:
parent
b77fd21969
commit
c2cafe426e
2 changed files with 32 additions and 24 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
#include "common/fs.h"
|
#include "common/fs.h"
|
||||||
|
#include "common/ptr.h"
|
||||||
|
|
||||||
DLObject::DLObject() :
|
DLObject::DLObject() :
|
||||||
_file(0),
|
_file(0),
|
||||||
|
@ -303,8 +304,6 @@ void DLObject::relocateSymbols(ptrdiff_t offset) {
|
||||||
bool DLObject::load() {
|
bool DLObject::load() {
|
||||||
Elf32_Ehdr ehdr;
|
Elf32_Ehdr ehdr;
|
||||||
Elf32_Phdr phdr;
|
Elf32_Phdr phdr;
|
||||||
Elf32_Shdr *shdr;
|
|
||||||
bool ret = true;
|
|
||||||
|
|
||||||
if (readElfHeader(&ehdr) == false)
|
if (readElfHeader(&ehdr) == false)
|
||||||
return false;
|
return false;
|
||||||
|
@ -319,29 +318,26 @@ bool DLObject::load() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shdr = loadSectionHeaders(&ehdr);
|
Common::ScopedPtrC<Elf32_Shdr> shdr(loadSectionHeaders(&ehdr));
|
||||||
if (!shdr)
|
if (!shdr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (ret && ((_symtab_sect = loadSymbolTable(&ehdr, shdr)) < 0))
|
_symtab_sect = loadSymbolTable(&ehdr, shdr);
|
||||||
ret = false;
|
if (_symtab_sect < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (ret && !loadStringTable(shdr))
|
if (!loadStringTable(shdr))
|
||||||
ret = false;
|
return false;
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
// Offset by our segment allocated address
|
// Offset by our segment allocated address
|
||||||
// must use _segmentVMA here for multiple segments (MIPS)
|
// must use _segmentVMA here for multiple segments (MIPS)
|
||||||
_segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
|
_segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
|
||||||
relocateSymbols(_segmentOffset);
|
relocateSymbols(_segmentOffset);
|
||||||
}
|
|
||||||
|
|
||||||
if (ret && !relocateRels(&ehdr, shdr))
|
if (!relocateRels(&ehdr, shdr))
|
||||||
ret = false;
|
return false;
|
||||||
|
|
||||||
free(shdr);
|
return true;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DLObject::open(const char *path) {
|
bool DLObject::open(const char *path) {
|
||||||
|
|
18
common/ptr.h
18
common/ptr.h
|
@ -236,21 +236,24 @@ public:
|
||||||
PointerType operator->() const { return _pointer; }
|
PointerType operator->() const { return _pointer; }
|
||||||
operator PointerType() const { return _pointer; }
|
operator PointerType() const { return _pointer; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implicit conversion operator to bool for convenience, to make
|
* Implicit conversion operator to bool for convenience, to make
|
||||||
* checks like "if (scopedPtr) ..." possible.
|
* checks like "if (scopedPtr) ..." possible.
|
||||||
*/
|
*/
|
||||||
operator bool() const { return _pointer != 0; }
|
operator bool() const { return _pointer != 0; }
|
||||||
|
|
||||||
|
void deletePointer() { delete _pointer; }
|
||||||
|
|
||||||
~ScopedPtr() {
|
~ScopedPtr() {
|
||||||
delete _pointer;
|
deletePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the pointer with the new value. Old object will be destroyed
|
* Resets the pointer with the new value. Old object will be destroyed
|
||||||
*/
|
*/
|
||||||
void reset(PointerType o = 0) {
|
void reset(PointerType o = 0) {
|
||||||
delete _pointer;
|
deletePointer();
|
||||||
_pointer = o;
|
_pointer = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,10 +276,19 @@ public:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
PointerType _pointer;
|
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
|
} // End of namespace Common
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue