diff options
author | Filippos Karapetis | 2010-05-18 13:05:09 +0000 |
---|---|---|
committer | Filippos Karapetis | 2010-05-18 13:05:09 +0000 |
commit | f3892a506b2f935bae0be6319394c503c786d368 (patch) | |
tree | 2edf8570fa4076c0af6aec863999dbf6cc3daddd /engines/sci/engine/seg_manager.cpp | |
parent | e3297ef2cad4b0efc4b262d73b1be4630497dd4a (diff) | |
download | scummvm-rg350-f3892a506b2f935bae0be6319394c503c786d368.tar.gz scummvm-rg350-f3892a506b2f935bae0be6319394c503c786d368.tar.bz2 scummvm-rg350-f3892a506b2f935bae0be6319394c503c786d368.zip |
- Removed the wrapper kalloc, kmem and kfree functions. Now, the associated Segment manager functions allocateHunkEntry, getHunkPointer and freeHunkEntry are used directly (which are more descriptive, anyway)
- Replaced the GET_SEGMENT macro by a method of the segment manager
- Removed the unused reference to the created hunk in allocateHunkEntry(), only the reg_t reference to it is returned now
svn-id: r49078
Diffstat (limited to 'engines/sci/engine/seg_manager.cpp')
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 6a30d54ca4..12398ce686 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -207,6 +207,10 @@ SegmentType SegManager::getSegmentType(SegmentId seg) { return _heap[seg]->getType(); } +SegmentObj *SegManager::getSegment(SegmentId seg, SegmentType type) { + return getSegmentType(seg) == type ? _heap[seg] : NULL; +} + Object *SegManager::getObject(reg_t pos) { SegmentObj *mobj = getSegmentObj(pos.segment); Object *obj = NULL; @@ -399,7 +403,12 @@ SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) { } void SegManager::freeHunkEntry(reg_t addr) { - HunkTable *ht = (HunkTable *)GET_SEGMENT(*this, addr.segment, SEG_TYPE_HUNK); + if (addr.isNull()) { + warning("Attempt to free a Hunk from a null address"); + return; + } + + HunkTable *ht = (HunkTable *)getSegment(addr.segment, SEG_TYPE_HUNK); if (!ht) { warning("Attempt to free Hunk from address %04x:%04x: Invalid segment type", PRINT_REG(addr)); @@ -409,7 +418,7 @@ void SegManager::freeHunkEntry(reg_t addr) { ht->freeEntry(addr.offset); } -Hunk *SegManager::allocateHunkEntry(const char *hunk_type, int size, reg_t *addr) { +reg_t SegManager::allocateHunkEntry(const char *hunk_type, int size) { HunkTable *table; int offset; @@ -419,17 +428,28 @@ Hunk *SegManager::allocateHunkEntry(const char *hunk_type, int size, reg_t *addr offset = table->allocEntry(); - *addr = make_reg(Hunks_seg_id, offset); + reg_t addr = make_reg(Hunks_seg_id, offset); Hunk *h = &(table->_table[offset]); if (!h) - return NULL; + return NULL_REG; h->mem = malloc(size); h->size = size; h->type = hunk_type; - return h; + return addr; +} + +byte *SegManager::getHunkPointer(reg_t addr) { + HunkTable *ht = (HunkTable *)getSegment(addr.segment, SEG_TYPE_HUNK); + + if (!ht || !ht->isValidEntry(addr.offset)) { + warning("getHunkPointer() with invalid handle"); + return NULL; + } + + return (byte *)ht->_table[addr.offset].mem; } Clone *SegManager::allocateClone(reg_t *addr) { |