mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-16 21:50:21 +00:00
CRUISE: Replace casts and offset calculations for memory debugger by a simple struct.
This commit is contained in:
parent
08ad90edf6
commit
715c07930d
@ -108,7 +108,15 @@ public:
|
|||||||
|
|
||||||
Common::RandomSource _rnd;
|
Common::RandomSource _rnd;
|
||||||
|
|
||||||
Common::List<byte *> _memList;
|
struct MemInfo {
|
||||||
|
int32 lineNum;
|
||||||
|
char fname[64];
|
||||||
|
uint32 magic;
|
||||||
|
|
||||||
|
static uint32 const cookie = 0x41424344;
|
||||||
|
};
|
||||||
|
|
||||||
|
Common::List<MemInfo*> _memList;
|
||||||
|
|
||||||
typedef Common::List<Common::Rect> RectList;
|
typedef Common::List<Common::Rect> RectList;
|
||||||
|
|
||||||
|
@ -40,19 +40,21 @@ unsigned int timer = 0;
|
|||||||
|
|
||||||
gfxEntryStruct* linkedMsgList = NULL;
|
gfxEntryStruct* linkedMsgList = NULL;
|
||||||
|
|
||||||
|
typedef CruiseEngine::MemInfo MemInfo;
|
||||||
|
|
||||||
void MemoryList() {
|
void MemoryList() {
|
||||||
if (!_vm->_memList.empty()) {
|
if (!_vm->_memList.empty()) {
|
||||||
debug("Current list of un-freed memory blocks:");
|
debug("Current list of un-freed memory blocks:");
|
||||||
Common::List<byte *>::iterator i;
|
Common::List<MemInfo*>::iterator i;
|
||||||
for (i = _vm->_memList.begin(); i != _vm->_memList.end(); ++i) {
|
for (i = _vm->_memList.begin(); i != _vm->_memList.end(); ++i) {
|
||||||
byte *v = *i;
|
MemInfo const *const v = *i;
|
||||||
debug("%s - %d", (const char *)(v - 68), *((int32 *)(v - 72)));
|
debug("%s - %d", v->fname, v->lineNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname) {
|
void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname) {
|
||||||
byte *result;
|
void *result;
|
||||||
|
|
||||||
if (gDebugLevel > 0) {
|
if (gDebugLevel > 0) {
|
||||||
// Find the point after the final slash
|
// Find the point after the final slash
|
||||||
@ -61,17 +63,17 @@ void *MemoryAlloc(uint32 size, bool clearFlag, int32 lineNum, const char *fname)
|
|||||||
--fnameP;
|
--fnameP;
|
||||||
|
|
||||||
// Create the new memory block and add it to the memory list
|
// Create the new memory block and add it to the memory list
|
||||||
byte *v = (byte *)malloc(size + 64 + 8);
|
MemInfo *const v = (MemInfo *)malloc(sizeof(MemInfo) + size);
|
||||||
*((int32 *) v) = lineNum;
|
v->lineNum = lineNum;
|
||||||
strncpy((char *)v + 4, fnameP, 63);
|
strncpy(v->fname, fnameP, sizeof(v->fname));
|
||||||
*((char *)v + 4 + 63) = '\0';
|
v->fname[ARRAYSIZE(v->fname) - 1] = '\0';
|
||||||
*((uint32 *) (v + 68)) = 0x41424344;
|
v->magic = MemInfo::cookie;
|
||||||
|
|
||||||
// Add the block to the memory list
|
// Add the block to the memory list
|
||||||
result = v + 64 + 8;
|
_vm->_memList.push_back(v);
|
||||||
_vm->_memList.push_back(result);
|
result = v + 1;
|
||||||
} else
|
} else
|
||||||
result = (byte *)malloc(size);
|
result = malloc(size);
|
||||||
|
|
||||||
if (clearFlag)
|
if (clearFlag)
|
||||||
memset(result, 0, size);
|
memset(result, 0, size);
|
||||||
@ -84,11 +86,11 @@ void MemoryFree(void *v) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (gDebugLevel > 0) {
|
if (gDebugLevel > 0) {
|
||||||
byte *p = (byte *)v;
|
MemInfo *const p = (MemInfo *)v - 1;
|
||||||
assert(*((uint32 *) (p - 4)) == 0x41424344);
|
assert(p->magic == MemInfo::cookie);
|
||||||
|
|
||||||
_vm->_memList.remove(p);
|
_vm->_memList.remove(p);
|
||||||
free(p - 8 - 64);
|
free(p);
|
||||||
} else
|
} else
|
||||||
free(v);
|
free(v);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user