All memory management now goes through allocation hooks instead of directly to
authorRyan C. Gordon <icculus@icculus.org>
Mon, 14 Mar 2005 11:49:30 +0000
changeset 691 71d9affe0d8a
parent 690 c34d1027aad0
child 692 9c2381075c5e
All memory management now goes through allocation hooks instead of directly to C runtime malloc/realloc/free...
archivers/dir.c
archivers/grp.c
archivers/hog.c
archivers/mix.c
archivers/mvl.c
archivers/qpak.c
archivers/wad.c
archivers/zip.c
physfs.c
physfs.h
physfs_internal.h
platform/Makefile.am
platform/macclassic.c
platform/os2.c
platform/pocketpc.c
platform/posix.c
platform/skeleton.c
platform/unix.c
platform/win32.c
--- a/archivers/dir.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/dir.c	Mon Mar 14 11:49:30 2005 +0000
@@ -91,7 +91,7 @@
     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 @@
     if (d != NULL)
     {
         __PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata);
-        free(d);
+        allocator.Free(d);
     } /* if */
 } /* DIR_enumerateFiles */
 
@@ -123,7 +123,7 @@
 
     BAIL_IF_MACRO(f == NULL, NULL, 0);
     retval = __PHYSFS_platformExists(f);
-    free(f);
+    allocator.Free(f);
     return(retval);
 } /* DIR_exists */
 
@@ -137,7 +137,7 @@
     *fileExists = __PHYSFS_platformExists(d);
     if (*fileExists)
         retval = __PHYSFS_platformIsDirectory(d);
-    free(d);
+    allocator.Free(d);
     return(retval);
 } /* DIR_isDirectory */
 
@@ -151,7 +151,7 @@
     *fileExists = __PHYSFS_platformExists(f);
     if (*fileExists)
         retval = __PHYSFS_platformIsSymLink(f);
-    free(f);
+    allocator.Free(f);
     return(retval);
 } /* DIR_isSymLink */
 
@@ -167,7 +167,7 @@
     *fileExists = __PHYSFS_platformExists(d);
     if (*fileExists)
         retval = __PHYSFS_platformGetLastModTime(d);
-    free(d);
+    allocator.Free(d);
     return(retval);
 } /* DIR_getLastModTime */
 
@@ -186,13 +186,13 @@
         *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 @@
 
     BAIL_IF_MACRO(f == NULL, NULL, 0);
     retval = __PHYSFS_platformDelete(f);
-    free(f);
+    allocator.Free(f);
     return(retval);
 } /* DIR_remove */
 
@@ -235,14 +235,14 @@
 
     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 */
 
 
--- a/archivers/grp.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/grp.c	Mon Mar 14 11:49:30 2005 +0000
@@ -64,9 +64,9 @@
 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 @@
 {
     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 @@
 
     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 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 @@
     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 @@
     *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 */
 
--- a/archivers/hog.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/hog.c	Mon Mar 14 11:49:30 2005 +0000
@@ -78,9 +78,9 @@
 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 @@
 {
     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 @@
 
     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 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 @@
     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 @@
     *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 */
 
--- a/archivers/mix.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/mix.c	Mon Mar 14 11:49:30 2005 +0000
@@ -116,8 +116,8 @@
 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 @@
 {
     MIXfileinfo *finfo = (MIXfileinfo *) opaque;
     __PHYSFS_platformClose(finfo->handle);
-    free(finfo);
+    allocator.Free(finfo);
     return(1);
 } /* MIX_fileClose */
 
@@ -231,11 +231,11 @@
     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 @@
     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 @@
     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 @@
     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 */
     
--- a/archivers/mvl.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/mvl.c	Mon Mar 14 11:49:30 2005 +0000
@@ -67,9 +67,9 @@
 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 @@
 {
     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 @@
 
     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 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 @@
     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 @@
     *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 */
 
--- a/archivers/qpak.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/qpak.c	Mon Mar 14 11:49:30 2005 +0000
@@ -81,9 +81,9 @@
 static void QPAK_dirClose(dvoid *opaque)
 {
     QPAKinfo *info = ((QPAKinfo *) opaque);
-    free(info->filename);
-    free(info->entries);
-    free(info);
+    allocator.Free(info->filename);
+    allocator.Free(info->entries);
+    allocator.Free(info);
 } /* QPAK_dirClose */
 
 
@@ -155,7 +155,7 @@
 {
     QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
     BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
-    free(finfo);
+    allocator.Free(finfo);
     return(1);
 } /* QPAK_fileClose */
 
@@ -245,7 +245,7 @@
 
     BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
     info->entryCount = fileCount;
-    info->entries = (QPAKentry *) malloc(sizeof (QPAKentry) * fileCount);
+    info->entries = (QPAKentry*) allocator.Malloc(sizeof(QPAKentry)*fileCount);
     if (info->entries == NULL)
     {
         __PHYSFS_platformClose(fh);
@@ -288,13 +288,13 @@
 
 static void *QPAK_openArchive(const char *name, int forWriting)
 {
-    QPAKinfo *info = malloc(sizeof (QPAKinfo));
+    QPAKinfo *info = (QPAKinfo *) allocator.Malloc(sizeof (QPAKinfo));
     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
 
     BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
     memset(info, '\0', sizeof (QPAKinfo));
 
-    info->filename = (char *) malloc(strlen(name) + 1);
+    info->filename = (char *) allocator.Malloc(strlen(name) + 1);
     if (info->filename == NULL)
     {
         __PHYSFS_setError(ERR_OUT_OF_MEMORY);
@@ -312,10 +312,10 @@
     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);
@@ -544,14 +544,14 @@
     BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
     BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
 
-    finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
+    finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
     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 */
 
--- a/archivers/wad.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/wad.c	Mon Mar 14 11:49:30 2005 +0000
@@ -83,9 +83,9 @@
 static void WAD_dirClose(dvoid *opaque)
 {
     WADinfo *info = ((WADinfo *) opaque);
-    free(info->filename);
-    free(info->entries);
-    free(info);
+    allocator.Free(info->filename);
+    allocator.Free(info->entries);
+    allocator.Free(info);
 } /* WAD_dirClose */
 
 
@@ -157,7 +157,7 @@
 {
     WADfileinfo *finfo = (WADfileinfo *) opaque;
     BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
-    free(finfo);
+    allocator.Free(finfo);
     return(1);
 } /* WAD_fileClose */
 
@@ -247,7 +247,7 @@
 
     BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0);
     info->entryCount = fileCount;
-    info->entries = (WADentry *) malloc(sizeof (WADentry) * fileCount);
+    info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount);
     if (info->entries == NULL)
     {
         __PHYSFS_platformClose(fh);
@@ -292,12 +292,12 @@
 static void *WAD_openArchive(const char *name, int forWriting)
 {
     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
-    WADinfo *info = malloc(sizeof (WADinfo));
+    WADinfo *info = (WADinfo *) allocator.Malloc(sizeof (WADinfo));
 
     BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
     memset(info, '\0', sizeof (WADinfo));
 
-    info->filename = (char *) malloc(strlen(name) + 1);
+    info->filename = (char *) allocator.Malloc(strlen(name) + 1);
     GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, WAD_openArchive_failed);
 
     if (!wad_load_entries(name, forWriting, info))
@@ -311,10 +311,10 @@
     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);
@@ -449,14 +449,14 @@
     *fileExists = (entry != NULL);
     BAIL_IF_MACRO(entry == NULL, NULL, NULL);
 
-    finfo = (WADfileinfo *) malloc(sizeof (WADfileinfo));
+    finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo));
     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 */
 
--- a/archivers/zip.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/archivers/zip.c	Mon Mar 14 11:49:30 2005 +0000
@@ -27,8 +27,8 @@
 #include "physfs_internal.h"
 
 /*
- * A buffer of ZIP_READBUFSIZE is malloc() for each compressed file opened,
- *  and is free()'d when you close the file; compressed data is read into
+ * A buffer of ZIP_READBUFSIZE is allocated for each compressed file opened,
+ *  and is freed when you close the file; compressed data is read into
  *  this buffer, and then is decompressed into the buffer passed to
  *  PHYSFS_read().
  *
@@ -121,7 +121,7 @@
  */
 static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
 {
-    return(((PHYSFS_Allocator *) opaque)->malloc(items * size));
+    return(((PHYSFS_Allocator *) opaque)->Malloc(items * size));
 } /* zlibPhysfsAlloc */
 
 /*
@@ -129,7 +129,7 @@
  */
 static void zlibPhysfsFree(voidpf opaque, voidpf address)
 {
-    ((PHYSFS_Allocator *) opaque)->free(address);
+    ((PHYSFS_Allocator *) opaque)->Free(address);
 } /* zlibPhysfsFree */
 
 
@@ -141,7 +141,7 @@
     memset(pstr, '\0', sizeof (z_stream));
     pstr->zalloc = zlibPhysfsAlloc;
     pstr->zfree = zlibPhysfsFree;
-    pstr->opaque = __PHYSFS_getAllocator();
+    pstr->opaque = &allocator;
 } /* initializeZStream */
 
 
@@ -369,9 +369,9 @@
         inflateEnd(&finfo->stream);
 
     if (finfo->buffer != NULL)
-        free(finfo->buffer);
+        allocator.Free(finfo->buffer);
 
-    free(finfo);
+    allocator.Free(finfo);
     return(1);
 } /* ZIP_fileClose */
 
@@ -388,7 +388,7 @@
     PHYSFS_uint32 extra = 0;
 
     filelen = __PHYSFS_platformFileLength(in);
-    BAIL_IF_MACRO(filelen == -1, NULL, 0);
+    BAIL_IF_MACRO(filelen == -1, NULL, 0);  /* !!! FIXME: unlocalized string */
     BAIL_IF_MACRO(filelen > 0xFFFFFFFF, "ZIP bigger than 2 gigs?!", 0);
 
     /*
@@ -501,10 +501,10 @@
     {
         ZIPentry *entry = &entries[i];
         if (entry->name != NULL)
-            free(entry->name);
+            allocator.Free(entry->name);
     } /* for */
 
-    free(entries);
+    allocator.Free(entries);
 } /* zip_free_entries */
 
 
@@ -658,7 +658,7 @@
         } /* else */
     } /* if */
 
-    free(path);
+    allocator.Free(path);
     return(entry);
 } /* zip_follow_symlink */
 
@@ -677,7 +677,7 @@
 
     BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, entry->offset), NULL, 0);
 
-    path = (char *) malloc(size + 1);
+    path = (char *) allocator.Malloc(size + 1);
     BAIL_IF_MACRO(path == NULL, ERR_OUT_OF_MEMORY, 0);
     
     if (entry->compression_method == COMPMETH_NONE)
@@ -687,7 +687,7 @@
     {
         z_stream stream;
         PHYSFS_uint32 compsize = entry->compressed_size;
-        PHYSFS_uint8 *compressed = (PHYSFS_uint8 *) malloc(compsize);
+        PHYSFS_uint8 *compressed = (PHYSFS_uint8 *) allocator.Malloc(compsize);
         if (compressed != NULL)
         {
             if (__PHYSFS_platformRead(in, compressed, compsize, 1) == 1)
@@ -706,12 +706,12 @@
                     rc = ((rc == Z_OK) || (rc == Z_STREAM_END));
                 } /* if */
             } /* if */
-            free(compressed);
+            allocator.Free(compressed);
         } /* if */
     } /* else */
 
     if (!rc)
-        free(path);
+        allocator.Free(path);
     else
     {
         path[entry->uncompressed_size] = '\0';    /* null-terminate it. */
@@ -928,7 +928,7 @@
     entry->resolved = (zip_has_symlink_attr(entry, external_attr)) ?
                             ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE;
 
-    entry->name = (char *) malloc(fnamelen + 1);
+    entry->name = (char *) allocator.Malloc(fnamelen + 1);
     BAIL_IF_MACRO(entry->name == NULL, ERR_OUT_OF_MEMORY, 0);
     if (__PHYSFS_platformRead(in, entry->name, fnamelen, 1) != 1)
         goto zip_load_entry_puked;
@@ -947,7 +947,7 @@
     return(1);  /* success. */
 
 zip_load_entry_puked:
-    free(entry->name);
+    allocator.Free(entry->name);
     return(0);  /* failure. */
 } /* zip_load_entry */
 
@@ -978,7 +978,7 @@
 
     BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, central_ofs), NULL, 0);
 
-    info->entries = (ZIPentry *) malloc(sizeof (ZIPentry) * max);
+    info->entries = (ZIPentry *) allocator.Malloc(sizeof (ZIPentry) * max);
     BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
 
     for (i = 0; i < max; i++)
@@ -1065,14 +1065,14 @@
 static ZIPinfo *zip_create_zipinfo(const char *name)
 {
     char *ptr;
-    ZIPinfo *info = (ZIPinfo *) malloc(sizeof (ZIPinfo));
+    ZIPinfo *info = (ZIPinfo *) allocator.Malloc(sizeof (ZIPinfo));
     BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
     memset(info, '\0', sizeof (ZIPinfo));
 
-    ptr = (char *) malloc(strlen(name) + 1);
+    ptr = (char *) allocator.Malloc(strlen(name) + 1);
     if (ptr == NULL)
     {
-        free(info);
+        allocator.Free(info);
         BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
     } /* if */
 
@@ -1110,8 +1110,8 @@
     if (info != NULL)
     {
         if (info->archiveName != NULL)
-            free(info->archiveName);
-        free(info);
+            allocator.Free(info->archiveName);
+        allocator.Free(info);
     } /* if */
 
     if (in != NULL)
@@ -1340,7 +1340,7 @@
     in = zip_get_file_handle(info->archiveName, info, entry);
     BAIL_IF_MACRO(in == NULL, NULL, NULL);
 
-    finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo));
+    finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo));
     if (finfo == NULL)
     {
         __PHYSFS_platformClose(in);
@@ -1359,7 +1359,7 @@
             return(NULL);
         } /* if */
 
-        finfo->buffer = (PHYSFS_uint8 *) malloc(ZIP_READBUFSIZE);
+        finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE);
         if (finfo->buffer == NULL)
         {
             ZIP_fileClose(finfo);
@@ -1387,8 +1387,8 @@
 {
     ZIPinfo *zi = (ZIPinfo *) (opaque);
     zip_free_entries(zi->entries, zi->entryCount);
-    free(zi->archiveName);
-    free(zi);
+    allocator.Free(zi->archiveName);
+    allocator.Free(zi);
 } /* ZIP_dirClose */
 
 
--- a/physfs.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/physfs.c	Mon Mar 14 11:49:30 2005 +0000
@@ -180,7 +180,7 @@
 
 /* allocator ... */
 static int externalAllocator = 0;
-static PHYSFS_Allocator allocator;
+PHYSFS_Allocator allocator;
 
 
 /* functions ... */
@@ -201,8 +201,8 @@
     if (pecd->errorstr)
         return;
 
-    ptr = realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
-    newstr = malloc(strlen(str) + 1);
+    ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
+    newstr = (char *) allocator.Malloc(strlen(str) + 1);
     if (ptr != NULL)
         pecd->list = (char **) ptr;
 
@@ -224,7 +224,7 @@
 {
     EnumStringListCallbackData ecd;
     memset(&ecd, '\0', sizeof (ecd));
-    ecd.list = (char **) malloc(sizeof (char *));
+    ecd.list = (char **) allocator.Malloc(sizeof (char *));
     BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
     func(enumStringListCallback, &ecd);
     BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL);
@@ -345,7 +345,7 @@
 
     if (err == NULL)
     {
-        err = (ErrMsg *) malloc(sizeof (ErrMsg));
+        err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg));
         if (err == NULL)
             return;   /* uhh...? */
 
@@ -389,7 +389,7 @@
     for (i = errorMessages; i != NULL; i = next)
     {
         next = i->next;
-        free(i);
+        allocator.Free(i);
     } /* for */
 
     errorMessages = NULL;
@@ -435,7 +435,7 @@
         void *opaque = funcs->openArchive(d, forWriting);
         if (opaque != NULL)
         {
-            retval = (DirHandle *) allocator.malloc(sizeof (DirHandle));
+            retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
             if (retval == NULL)
                 funcs->dirClose(opaque);
             else
@@ -592,13 +592,13 @@
     dirHandle = openDirectory(newDir, forWriting);
     GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle);
 
-    dirHandle->dirName = (char *) malloc(strlen(newDir) + 1);
+    dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1);
     GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle);
     strcpy(dirHandle->dirName, newDir);
 
     if ((mountPoint != NULL) && (*mountPoint != '\0'))
     {
-        dirHandle->mountPoint = (char *) malloc(strlen(mountPoint) + 2);
+        dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2);
         GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle);
         strcpy(dirHandle->mountPoint, mountPoint);
         strcat(dirHandle->mountPoint, "/");
@@ -610,9 +610,9 @@
     if (dirHandle != NULL)
     {
         dirHandle->funcs->dirClose(dirHandle->opaque);
-        free(dirHandle->dirName);
-        free(dirHandle->mountPoint);
-        free(dirHandle);
+        allocator.Free(dirHandle->dirName);
+        allocator.Free(dirHandle->mountPoint);
+        allocator.Free(dirHandle);
     } /* if */
 
     return(NULL);
@@ -631,9 +631,9 @@
         BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0);
     
     dh->funcs->dirClose(dh->opaque);
-    free(dh->dirName);
-    free(dh->mountPoint);
-    free(dh);
+    allocator.Free(dh->dirName);
+    allocator.Free(dh->mountPoint);
+    allocator.Free(dh);
     return(1);
 } /* freeDirHandle */
 
@@ -652,8 +652,8 @@
         const char *uname = __PHYSFS_platformGetUserName();
 
         str = (uname != NULL) ? uname : "default";
-        retval = (char *) malloc(strlen(baseDir) + strlen(str) +
-                                 strlen(dirsep) + 6);
+        retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
+                                           strlen(dirsep) + 6);
 
         if (retval == NULL)
             __PHYSFS_setError(ERR_OUT_OF_MEMORY);
@@ -661,7 +661,7 @@
             sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
 
         if (uname != NULL)
-            free((void *) uname);
+            allocator.Free((void *) uname);
     } /* else */
 
     return(retval);
@@ -676,10 +676,10 @@
     if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
         return(1);
 
-    ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
+    ptr = (char *) allocator.Realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
     if (!ptr)
     {
-        free(*dir);
+        allocator.Free(*dir);
         return(0);
     } /* if */
 
@@ -717,7 +717,7 @@
         } /* while */
 
         size = (size_t) (ptr - argv0);
-        retval = (char *) malloc(size + 1);
+        retval = (char *) allocator.Malloc(size + 1);
         BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
         memcpy(retval, argv0, size);
         retval[size] = '\0';
@@ -736,7 +736,7 @@
      * Not a good alternative, but it only happens if the current
      * directory was deleted from under the program.
      */
-    retval = (char *) malloc(strlen(dirsep) + 1);
+    retval = (char *) allocator.Malloc(strlen(dirsep) + 1);
     strcpy(retval, dirsep);
     return(retval);
 } /* calculateBaseDir */
@@ -777,7 +777,7 @@
     if (!externalAllocator)
         setDefaultAllocator();
 
-    BAIL_IF_MACRO(!allocator.init(), NULL, 0);
+    BAIL_IF_MACRO(!allocator.Init(), NULL, 0);
 
     BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
 
@@ -787,7 +787,7 @@
     BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
 
     ptr = __PHYSFS_platformRealPath(baseDir);
-    free(baseDir);
+    allocator.Free(baseDir);
     BAIL_IF_MACRO(ptr == NULL, NULL, 0);
     baseDir = ptr;
 
@@ -797,13 +797,13 @@
     if (userDir != NULL)
     {
         ptr = __PHYSFS_platformRealPath(userDir);
-        free(userDir);
+        allocator.Free(userDir);
         userDir = ptr;
     } /* if */
 
     if ((userDir == NULL) || (!appendDirSep(&userDir)))
     {
-        free(baseDir);
+        allocator.Free(baseDir);
         baseDir = NULL;
         return(0);
     } /* if */
@@ -832,7 +832,7 @@
             return(0);
         } /* if */
 
-        free(i);
+        allocator.Free(i);
     } /* for */
 
     *list = NULL;
@@ -873,13 +873,13 @@
 
     if (baseDir != NULL)
     {
-        free(baseDir);
+        allocator.Free(baseDir);
         baseDir = NULL;
     } /* if */
 
     if (userDir != NULL)
     {
-        free(userDir);
+        allocator.Free(userDir);
         userDir = NULL;
     } /* if */
 
@@ -889,7 +889,7 @@
     __PHYSFS_platformDestroyMutex(errorLock);
     __PHYSFS_platformDestroyMutex(stateLock);
 
-    allocator.deinit();
+    allocator.Deinit();
 
     errorLock = stateLock = NULL;
     return(1);
@@ -906,9 +906,9 @@
 {
     void **i;
     for (i = (void **) list; *i != NULL; i++)
-        free(*i);
+        allocator.Free(*i);
 
-    free(list);
+    allocator.Free(list);
 } /* PHYSFS_freeList */
 
 
@@ -1106,8 +1106,10 @@
     BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
 
         /* set write dir... */
-    str = malloc(strlen(userdir) + (strlen(organization) * 2) +
-                 (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
+    str = (char *) allocator.Malloc(
+            strlen(userdir) + (strlen(organization) * 2) +
+            (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
+
     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
     sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
 
@@ -1130,14 +1132,14 @@
         if (no_write)
         {
             PHYSFS_setWriteDir(NULL);   /* just in case. */
-            free(str);
+            allocator.Free(str);
             BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0);
         } /* if */
     } /* if */
 
     /* Put write dir first in search path... */
     PHYSFS_addToSearchPath(str, 0);
-    free(str);
+    allocator.Free(str);
 
         /* Put base path on search path... */
     PHYSFS_addToSearchPath(basedir, 1);
@@ -1170,12 +1172,13 @@
                 if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
                 {
                     const char *d = PHYSFS_getRealDir(*i);
-                    str = malloc(strlen(d) + strlen(dirsep) + l + 1);
+                    size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
+                    str = (char *) allocator.Malloc(allocsize);
                     if (str != NULL)
                     {
                         sprintf(str, "%s%s%s", d, dirsep, *i);
                         PHYSFS_addToSearchPath(str, archivesFirst == 0);
-                        free(str);
+                        allocator.Free(str);
                     } /* if */
                 } /* if */
             } /* if */
@@ -1195,9 +1198,9 @@
 
 
 /* string manipulation in C makes my ass itch. */
-char * __PHYSFS_convertToDependent(const char *prepend,
-                                              const char *dirName,
-                                              const char *append)
+char *__PHYSFS_convertToDependent(const char *prepend,
+                                  const char *dirName,
+                                  const char *append)
 {
     const char *dirsep = __PHYSFS_platformDirSeparator;
     size_t sepsize = strlen(dirsep);
@@ -1206,7 +1209,7 @@
     char *i2;
     size_t allocSize;
 
-    while (*dirName == '/')
+    while (*dirName == '/')  /* !!! FIXME: pass through sanitize function. */
         dirName++;
 
     allocSize = strlen(dirName) + 1;
@@ -1230,7 +1233,7 @@
         } while (str != NULL);
     } /* if */
 
-    str = (char *) malloc(allocSize);
+    str = (char *) allocator.Malloc(allocSize);
     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
 
     if (prepend == NULL)
@@ -1504,8 +1507,8 @@
             return;  /* already in the list. */
     } /* if */
 
-    ptr = realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
-    newstr = malloc(strlen(str) + 1);
+    ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
+    newstr = (char *) allocator.Malloc(strlen(str) + 1);
     if (ptr != NULL)
         pecd->list = (char **) ptr;
 
@@ -1529,7 +1532,7 @@
 {
     EnumStringListCallbackData ecd;
     memset(&ecd, '\0', sizeof (ecd));
-    ecd.list = (char **) malloc(sizeof (char *));
+    ecd.list = (char **) allocator.Malloc(sizeof (char *));
     BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
     PHYSFS_enumerateFilesCallback(path, enumFilesCallback, &ecd);
     ecd.list[ecd.size] = NULL;
@@ -1690,7 +1693,7 @@
 
     BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
 
-    fh = (FileHandle *) malloc(sizeof (FileHandle));
+    fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
     if (fh == NULL)
     {
         f->fileClose(opaque);
@@ -1736,7 +1739,7 @@
 
     __PHYSFS_platformGrabMutex(stateLock);
 
-    BAIL_IF_MACRO_MUTEX(!searchPath, ERR_PATH_NOT_FOUND, stateLock, NULL);
+    BAIL_IF_MACRO_MUTEX(!searchPath, ERR_NO_SUCH_PATH, stateLock, NULL);
 
     /* !!! FIXME: Why aren't we using a for loop here? */
     i = searchPath;
@@ -1755,7 +1758,7 @@
 
     BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
 
-    fh = (FileHandle *) malloc(sizeof (FileHandle));
+    fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
     if (fh == NULL)
     {
         i->funcs->fileClose(opaque);
@@ -1793,14 +1796,14 @@
                 return(-1);
 
             if (tmp != NULL)  /* free any associated buffer. */
-                free(tmp);
+                allocator.Free(tmp);
 
             if (prev == NULL)
                 *list = handle->next;
             else
                 prev->next = handle->next;
 
-            free(handle);
+            allocator.Free(handle);
             return(1);
         } /* if */
         prev = i;
@@ -2005,14 +2008,15 @@
     {
         if (fh->buffer != NULL)
         {
-            free(fh->buffer);
+            allocator.Free(fh->buffer);
             fh->buffer = NULL;
         } /* if */
     } /* if */
 
     else
     {
-        PHYSFS_uint8 *newbuf = realloc(fh->buffer, bufsize);
+        PHYSFS_uint8 *newbuf;
+        newbuf = (PHYSFS_uint8 *) allocator.Realloc(fh->buffer, bufsize);
         BAIL_IF_MACRO(newbuf == NULL, ERR_OUT_OF_MEMORY, 0);
         fh->buffer = newbuf;
     } /* else */
@@ -2054,11 +2058,11 @@
 static void setDefaultAllocator(void)
 {
     assert(!externalAllocator);
-    allocator.init = __PHYSFS_platformAllocatorInit;
-    allocator.deinit = __PHYSFS_platformAllocatorDeinit;
-    allocator.malloc = __PHYSFS_platformAllocatorMalloc;
-    allocator.realloc = __PHYSFS_platformAllocatorRealloc;
-    allocator.free = __PHYSFS_platformAllocatorFree;
+    allocator.Init = __PHYSFS_platformAllocatorInit;
+    allocator.Deinit = __PHYSFS_platformAllocatorDeinit;
+    allocator.Malloc = __PHYSFS_platformAllocatorMalloc;
+    allocator.Realloc = __PHYSFS_platformAllocatorRealloc;
+    allocator.Free = __PHYSFS_platformAllocatorFree;
 } /* setDefaultAllocator */
 
 
--- a/physfs.h	Mon Mar 14 11:48:29 2005 +0000
+++ b/physfs.h	Mon Mar 14 11:49:30 2005 +0000
@@ -1861,11 +1861,11 @@
  */
 typedef struct
 {
-    int (*init)(void);
-    void (*deinit)(void);
-    void *(*malloc)(size_t);
-    void *(*realloc)(void *, size_t);
-    void (*free)(void *);
+    int (*Init)(void);
+    void (*Deinit)(void);
+    void *(*Malloc)(size_t);
+    void *(*Realloc)(void *, size_t);
+    void (*Free)(void *);
 } PHYSFS_Allocator;
 
 
@@ -1876,6 +1876,8 @@
  * (This is for limited, hardcore use. If you don't immediately see a need
  *  for it, you can probably ignore this forever.)
  *
+ *  !!! FIXME: don't promise C runtime malloc.
+ *
  * By default, PhysicsFS will use ANSI C malloc/realloc/calloc/free calls
  *  to manage dynamic memory, but in some uncommon cases, the app might want
  *  more control over the library's memory management. This lets you redirect
--- a/physfs_internal.h	Mon Mar 14 11:48:29 2005 +0000
+++ b/physfs_internal.h	Mon Mar 14 11:49:30 2005 +0000
@@ -26,6 +26,11 @@
 extern "C" {
 #endif
 
+/* Use the allocation hooks. */
+#define malloc(x) Do not use malloc() directly.
+#define realloc(x, y) Do not use realloc() directly.
+#define free(x) Do not use free() directly.
+
 
 /* The LANG section. */
 /*  please send questions/translations to Ryan: icculus@clutteredmind.org. */
@@ -1241,10 +1246,12 @@
 
 
 /*
- * Get the current allocator. Not valid before PHYSFS_init is called!
+ * The current allocator. Not valid before PHYSFS_init is called!
  */
-PHYSFS_Allocator *__PHYSFS_getAllocator(void);
+extern PHYSFS_Allocator __PHYSFS_AllocatorHooks;
 
+/* convenience macro to make this less cumbersome internally... */
+#define allocator __PHYSFS_AllocatorHooks
 
 /*--------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------*/
--- a/platform/Makefile.am	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/Makefile.am	Mon Mar 14 11:49:30 2005 +0000
@@ -19,6 +19,7 @@
 	skeleton.c    \
 	macclassic.c  \
 	win32.c       \
+	pocketpc.c    \
 	unix.c        \
 	os2.c         \
     beos.cpp
--- a/platform/macclassic.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/macclassic.c	Mon Mar 14 11:49:30 2005 +0000
@@ -241,7 +241,7 @@
         if (oserr(PBGetCatInfoSync(&infoPB)) != noErr)
         {
             if (retval != NULL)
-                free(retval);
+                allocator.Free(retval);
             return(NULL);
         } /* if */
 
@@ -249,11 +249,11 @@
 
         /* allocate more space for the retval... */
         retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
-        ptr = (char *) malloc(retLength);
+        ptr = (char *) allocator.Malloc(retLength);
         if (ptr == NULL)
         {
             if (retval != NULL)
-                free(retval);
+                allocator.Free(retval);
             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
         } /* if */
 
@@ -264,7 +264,7 @@
         {
             strcat(ptr, ":");
             strcat(ptr, retval);
-            free(retval);
+            allocator.Free(retval);
         } /* if */
         retval = ptr;
     } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
@@ -297,7 +297,7 @@
     BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
 
     HLock((Handle) strHandle);
-    retval = (char *) malloc((*strHandle)[0] + 1);
+    retval = (char *) allocator.Malloc((*strHandle)[0] + 1);
     if (retval == NULL)
     {
         HUnlock((Handle) strHandle);
@@ -533,7 +533,7 @@
               strlen(dirName) + 1;
     const char *src;
     char *dst;
-    char *retval = malloc(len);
+    char *retval = (char *) allocator.Malloc(len);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
     if (prepend != NULL)
@@ -691,7 +691,7 @@
         created = 1;
     } /* if */
 
-    retval = (SInt16 *) malloc(sizeof (SInt16));
+    retval = (SInt16 *) allocator.Malloc(sizeof (SInt16));
     if (retval == NULL)
     {
         if (created)
@@ -702,7 +702,7 @@
     err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
     if (oserr(err) != noErr)
     {
-        free(retval);
+        allocator.Free(retval);
         if (created)
             HDelete(spec.vRefNum, spec.parID, spec.name);
         return(NULL);
@@ -866,7 +866,7 @@
     } /* if */
 
     BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
-    free(opaque);
+    allocator.Free(opaque);
 
     if (flushVol)
         FlushVol(volName, vRefNum);  /* update catalog info, etc. */
@@ -936,5 +936,39 @@
     return((PHYSFS_sint64) modDate);
 } /* __PHYSFS_platformGetLastModTime */
 
+
+/* !!! FIXME: Don't use C runtime for allocators? */
+int __PHYSFS_platformAllocatorInit(void)
+{
+    return(1);  /* always succeeds. */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void __PHYSFS_platformAllocatorDeinit(void)
+{
+    /* no-op */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void *__PHYSFS_platformAllocatorMalloc(size_t s)
+{
+    #undef malloc
+    return(malloc(s));
+} /* __PHYSFS_platformMalloc */
+
+
+void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
+{
+    #undef realloc
+    return(realloc(ptr, s));
+} /* __PHYSFS_platformRealloc */
+
+
+void __PHYSFS_platformAllocatorFree(void *ptr)
+{
+    #undef free
+    free(ptr);
+} /* __PHYSFS_platformAllocatorFree */
+
 /* end of macclassic.c ... */
 
--- a/platform/os2.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/os2.c	Mon Mar 14 11:49:30 2005 +0000
@@ -199,7 +199,7 @@
     /* The string is capitalized! Figure out the REAL case... */
     cvt_path_to_correct_case(buf);
 
-    baseDir = (char *) malloc(len + 1);
+    baseDir = (char *) allocator.Malloc(len + 1);
     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
     strcpy(baseDir, buf);
     return(1);  /* success. */
@@ -209,7 +209,7 @@
 int __PHYSFS_platformDeinit(void)
 {
     assert(baseDir != NULL);
-    free(baseDir);
+    allocator.Free(baseDir);
     baseDir = NULL;
     return(1);  /* success. */
 } /* __PHYSFS_platformDeinit */
@@ -279,7 +279,7 @@
 
 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
 {
-    char *retval = (char *) malloc(strlen(baseDir) + 1);
+    char *retval = (char *) allocator.Malloc(strlen(baseDir) + 1);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     strcpy(retval, baseDir); /* calculated at init time. */
     return(retval);
@@ -365,6 +365,7 @@
 } /* __PHYSFS_platformIsDirectory */
 
 
+/* !!! FIXME: can we lose the malloc here? */
 char *__PHYSFS_platformCvtToDependent(const char *prepend,
                                       const char *dirName,
                                       const char *append)
@@ -372,7 +373,7 @@
     int len = ((prepend) ? strlen(prepend) : 0) +
               ((append) ? strlen(append) : 0) +
               strlen(dirName) + 1;
-    char *retval = malloc(len);
+    char *retval = allocator.Malloc(len);
     char *p;
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -441,14 +442,14 @@
     /* The first call just tells us how much space we need for the string. */
     rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
     pathSize++; /* Add space for null terminator. */
-    retval = (char *) malloc(pathSize + 3);  /* plus "x:\\" */
+    retval = (char *) allocator.Malloc(pathSize + 3);  /* plus "x:\\" */
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
     /* Actually get the string this time. */
     rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
     if (os2err(rc) != NO_ERROR)
     {
-        free(retval);
+        allocator.Free(retval);
         return(NULL);
     } /* if */
 
@@ -465,7 +466,7 @@
     char *retval;
     APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
-    retval = (char *) malloc(strlen(buf) + 1);
+    retval = (char *) allocator.Malloc(strlen(buf) + 1);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     strcpy(retval, buf);
     return(retval);
--- a/platform/pocketpc.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/pocketpc.c	Mon Mar 14 11:49:30 2005 +0000
@@ -72,11 +72,11 @@
     if (w_str != NULL)
     {
         int len = wcslen(w_str) + 1;
-        str = (char *) malloc(len);
+        str = (char *) allocator.Malloc(len);
 
         if (WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL) == 0)
         {    /*Conversion failed */
-            free(str);
+            allocator.Free(str);
             return(NULL);
         } /* if */
         else
@@ -98,10 +98,10 @@
     if (str != NULL)
     {
         int len = strlen(str) + 1;
-        w_str = (wchar_t *) malloc(sizeof (wchar_t) * len);
+        w_str = (wchar_t *) allocator.Malloc(sizeof (wchar_t) * len);
         if (MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len) == 0)
         {
-            free(w_str);
+            allocator.Free(w_str);
             return(NULL);
         } /* if */
         else
@@ -121,7 +121,7 @@
     DWORD buflen;
     int success = 0;
     TCHAR *ptr = NULL;
-    TCHAR *retval = (TCHAR *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
+    TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
     char *charretval;
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
@@ -145,17 +145,17 @@
 
     if (!success)
     {
-        free(retval);
+        allocator.Free(retval);
         return(NULL);  /* physfs error message will be set, above. */
     } /* if */
 
     /* free up the bytes we didn't actually use. */
-    ptr = (TCHAR *) realloc(retval, sizeof(TCHAR) * _tcslen(retval) + 1);
+    ptr = (TCHAR *) allocator.Realloc(retval, sizeof(TCHAR)*_tcslen(retval)+1);
     if (ptr != NULL)
         retval = ptr;
 
     charretval = UnicodeToAsc(retval);
-    free(retval);
+    allocator.Free(retval);
     if(charretval == NULL) {
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     }
@@ -173,7 +173,7 @@
 
 int __PHYSFS_platformDeinit(void)
 {
-    free(userDir);
+    allocator.Free(userDir);
     return(1);  /* always succeed. */
 } /* __PHYSFS_platformDeinit */
 
@@ -230,7 +230,7 @@
     if(w_fname!=NULL)
     {
     retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
-    free(w_fname);
+    allocator.Free(w_fname);
     }
 
     return(retval);
@@ -252,7 +252,7 @@
     if(w_fname!=NULL)
     {
     retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
-    free(w_fname);
+    allocator.Free(w_fname);
     }
 
     return(retval);
@@ -266,7 +266,7 @@
     int len = ((prepend) ? strlen(prepend) : 0) +
     ((append) ? strlen(append) : 0) +
     strlen(dirName) + 1;
-    char *retval = malloc(len);
+    char *retval = (char *) allocator.Malloc(len);
     char *p;
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -325,8 +325,8 @@
     w_SearchPath=AscToUnicode(SearchPath);
 
     dir = FindFirstFile(w_SearchPath, &ent);
-    free(w_SearchPath);
-    free(SearchPath);
+    allocator.Free(w_SearchPath);
+    allocator.Free(SearchPath);
 
     if (dir == INVALID_HANDLE_VALUE)
         return;
@@ -347,7 +347,7 @@
             break;
 
         callback(callbackdata, str);
-        free(str);
+        allocator.Free(str);
     } while (FindNextFile(dir, &ent) != 0);
 
     FindClose(dir);
@@ -362,10 +362,8 @@
 
 char *__PHYSFS_platformRealPath(const char *path)
 {
-    char *retval=(char *)malloc(strlen(path)+1);
-
+    char *retval = (char *) allocator.Malloc(strlen(path) + 1);
     strcpy(retval,path);
-
     return(retval);
 } /* __PHYSFS_platformRealPath */
 
@@ -376,7 +374,7 @@
     if(w_path!=NULL)
     {
     DWORD rc = CreateDirectory(w_path, NULL);
-    free(w_path);
+    allocator.Free(w_path);
     if(rc==0)
     {
         return(0);
@@ -399,7 +397,7 @@
     fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
                             creation, FILE_ATTRIBUTE_NORMAL, NULL);
 
-    free(w_fname);
+    allocator.Free(w_fname);
 
     if(fileHandle==INVALID_HANDLE_VALUE)
     {
@@ -408,7 +406,7 @@
 
     BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
 
-    retval = malloc(sizeof (winCEfile));
+    retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
     if (retval == NULL)
     {
     CloseHandle(fileHandle);
@@ -443,7 +441,7 @@
         {
             const char *err = win32strerror();
             CloseHandle(h);
-            free(retval);
+            allocator.Free(retval);
             BAIL_MACRO(err, NULL);
         } /* if */
     } /* if */
@@ -604,7 +602,7 @@
 {
     HANDLE Handle = ((winCEfile *) opaque)->handle;
     BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
-    free(opaque);
+    allocator.Free(opaque);
     return(1);
 } /* __PHYSFS_platformClose */
 
@@ -617,13 +615,13 @@
     if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
     {
     int retval=!RemoveDirectory(w_path);
-    free(w_path);
+    allocator.Free(w_path);
         BAIL_IF_MACRO(retval, win32strerror(), 0);
     } /* if */
     else
     {
     int retval=!DeleteFile(w_path);
-    free(w_path);
+    allocator.Free(w_path);
         BAIL_IF_MACRO(retval, win32strerror(), 0);
     } /* else */
 
@@ -660,5 +658,39 @@
     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
 } /* __PHYSFS_platformGetLastModTime */
 
+
+/* !!! FIXME: Don't use C runtime for allocators? */
+int __PHYSFS_platformAllocatorInit(void)
+{
+    return(1);  /* always succeeds. */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void __PHYSFS_platformAllocatorDeinit(void)
+{
+    /* no-op */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void *__PHYSFS_platformAllocatorMalloc(size_t s)
+{
+    #undef malloc
+    return(malloc(s));
+} /* __PHYSFS_platformMalloc */
+
+
+void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
+{
+    #undef realloc
+    return(realloc(ptr, s));
+} /* __PHYSFS_platformRealloc */
+
+
+void __PHYSFS_platformAllocatorFree(void *ptr)
+{
+    #undef free
+    free(ptr);
+} /* __PHYSFS_platformAllocatorFree */
+
 /* end of pocketpc.c ... */
 
--- a/platform/posix.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/posix.c	Mon Mar 14 11:49:30 2005 +0000
@@ -59,7 +59,7 @@
 
     if (envr != NULL)
     {
-        retval = (char *) malloc(strlen(envr) + 1);
+        retval = (char *) allocator.Malloc(strlen(envr) + 1);
         if (retval != NULL)
             strcpy(retval, envr);
     } /* if */
@@ -77,7 +77,7 @@
     pw = getpwuid(uid);
     if ((pw != NULL) && (pw->pw_name != NULL))
     {
-        retval = (char *) malloc(strlen(pw->pw_name) + 1);
+        retval = (char *) allocator.Malloc(strlen(pw->pw_name) + 1);
         if (retval != NULL)
             strcpy(retval, pw->pw_name);
     } /* if */
@@ -95,7 +95,7 @@
     pw = getpwuid(uid);
     if ((pw != NULL) && (pw->pw_dir != NULL))
     {
-        retval = (char *) malloc(strlen(pw->pw_dir) + 1);
+        retval = (char *) allocator.Malloc(strlen(pw->pw_dir) + 1);
         if (retval != NULL)
             strcpy(retval, pw->pw_dir);
     } /* if */
@@ -204,7 +204,7 @@
     int len = ((prepend) ? strlen(prepend) : 0) +
               ((append) ? strlen(append) : 0) +
               strlen(dirName) + 1;
-    char *retval = (char *) malloc(len);
+    char *retval = (char *) allocator.Malloc(len);
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
@@ -240,7 +240,7 @@
     {
         dlen = strlen(dirname);
         bufsize = dlen + 256;
-        buf = (char *) malloc(bufsize);
+        buf = (char *) allocator.Malloc(bufsize);
         if (buf == NULL)
             return;
         strcpy(buf, dirname);
@@ -256,7 +256,7 @@
     if (dir == NULL)
     {
         if (buf != NULL)
-            free(buf);
+            allocator.Free(buf);
         return;
     } /* if */
 
@@ -274,7 +274,7 @@
             int len = strlen(ent->d_name) + dlen + 1;
             if (len > bufsize)
             {
-                p = realloc(buf, len);
+                p = (char *) allocator.Realloc(buf, len);
                 if (p == NULL)
                     continue;
                 buf = p;
@@ -290,7 +290,7 @@
     } /* while */
 
     if (buf != NULL)
-        free(buf);
+        allocator.Free(buf);
 
     closedir(dir);
 } /* __PHYSFS_platformEnumerateFiles */
@@ -305,11 +305,11 @@
     do
     {
         allocSize += 100;
-        ptr = (char *) realloc(retval, allocSize);
+        ptr = (char *) allocator.Realloc(retval, allocSize);
         if (ptr == NULL)
         {
             if (retval != NULL)
-                free(retval);
+                allocator.Free(retval);
             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
         } /* if */
 
@@ -324,7 +324,7 @@
              * directory not existing.
              */
         if (retval != NULL)
-            free(retval);
+            allocator.Free(retval);
         BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
     } /* if */
 
@@ -352,7 +352,7 @@
     fd = open(filename, mode, S_IRUSR | S_IWUSR);
     BAIL_IF_MACRO(fd < 0, strerror(errno), NULL);
 
-    retval = (int *) malloc(sizeof (int));
+    retval = (int *) allocator.Malloc(sizeof (int));
     if (retval == NULL)
     {
         close(fd);
@@ -482,7 +482,7 @@
 {
     int fd = *((int *) opaque);
     BAIL_IF_MACRO(close(fd) == -1, strerror(errno), 0);
-    free(opaque);
+    allocator.Free(opaque);
     return(1);
 } /* __PHYSFS_platformClose */
 
@@ -516,18 +516,21 @@
 
 void *__PHYSFS_platformAllocatorMalloc(size_t s)
 {
+    #undef malloc
     return(malloc(s));
 } /* __PHYSFS_platformMalloc */
 
 
 void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
 {
+    #undef realloc
     return(realloc(ptr, s));
 } /* __PHYSFS_platformRealloc */
 
 
 void __PHYSFS_platformAllocatorFree(void *ptr)
 {
+    #undef free
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
--- a/platform/skeleton.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/skeleton.c	Mon Mar 14 11:49:30 2005 +0000
@@ -233,5 +233,38 @@
     BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
 } /* __PHYSFS_platformGetLastModTime */
 
+
+int __PHYSFS_platformAllocatorInit(void)
+{
+    return(1);  /* always succeeds. */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void __PHYSFS_platformAllocatorDeinit(void)
+{
+    /* no-op */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void *__PHYSFS_platformAllocatorMalloc(size_t s)
+{
+    #undef malloc
+    return(malloc(s));
+} /* __PHYSFS_platformMalloc */
+
+
+void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
+{
+    #undef realloc
+    return(realloc(ptr, s));
+} /* __PHYSFS_platformRealloc */
+
+
+void __PHYSFS_platformAllocatorFree(void *ptr)
+{
+    #undef free
+    free(ptr);
+} /* __PHYSFS_platformAllocatorFree */
+
 /* end of skeleton.c ... */
 
--- a/platform/unix.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/unix.c	Mon Mar 14 11:49:30 2005 +0000
@@ -57,6 +57,10 @@
 #define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
+/* Seems to get defined in some system header... */
+#ifdef Free
+#undef Free
+#endif
 
 const char *__PHYSFS_platformDirSeparator = "/";
 
@@ -250,7 +254,7 @@
  *  if it doesn't exist or there were other problems. PHYSFS_SetError() is
  *  called if we have a problem.
  *
- * (envr) will be scribbled over, and you are expected to free() the
+ * (envr) will be scribbled over, and you are expected to allocator.Free() the
  *  return value when you're done with it.
  */
 static char *findBinaryInPath(const char *bin, char *envr)
@@ -273,11 +277,11 @@
         size = strlen(start) + strlen(bin) + 2;
         if (size > alloc_size)
         {
-            char *x = (char *) realloc(exe, size);
+            char *x = (char *) allocator.Realloc(exe, size);
             if (x == NULL)
             {
                 if (exe != NULL)
-                    free(exe);
+                    allocator.Free(exe);
                 BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
             } /* if */
 
@@ -301,7 +305,7 @@
     } while (ptr != NULL);
 
     if (exe != NULL)
-        free(exe);
+        allocator.Free(exe);
 
     return(NULL);  /* doesn't exist in path. */
 } /* findBinaryInPath */
@@ -320,7 +324,7 @@
     envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
     BAIL_IF_MACRO(!envr, NULL, NULL);
     retval = findBinaryInPath(argv0, envr);
-    free(envr);
+    allocator.Free(envr);
     return(retval);
 } /* __PHYSFS_platformCalcBaseDir */
 
@@ -377,11 +381,14 @@
     char *sub_str = "/contents/macos";
     char *found_ptr = NULL;
     char *tempbuf = NULL;
+    size_t len = strlen(path) + 1;
     int i;
     
-    /* Calloc will place the \0 character in the proper place for us */
     /* !!! FIXME: Can we stack-allocate this? --ryan. */
-    tempbuf = (char*)calloc( (strlen(path)+1), sizeof(char) );
+    tempbuf = (char *) allocator.Malloc(len);
+    if (!tempbuf) return;
+    memset(tempbuf, '\0', len);
+
     /* Unlike other Unix filesystems, HFS is case insensitive
      * It wouldn be nice to use strcasestr, but it doesn't seem
      * to be available in the OSX gcc library right now.
@@ -399,7 +406,7 @@
     {
         /* It doesn't look like a bundle so we can keep the 
          * original path. Just return */
-        free(tempbuf);
+        allocator.Free(tempbuf);
         return;
     }
     /* We have a bundle, so let's backstep character by character
@@ -424,7 +431,7 @@
         /* Back up one more to remove trailing '/' and set the '\0' */
         path[i] = '\0';
     }
-    free(tempbuf);
+    allocator.Free(tempbuf);
     return;
 }
 #endif /* defined __MACH__ && defined __APPLE__ */
@@ -437,7 +444,7 @@
 
     errno = 0;
     BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
-    retval = (char *) malloc(strlen(resolved_path) + 1);
+    retval = (char *) allocator.Malloc(strlen(resolved_path) + 1);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     strcpy(retval, resolved_path);
 
@@ -483,12 +490,13 @@
 void *__PHYSFS_platformCreateMutex(void)
 {
     int rc;
-    pthread_mutex_t *m = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t));
+    pthread_mutex_t *m;
+    m = (pthread_mutex_t *) allocator.Malloc(sizeof (pthread_mutex_t));
     BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL);
     rc = pthread_mutex_init(m, NULL);
     if (rc != 0)
     {
-        free(m);
+        allocator.Free(m);
         BAIL_MACRO(strerror(rc), NULL);
     } /* if */
 
@@ -499,7 +507,7 @@
 void __PHYSFS_platformDestroyMutex(void *mutex)
 {
     pthread_mutex_destroy((pthread_mutex_t *) mutex);
-    free(mutex);
+    allocator.Free(mutex);
 } /* __PHYSFS_platformDestroyMutex */
 
 
--- a/platform/win32.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/win32.c	Mon Mar 14 11:49:30 2005 +0000
@@ -111,7 +111,7 @@
     DWORD buflen;
     int success = 0;
     char *ptr = NULL;
-    char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
+    char *retval = (char *) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
@@ -159,12 +159,12 @@
 
     if (!success)
     {
-        free(retval);
+        allocator.Free(retval);
         return(NULL);  /* physfs error message will be set, above. */
     } /* if */
 
     /* free up the bytes we didn't actually use. */
-    ptr = (char *) realloc(retval, strlen(retval) + 1);
+    ptr = (char *) allocator.Realloc(retval, strlen(retval) + 1);
     if (ptr != NULL)
         retval = ptr;
 
@@ -221,12 +221,12 @@
                 assert(!rc);  /* success?! */
 
                 /* Allocate memory for the profile directory */
-                userDir = (char *) malloc(psize);
+                userDir = (char *) allocator.Malloc(psize);
                 if (userDir != NULL)
                 {
                     if (!GetUserProfileDirectory(accessToken, userDir, &psize))
                     {
-                        free(userDir);
+                        allocator.Free(userDir);
                         userDir = NULL;
                     } /* if */
                 } /* else */
@@ -297,12 +297,12 @@
 
     if (GetUserName(NULL, &bufsize) == 0)  /* This SHOULD fail. */
     {
-        retval = (LPTSTR) malloc(bufsize);
+        retval = (LPTSTR) allocator.Malloc(bufsize);
         BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
         if (GetUserName(retval, &bufsize) == 0)  /* ?! */
         {
             __PHYSFS_setError(win32strerror());
-            free(retval);
+            allocator.Free(retval);
             retval = NULL;
         } /* if */
     } /* if */
@@ -313,7 +313,7 @@
 
 char *__PHYSFS_platformGetUserDir(void)
 {
-    char *retval = (char *) malloc(strlen(userDir) + 1);
+    char *retval = (char *) allocator.Malloc(strlen(userDir) + 1);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     strcpy(retval, userDir); /* calculated at init time. */
     return(retval);
@@ -409,7 +409,7 @@
     int len = ((prepend) ? strlen(prepend) : 0) +
               ((append) ? strlen(append) : 0) +
               strlen(dirName) + 1;
-    char *retval = malloc(len);
+    char *retval = (char *) allocator.Malloc(len);
     char *p;
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -491,7 +491,7 @@
     DWORD buflen = 0;
 
     buflen = GetCurrentDirectory(buflen, NULL);
-    retval = (LPTSTR) malloc(sizeof (TCHAR) * (buflen + 2));
+    retval = (LPTSTR) allocator.Malloc(sizeof (TCHAR) * (buflen + 2));
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
     GetCurrentDirectory(buflen, retval);
 
@@ -511,7 +511,7 @@
     BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
     BAIL_IF_MACRO(*path == '\0', ERR_INVALID_ARGUMENT, NULL);
 
-    retval = (char *) malloc(MAX_PATH);
+    retval = (char *) allocator.Malloc(MAX_PATH);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
         /*
@@ -526,7 +526,7 @@
         char *currentDir = __PHYSFS_platformCurrentDir();
         if (currentDir == NULL)
         {
-            free(retval);
+            allocator.Free(retval);
             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
         } /* if */
 
@@ -572,7 +572,7 @@
             } /* else */
         } /* else */
 
-        free(currentDir);
+        allocator.Free(currentDir);
     } /* else */
 
     /* (whew.) Ok, now take out "." and ".." path entries... */
@@ -615,7 +615,7 @@
     } /* while */
 
         /* shrink the retval's memory block if possible... */
-    p = (char *) realloc(retval, strlen(retval) + 1);
+    p = (char *) allocator.Realloc(retval, strlen(retval) + 1);
     if (p != NULL)
         retval = p;
 
@@ -708,7 +708,7 @@
 {
     if (userDir != NULL)
     {
-        free(userDir);
+        allocator.Free(userDir);
         userDir = NULL;
     } /* if */
 
@@ -736,7 +736,7 @@
         win32strerror(), NULL
     );
 
-    retval = malloc(sizeof (win32file));
+    retval = (win32file *) allocator.Malloc(sizeof (win32file));
     if (retval == NULL)
     {
         CloseHandle(fileHandle);
@@ -772,7 +772,7 @@
         {
             const char *err = win32strerror();
             CloseHandle(h);
-            free(retval);
+            allocator.Free(retval);
             BAIL_MACRO(err, NULL);
         } /* if */
     } /* if */
@@ -946,7 +946,7 @@
 {
     HANDLE Handle = ((win32file *) opaque)->handle;
     BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
-    free(opaque);
+    allocator.Free(opaque);
     return(1);
 } /* __PHYSFS_platformClose */
 
@@ -1100,7 +1100,7 @@
         rc = GetFileTime(f->handle, NULL, NULL, &ft);
         err = win32strerror();
         CloseHandle(f->handle);
-        free(f);
+        allocator.Free(f);
         BAIL_IF_MACRO(!rc, err, -1);
         retval = FileTimeToPhysfsTime(&ft);
     } /* if */
@@ -1108,6 +1108,40 @@
     return(retval);
 } /* __PHYSFS_platformGetLastModTime */
 
+
+/* !!! FIXME: Don't use C runtime for allocators? */
+int __PHYSFS_platformAllocatorInit(void)
+{
+    return(1);  /* always succeeds. */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void __PHYSFS_platformAllocatorDeinit(void)
+{
+    /* no-op */
+} /* __PHYSFS_platformAllocatorInit */
+
+
+void *__PHYSFS_platformAllocatorMalloc(size_t s)
+{
+    #undef malloc
+    return(malloc(s));
+} /* __PHYSFS_platformMalloc */
+
+
+void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
+{
+    #undef realloc
+    return(realloc(ptr, s));
+} /* __PHYSFS_platformRealloc */
+
+
+void __PHYSFS_platformAllocatorFree(void *ptr)
+{
+    #undef free
+    free(ptr);
+} /* __PHYSFS_platformAllocatorFree */
+
 #endif
 
 /* end of win32.c ... */