Skip to content
Permalink
Browse files
All memory management now goes through allocation hooks instead of di…
…rectly to

 C runtime malloc/realloc/free...
  • Loading branch information
icculus committed Mar 14, 2005
1 parent 4787894 commit d840403c1c51fcbc3e949be6599010b04fc912b5
Showing with 419 additions and 260 deletions.
  1. +11 −11 archivers/dir.c
  2. +12 −12 archivers/grp.c
  3. +12 −12 archivers/hog.c
  4. +11 −11 archivers/mix.c
  5. +12 −12 archivers/mvl.c
  6. +12 −12 archivers/qpak.c
  7. +12 −12 archivers/wad.c
  8. +27 −27 archivers/zip.c
  9. +62 −58 physfs.c
  10. +7 −5 physfs.h
  11. +9 −2 physfs_internal.h
  12. +1 −0 platform/Makefile.am
  13. +43 −9 platform/macclassic.c
  14. +8 −7 platform/os2.c
  15. +57 −25 platform/pocketpc.c
  16. +16 −13 platform/posix.c
  17. +33 −0 platform/skeleton.c
  18. +21 −13 platform/unix.c
  19. +53 −19 platform/win32.c
@@ -91,7 +91,7 @@ static void *DIR_openArchive(const char *name, int forWriting)
BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
ERR_UNSUPPORTED_ARCHIVE, 0);

retval = malloc(namelen + seplen + 1);
retval = allocator.Malloc(namelen + seplen + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);

/* make sure there's a dir separator at the end of the string */
@@ -111,7 +111,7 @@ static void DIR_enumerateFiles(dvoid *opaque, const char *dname,
if (d != NULL)
{
__PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata);
free(d);
allocator.Free(d);
} /* if */
} /* DIR_enumerateFiles */

@@ -123,7 +123,7 @@ static int DIR_exists(dvoid *opaque, const char *name)

BAIL_IF_MACRO(f == NULL, NULL, 0);
retval = __PHYSFS_platformExists(f);
free(f);
allocator.Free(f);
return(retval);
} /* DIR_exists */

@@ -137,7 +137,7 @@ static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists)
*fileExists = __PHYSFS_platformExists(d);
if (*fileExists)
retval = __PHYSFS_platformIsDirectory(d);
free(d);
allocator.Free(d);
return(retval);
} /* DIR_isDirectory */

@@ -151,7 +151,7 @@ static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists)
*fileExists = __PHYSFS_platformExists(f);
if (*fileExists)
retval = __PHYSFS_platformIsSymLink(f);
free(f);
allocator.Free(f);
return(retval);
} /* DIR_isSymLink */

@@ -167,7 +167,7 @@ static PHYSFS_sint64 DIR_getLastModTime(dvoid *opaque,
*fileExists = __PHYSFS_platformExists(d);
if (*fileExists)
retval = __PHYSFS_platformGetLastModTime(d);
free(d);
allocator.Free(d);
return(retval);
} /* DIR_getLastModTime */

@@ -186,13 +186,13 @@ static fvoid *doOpen(dvoid *opaque, const char *name,
*fileExists = __PHYSFS_platformExists(f);
if (!(*fileExists))
{
free(f);
allocator.Free(f);
return(NULL);
} /* if */
} /* if */

rc = openFunc(f);
free(f);
allocator.Free(f);

return((fvoid *) rc);
} /* doOpen */
@@ -223,7 +223,7 @@ static int DIR_remove(dvoid *opaque, const char *name)

BAIL_IF_MACRO(f == NULL, NULL, 0);
retval = __PHYSFS_platformDelete(f);
free(f);
allocator.Free(f);
return(retval);
} /* DIR_remove */

@@ -235,14 +235,14 @@ static int DIR_mkdir(dvoid *opaque, const char *name)

BAIL_IF_MACRO(f == NULL, NULL, 0);
retval = __PHYSFS_platformMkDir(f);
free(f);
allocator.Free(f);
return(retval);
} /* DIR_mkdir */


static void DIR_dirClose(dvoid *opaque)
{
free(opaque);
allocator.Free(opaque);
} /* DIR_dirClose */


@@ -64,9 +64,9 @@ typedef struct
static void GRP_dirClose(dvoid *opaque)
{
GRPinfo *info = ((GRPinfo *) opaque);
free(info->filename);
free(info->entries);
free(info);
allocator.Free(info->filename);
allocator.Free(info->entries);
allocator.Free(info);
} /* GRP_dirClose */


@@ -138,7 +138,7 @@ static int GRP_fileClose(fvoid *opaque)
{
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
free(finfo);
allocator.Free(finfo);
return(1);
} /* GRP_fileClose */

@@ -221,7 +221,7 @@ static int grp_load_entries(const char *name, int forWriting, GRPinfo *info)

BAIL_IF_MACRO(!grp_open(name, forWriting, &fh, &fileCount), NULL, 0);
info->entryCount = fileCount;
info->entries = (GRPentry *) malloc(sizeof (GRPentry) * fileCount);
info->entries = (GRPentry *) allocator.Malloc(sizeof(GRPentry)*fileCount);
if (info->entries == NULL)
{
__PHYSFS_platformClose(fh);
@@ -264,12 +264,12 @@ static int grp_load_entries(const char *name, int forWriting, GRPinfo *info)
static void *GRP_openArchive(const char *name, int forWriting)
{
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
GRPinfo *info = malloc(sizeof (GRPinfo));
GRPinfo *info = (GRPinfo *) allocator.Malloc(sizeof (GRPinfo));

BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);

memset(info, '\0', sizeof (GRPinfo));
info->filename = (char *) malloc(strlen(name) + 1);
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, GRP_openArchive_failed);

if (!grp_load_entries(name, forWriting, info))
@@ -284,10 +284,10 @@ static void *GRP_openArchive(const char *name, int forWriting)
if (info != NULL)
{
if (info->filename != NULL)
free(info->filename);
allocator.Free(info->filename);
if (info->entries != NULL)
free(info->entries);
free(info);
allocator.Free(info->entries);
allocator.Free(info);
} /* if */

return(NULL);
@@ -390,14 +390,14 @@ static fvoid *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
*fileExists = (entry != NULL);
BAIL_IF_MACRO(entry == NULL, NULL, NULL);

finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo));
finfo = (GRPfileinfo *) allocator.Malloc(sizeof (GRPfileinfo));
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);

finfo->handle = __PHYSFS_platformOpenRead(info->filename);
if ( (finfo->handle == NULL) ||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
{
free(finfo);
allocator.Free(finfo);
return(NULL);
} /* if */

@@ -78,9 +78,9 @@ typedef struct
static void HOG_dirClose(dvoid *opaque)
{
HOGinfo *info = ((HOGinfo *) opaque);
free(info->filename);
free(info->entries);
free(info);
allocator.Free(info->filename);
allocator.Free(info->entries);
allocator.Free(info);
} /* HOG_dirClose */


@@ -152,7 +152,7 @@ static int HOG_fileClose(fvoid *opaque)
{
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
free(finfo);
allocator.Free(finfo);
return(1);
} /* HOG_fileClose */

@@ -256,7 +256,7 @@ static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)

BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
info->entryCount = fileCount;
info->entries = (HOGentry *) malloc(sizeof (HOGentry) * fileCount);
info->entries = (HOGentry *) allocator.Malloc(sizeof(HOGentry)*fileCount);
if (info->entries == NULL)
{
__PHYSFS_platformClose(fh);
@@ -304,11 +304,11 @@ static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)
static void *HOG_openArchive(const char *name, int forWriting)
{
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
HOGinfo *info = malloc(sizeof (HOGinfo));
HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));

BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
memset(info, '\0', sizeof (HOGinfo));
info->filename = (char *) malloc(strlen(name) + 1);
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);

if (!hog_load_entries(name, forWriting, info))
@@ -323,10 +323,10 @@ static void *HOG_openArchive(const char *name, int forWriting)
if (info != NULL)
{
if (info->filename != NULL)
free(info->filename);
allocator.Free(info->filename);
if (info->entries != NULL)
free(info->entries);
free(info);
allocator.Free(info->entries);
allocator.Free(info);
} /* if */

return(NULL);
@@ -429,14 +429,14 @@ static fvoid *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
*fileExists = (entry != NULL);
BAIL_IF_MACRO(entry == NULL, NULL, NULL);

finfo = (HOGfileinfo *) malloc(sizeof (HOGfileinfo));
finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);

finfo->handle = __PHYSFS_platformOpenRead(info->filename);
if ( (finfo->handle == NULL) ||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
{
free(finfo);
allocator.Free(finfo);
return(NULL);
} /* if */

@@ -116,8 +116,8 @@ static PHYSFS_uint32 MIX_hash(const char *name)
static void MIX_dirClose(dvoid *opaque)
{
MIXinfo *info = ((MIXinfo *) opaque);
free(info->entry);
free(info->filename);
allocator.Free(info->entry);
allocator.Free(info->filename);
} /* MIX_dirClose */


@@ -186,7 +186,7 @@ static int MIX_fileClose(fvoid *opaque)
{
MIXfileinfo *finfo = (MIXfileinfo *) opaque;
__PHYSFS_platformClose(finfo->handle);
free(finfo);
allocator.Free(finfo);
return(1);
} /* MIX_fileClose */

@@ -231,11 +231,11 @@ static void *MIX_openArchive(const char *name, int forWriting)
MIXinfo *info = NULL;
void *handle = NULL;

info = (MIXinfo *) malloc(sizeof (MIXinfo));
info = (MIXinfo *) allocator.Malloc(sizeof (MIXinfo));
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
memset(info, '\0', sizeof (MIXinfo));

info->filename = (char *) malloc(strlen(name) + 1);
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);

/* store filename */
@@ -254,7 +254,7 @@ static void *MIX_openArchive(const char *name, int forWriting)
info->delta = 6 + (info->header.num_files * 12);

/* allocate space for the entries and read the entries */
info->entry = malloc(sizeof (MIXentry) * info->header.num_files);
info->entry = allocator.Malloc(sizeof (MIXentry) * info->header.num_files);
GOTO_IF_MACRO(!info->entry, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);

/* read the directory list */
@@ -274,10 +274,10 @@ static void *MIX_openArchive(const char *name, int forWriting)
if (info != NULL)
{
if (info->filename != NULL)
free(info->filename);
allocator.Free(info->filename);
if (info->entry != NULL)
free(info->entry);
free(info);
allocator.Free(info->entry);
allocator.Free(info);
} /* if */

if (handle != NULL)
@@ -367,14 +367,14 @@ static fvoid *MIX_openRead(dvoid *opaque, const char *fnm, int *fileExists)
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);

/* allocate a MIX handle */
finfo = (MIXfileinfo *) malloc(sizeof (MIXfileinfo));
finfo = (MIXfileinfo *) allocator.Malloc(sizeof (MIXfileinfo));
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);

/* open the archive */
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
if(!finfo->handle)
{
free(finfo);
allocator.Free(finfo);
return(NULL);
} /* if */

@@ -67,9 +67,9 @@ typedef struct
static void MVL_dirClose(dvoid *opaque)
{
MVLinfo *info = ((MVLinfo *) opaque);
free(info->filename);
free(info->entries);
free(info);
allocator.Free(info->filename);
allocator.Free(info->entries);
allocator.Free(info);
} /* MVL_dirClose */


@@ -141,7 +141,7 @@ static int MVL_fileClose(fvoid *opaque)
{
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
free(finfo);
allocator.Free(finfo);
return(1);
} /* MVL_fileClose */

@@ -223,7 +223,7 @@ static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info)

BAIL_IF_MACRO(!mvl_open(name, forWriting, &fh, &fileCount), NULL, 0);
info->entryCount = fileCount;
info->entries = (MVLentry *) malloc(sizeof (MVLentry) * fileCount);
info->entries = (MVLentry *) allocator.Malloc(sizeof(MVLentry)*fileCount);
if (info->entries == NULL)
{
__PHYSFS_platformClose(fh);
@@ -262,12 +262,12 @@ static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info)
static void *MVL_openArchive(const char *name, int forWriting)
{
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
MVLinfo *info = malloc(sizeof (MVLinfo));
MVLinfo *info = (MVLinfo *) allocator.Malloc(sizeof (MVLinfo));

BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
memset(info, '\0', sizeof (MVLinfo));

info->filename = (char *) malloc(strlen(name) + 1);
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MVL_openArchive_failed);
if (!mvl_load_entries(name, forWriting, info))
goto MVL_openArchive_failed;
@@ -280,10 +280,10 @@ static void *MVL_openArchive(const char *name, int forWriting)
if (info != NULL)
{
if (info->filename != NULL)
free(info->filename);
allocator.Free(info->filename);
if (info->entries != NULL)
free(info->entries);
free(info);
allocator.Free(info->entries);
allocator.Free(info);
} /* if */

return(NULL);
@@ -386,14 +386,14 @@ static fvoid *MVL_openRead(dvoid *opaque, const char *fnm, int *fileExists)
*fileExists = (entry != NULL);
BAIL_IF_MACRO(entry == NULL, NULL, NULL);

finfo = (MVLfileinfo *) malloc(sizeof (MVLfileinfo));
finfo = (MVLfileinfo *) allocator.Malloc(sizeof (MVLfileinfo));
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);

finfo->handle = __PHYSFS_platformOpenRead(info->filename);
if ( (finfo->handle == NULL) ||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
{
free(finfo);
allocator.Free(finfo);
return(NULL);
} /* if */

0 comments on commit d840403

Please sign in to comment.