Removed ScummVM's private alloc / free / realloc functions. If I break

something, just yell :-)

svn-id: r4160
This commit is contained in:
Lionel Ulmer 2002-05-01 17:16:47 +00:00
parent 75f0674e46
commit 7fa28ffec2
7 changed files with 36 additions and 78 deletions

View file

@ -72,7 +72,7 @@ keys(0), values(0), nkeys(0)
hashconfig::~hashconfig()
{
Scumm::free(domain);
free(domain);
}
bool hashconfig::is_domain(const char *d) const
@ -99,14 +99,14 @@ const char *hashconfig::set(const char *key, const char *value)
for (i = 0; i < nkeys; i++) {
if (!strcmp(key, keys[i])) {
Scumm::free(values[i]);
free(values[i]);
return values[i] = value ? Scumm::Strdup(value) : 0;
}
}
nkeys++;
keys = (char **)Scumm::realloc(keys, nkeys * sizeof(char *));
values = (char **)Scumm::realloc(values, nkeys * sizeof(char *));
keys = (char **)realloc(keys, nkeys * sizeof(char *));
values = (char **)realloc(values, nkeys * sizeof(char *));
keys[nkeys - 1] = Scumm::Strdup(key);
return values[nkeys - 1] = value ? Scumm::Strdup(value) : 0;
}
@ -135,7 +135,7 @@ void hashconfig::flush(FILE * cfg_file) const
void hashconfig::rename(const char *d)
{
Scumm::free(domain);
free(domain);
domain = d ? Scumm::Strdup(d) : 0;
}
@ -208,13 +208,13 @@ Config::~Config()
{
int i;
Scumm::free(filename);
Scumm::free(domain);
free(filename);
free(domain);
for (i = 0; i < ndomains; i++) {
delete hash[i];
}
Scumm::free(hash);
free(hash);
}
const char *Config::get(const char *key, const char *d) const
@ -248,7 +248,7 @@ const char *Config::set(const char *key, const char *value, const char *d)
ndomains++;
hash =
(hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
(hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
return hash[ndomains - 1]->set(key, value);
@ -272,7 +272,7 @@ const char *Config::set(const char *key, int value_i, const char *d)
ndomains++;
hash =
(hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
(hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
return hash[ndomains - 1]->set(key, value);
@ -281,7 +281,7 @@ const char *Config::set(const char *key, int value_i, const char *d)
void Config::set_domain(const char *d)
{
int i;
Scumm::free(domain);
free(domain);
domain = d ? Scumm::Strdup(d) : 0;
for (i = 0; i < ndomains; i++) {
@ -290,7 +290,7 @@ void Config::set_domain(const char *d)
}
ndomains++;
hash =
(hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
(hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
}
@ -346,7 +346,7 @@ void Config::delete_domain(const char *d)
void Config::change_filename(const char *f)
{
Scumm::free(filename);
free(filename);
filename = f ? Scumm::Strdup(f) : 0;
}
@ -367,7 +367,7 @@ void Config::merge_config(const Config * c)
if (!found) {
ndomains++;
hash =
(hashconfig **) Scumm::realloc(hash, ndomains * sizeof(hashconfig *));
(hashconfig **) realloc(hash, ndomains * sizeof(hashconfig *));
hash[ndomains - 1] = new hashconfig(domain);
hash[ndomains - 1]->merge(c->hash[i]);
}

View file

@ -107,7 +107,7 @@ int main(int argc, char *argv[])
{
char *s = detector.getGameName();
system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s);
Scumm::free(s);
free(s);
}
/* Simon the Sorcerer? */

View file

@ -403,12 +403,12 @@ void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name,
res.num[id] = num;
res.tags[id] = tag;
res.name[id] = name;
res.address[id] = (byte **)alloc(num * sizeof(void *));
res.flags[id] = (byte *)alloc(num * sizeof(byte));
res.address[id] = (byte **)calloc(num, sizeof(void *));
res.flags[id] = (byte *)calloc(num, sizeof(byte));
if (mode) {
res.roomno[id] = (byte *)alloc(num * sizeof(byte));
res.roomoffs[id] = (uint32 *)alloc(num * sizeof(uint32));
res.roomno[id] = (byte *)calloc(num, sizeof(byte));
res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32));
}
}
@ -750,7 +750,7 @@ byte *Scumm::createResource(int type, int idx, uint32 size)
expireResources(size);
CHECK_HEAP ptr = (byte *)alloc(size + sizeof(MemBlkHeader) + SAFETY_AREA);
CHECK_HEAP ptr = (byte *)calloc(size + sizeof(MemBlkHeader) + SAFETY_AREA, 1);
if (ptr == NULL) {
error("Out of memory while allocating %d", size);
}
@ -1133,7 +1133,7 @@ void Scumm::readMAXS()
_numCharsets = fileReadWordLE();
_numCostumes = fileReadWordLE();
_objectRoomTable = (byte *)alloc(_numGlobalObjects);
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
_numGlobalScripts = 2000;
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
@ -1182,7 +1182,7 @@ void Scumm::readMAXS()
}
if (_shadowPaletteSize)
_shadowPalette = (byte *)alloc(_shadowPaletteSize);
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
allocateArrays();
_dynamicRoomOffsets = 1;
@ -1193,17 +1193,17 @@ void Scumm::allocateArrays()
// Note: Buffers are now allocated in scummMain to allow for
// early GUI init.
_objectOwnerTable = (byte *)alloc(_numGlobalObjects);
_objectStateTable = (byte *)alloc(_numGlobalObjects);
_classData = (uint32 *)alloc(_numGlobalObjects * sizeof(uint32));
_arrays = (byte *)alloc(_numArray);
_newNames = (uint16 *)alloc(_numNewNames * sizeof(uint16));
_objectOwnerTable = (byte *)calloc(_numGlobalObjects, 1);
_objectStateTable = (byte *)calloc(_numGlobalObjects, 1);
_classData = (uint32 *)calloc(_numGlobalObjects, sizeof(uint32));
_arrays = (byte *)calloc(_numArray, 1);
_newNames = (uint16 *)calloc(_numNewNames, sizeof(uint16));
_inventory = (uint16 *)alloc(_numInventory * sizeof(uint16));
_verbs = (VerbSlot *)alloc(_numVerbs * sizeof(VerbSlot));
_objs = (ObjectData *)alloc(_numLocalObjects * sizeof(ObjectData));
_vars = (int16 *) alloc(_numVariables * sizeof(int16));
_bitVars = (byte *)alloc(_numBitVariables >> 3);
_inventory = (uint16 *)calloc(_numInventory, sizeof(uint16));
_verbs = (VerbSlot *)calloc(_numVerbs, sizeof(VerbSlot));
_objs = (ObjectData *)calloc(_numLocalObjects, sizeof(ObjectData));
_vars = (int16 *) calloc(_numVariables, sizeof(int16));
_bitVars = (byte *)calloc(_numBitVariables >> 3, 1);
allocResTypeData(rtCostume,
(_features & GF_NEW_COSTUMES) ? MKID('AKOS') :

View file

@ -1351,9 +1351,6 @@ public:
uint fileReadWordLE(void *handle);
uint fileReadWordBE(void *handle);
static byte *alloc(int size);
static byte *realloc(void *mem, int size);
static void free(void *mem);
static char *Strdup(const char *);
/* Version 5 script opcodes */

View file

@ -711,8 +711,8 @@ void Scumm::decompressBundleSound(int index) {
unsigned char *p;
fileSeek(_sfxFile, bundle_table[index].offset + table[i].offset, SEEK_SET);
CompInput = (unsigned char *)alloc(table[i].size);
CompOutput = (unsigned char *)alloc(10000);
CompInput = (unsigned char *)malloc(table[i].size);
CompOutput = (unsigned char *)malloc(10000);
fileRead((FILE *)_sfxFile, CompInput, table[i].size);

41
sys.cpp
View file

@ -201,50 +201,11 @@ uint32 Scumm::fileReadDwordBE(void *handle)
return (b << 16) | a;
}
byte *Scumm::alloc(int size)
{
byte *me = (byte *)::calloc(size + 4, 1);
if (me == NULL)
return NULL;
*((uint32 *)me) = 0xDEADBEEF;
return me + 4;
}
void Scumm::free(void *mem)
{
if (mem) {
byte *me = (byte *)mem - 4;
if (*((uint32 *)me) != 0xDEADBEEF) {
error("Freeing invalid block.");
}
*((uint32 *)me) = 0xC007CAFE;
::free(me);
}
}
byte *Scumm::realloc(void *mem, int size)
{
byte * me = (byte *) mem;
if (mem) {
if (size) {
me = (byte *) ::realloc((me - 4), size + 4);
return me + 4;
} else {
free(me);
return NULL;
}
} else {
return alloc(size);
}
}
char *Scumm::Strdup(const char *s)
{
if (s) {
int l = strlen(s) + 1;
char * r = (char *) alloc(l);
char * r = (char *) malloc(l);
memcpy(r, s, l);
return r;
}

View file

@ -82,7 +82,7 @@ void Scumm_v3::readIndexFile()
_numGlobalScripts = 200;
_shadowPaletteSize = 256;
_shadowPalette = (byte *)alloc(_shadowPaletteSize); // stupid for now. Need to be removed later
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1); // stupid for now. Need to be removed later
_numFlObject = 50;
allocateArrays();