From DONOTREPLY at icculus.org Tue Sep 6 02:24:43 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 6 Sep 2005 02:24:43 -0400 Subject: r762 - in trunk: . platform Message-ID: <20050906062443.31538.qmail@icculus.org> Author: icculus Date: 2005-09-06 02:24:42 -0400 (Tue, 06 Sep 2005) New Revision: 762 Modified: trunk/CHANGELOG trunk/physfs.h trunk/physfs_internal.h trunk/platform/macclassic.c trunk/platform/os2.c trunk/platform/pocketpc.c trunk/platform/posix.c trunk/platform/skeleton.c trunk/platform/win32.c Log: Don't use size_t in physfs.h, since it relies on C runtime headers. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/CHANGELOG 2005-09-06 06:24:42 UTC (rev 762) @@ -2,6 +2,9 @@ * CHANGELOG. */ +09062005 - Happy September. Changed the allocation abstraction to use + PHYSFS_uint64 instead of size_t, so we don't have to include + system headers inside physfs.h. 08202005 - Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig() and other corner cases. 07242005 - Patched to compile on BeOS. Modified: trunk/physfs.h =================================================================== --- trunk/physfs.h 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/physfs.h 2005-09-06 06:24:42 UTC (rev 762) @@ -1857,14 +1857,21 @@ * Allocators are assumed to be reentrant by the caller; please mutex * accordingly. * + * Allocations are always discussed in 64-bits, for future expansion...we're + * on the cusp of a 64-bit transition, and we'll probably be allocating 6 + * gigabytes like it's nothing sooner or later, and I don't want to change + * this again at that point. If you're on a 32-bit platform and have to + * downcast, it's okay to return NULL if the allocation is greater than + * 4 gigabytes, since you'd have to do so anyhow. + * * \sa PHYSFS_setAllocator */ typedef struct { int (*Init)(void); void (*Deinit)(void); - void *(*Malloc)(size_t); - void *(*Realloc)(void *, size_t); + void *(*Malloc)(PHYSFS_uint64); + void *(*Realloc)(void *, PHYSFS_uint64); void (*Free)(void *); } PHYSFS_Allocator; Modified: trunk/physfs_internal.h =================================================================== --- trunk/physfs_internal.h 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/physfs_internal.h 2005-09-06 06:24:42 UTC (rev 762) @@ -1682,14 +1682,14 @@ * This is used for allocation if the user hasn't selected their own * allocator via PHYSFS_setAllocator(). */ -void *__PHYSFS_platformAllocatorMalloc(size_t s); +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s); /* * Implement realloc. It's safe to just pass through from the C runtime. * This is used for allocation if the user hasn't selected their own * allocator via PHYSFS_setAllocator(). */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s); +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s); /* * Implement free. It's safe to just pass through from the C runtime. Modified: trunk/platform/macclassic.c =================================================================== --- trunk/platform/macclassic.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/macclassic.c 2005-09-06 06:24:42 UTC (rev 762) @@ -939,17 +939,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ Modified: trunk/platform/os2.c =================================================================== --- trunk/platform/os2.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/os2.c 2005-09-06 06:24:42 UTC (rev 762) @@ -754,17 +754,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ Modified: trunk/platform/pocketpc.c =================================================================== --- trunk/platform/pocketpc.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/pocketpc.c 2005-09-06 06:24:42 UTC (rev 762) @@ -672,17 +672,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ Modified: trunk/platform/posix.c =================================================================== --- trunk/platform/posix.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/posix.c 2005-09-06 06:24:42 UTC (rev 762) @@ -514,17 +514,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ Modified: trunk/platform/skeleton.c =================================================================== --- trunk/platform/skeleton.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/skeleton.c 2005-09-06 06:24:42 UTC (rev 762) @@ -246,17 +246,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ Modified: trunk/platform/win32.c =================================================================== --- trunk/platform/win32.c 2005-08-20 04:46:25 UTC (rev 761) +++ trunk/platform/win32.c 2005-09-06 06:24:42 UTC (rev 762) @@ -1122,17 +1122,23 @@ } /* __PHYSFS_platformAllocatorInit */ -void *__PHYSFS_platformAllocatorMalloc(size_t s) +void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef malloc - return(malloc(s)); + return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */ -void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s) +void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { + /* make sure s isn't larger than the address space of the platform... */ + if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) ) + BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); #undef realloc - return(realloc(ptr, s)); + return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */ From DONOTREPLY at icculus.org Tue Sep 6 02:25:48 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 6 Sep 2005 02:25:48 -0400 Subject: r763 - in trunk: . platform Message-ID: <20050906062548.31642.qmail@icculus.org> Author: icculus Date: 2005-09-06 02:25:48 -0400 (Tue, 06 Sep 2005) New Revision: 763 Modified: trunk/configure.in trunk/platform/win32.c Log: Some minor (albeit incomplete) MingW fixes. Modified: trunk/configure.in =================================================================== --- trunk/configure.in 2005-09-06 06:24:42 UTC (rev 762) +++ trunk/configure.in 2005-09-06 06:25:48 UTC (rev 763) @@ -399,8 +399,13 @@ AC_MSG_RESULT([$this_is_cygwin]) AC_MSG_CHECKING([if this is mingw]) +if test x$target_os = xmingw32; then + this_is_mingw=yes +fi if test x$target_os = xmingw32msvc; then this_is_mingw=yes +fi +if test x$this_is_mingw = xyes; then PHYSFSCFLAGS="$PHYSFSCFLAGS -DWIN32" enable_cdrom=yes enable_pthreads=no Modified: trunk/platform/win32.c =================================================================== --- trunk/platform/win32.c 2005-09-06 06:24:42 UTC (rev 762) +++ trunk/platform/win32.c 2005-09-06 06:25:48 UTC (rev 763) @@ -25,7 +25,7 @@ #if (defined _MSC_VER) #define alloca(x) _alloca(x) -#elif (defined MINGW) /* scary...hopefully this is okay. */ +#elif (defined __MINGW32__) /* scary...hopefully this is okay. */ #define alloca(x) __builtin_alloca(x) #endif From DONOTREPLY at icculus.org Tue Sep 6 02:28:35 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 6 Sep 2005 02:28:35 -0400 Subject: r764 - trunk Message-ID: <20050906062835.31857.qmail@icculus.org> Author: icculus Date: 2005-09-06 02:28:35 -0400 (Tue, 06 Sep 2005) New Revision: 764 Modified: trunk/CHANGELOG Log: Updated. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-06 06:25:48 UTC (rev 763) +++ trunk/CHANGELOG 2005-09-06 06:28:35 UTC (rev 764) @@ -4,7 +4,8 @@ 09062005 - Happy September. Changed the allocation abstraction to use PHYSFS_uint64 instead of size_t, so we don't have to include - system headers inside physfs.h. + system headers inside physfs.h. Minor MingW fixes (but it's still + broken, I think). 08202005 - Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig() and other corner cases. 07242005 - Patched to compile on BeOS. From DONOTREPLY at icculus.org Tue Sep 6 02:31:04 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 6 Sep 2005 02:31:04 -0400 Subject: r765 - in branches/stable-1.0: . platform Message-ID: <20050906063104.32050.qmail@icculus.org> Author: icculus Date: 2005-09-06 02:31:04 -0400 (Tue, 06 Sep 2005) New Revision: 765 Modified: branches/stable-1.0/CHANGELOG branches/stable-1.0/configure.in branches/stable-1.0/platform/win32.c Log: Minor MingW patches backported from dev branch. Modified: branches/stable-1.0/CHANGELOG =================================================================== --- branches/stable-1.0/CHANGELOG 2005-09-06 06:28:35 UTC (rev 764) +++ branches/stable-1.0/CHANGELOG 2005-09-06 06:31:04 UTC (rev 765) @@ -4,6 +4,7 @@ -- stuff in the stable-1.0 branch, backported from 2.0.0 dev branch, etc --- +09062005 - Happy September. Minor MingW fixes (but it's still broken, I think). 07232005 - Fixed bug in zip archiver (thanks, J?rg Walter!). Updated zlib to 1.2.3, which properly includes the security fix. Fixed "make dist" to handle .svn dirs and other file changes. Removed "debian" Modified: branches/stable-1.0/configure.in =================================================================== --- branches/stable-1.0/configure.in 2005-09-06 06:28:35 UTC (rev 764) +++ branches/stable-1.0/configure.in 2005-09-06 06:31:04 UTC (rev 765) @@ -383,8 +383,13 @@ AC_MSG_RESULT([$this_is_cygwin]) AC_MSG_CHECKING([if this is mingw]) +if test x$target_os = xmingw32; then + this_is_mingw=yes +fi if test x$target_os = xmingw32msvc; then this_is_mingw=yes +fi +if test x$this_is_mingw = xyes; then PHYSFSCFLAGS="$PHYSFSCFLAGS -DWIN32" enable_cdrom=yes enable_pthreads=no Modified: branches/stable-1.0/platform/win32.c =================================================================== --- branches/stable-1.0/platform/win32.c 2005-09-06 06:28:35 UTC (rev 764) +++ branches/stable-1.0/platform/win32.c 2005-09-06 06:31:04 UTC (rev 765) @@ -25,7 +25,7 @@ #if (defined _MSC_VER) #define alloca(x) _alloca(x) -#elif (defined MINGW) /* scary...hopefully this is okay. */ +#elif (defined __MINGW32__) /* scary...hopefully this is okay. */ #define alloca(x) __builtin_alloca(x) #endif From DONOTREPLY at icculus.org Fri Sep 9 10:07:43 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Sep 2005 10:07:43 -0400 Subject: r766 - trunk Message-ID: <20050909140743.13031.qmail@icculus.org> Author: icculus Date: 2005-09-09 10:07:43 -0400 (Fri, 09 Sep 2005) New Revision: 766 Modified: trunk/CHANGELOG trunk/physfs.c trunk/physfs.h Log: Some tweaks to PHYSFS_Allocator. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-06 06:31:04 UTC (rev 765) +++ trunk/CHANGELOG 2005-09-09 14:07:43 UTC (rev 766) @@ -2,6 +2,7 @@ * CHANGELOG. */ +09092005 - Some tweaks to PHYSFS_Allocator. 09062005 - Happy September. Changed the allocation abstraction to use PHYSFS_uint64 instead of size_t, so we don't have to include system headers inside physfs.h. Minor MingW fixes (but it's still Modified: trunk/physfs.c =================================================================== --- trunk/physfs.c 2005-09-06 06:31:04 UTC (rev 765) +++ trunk/physfs.c 2005-09-09 14:07:43 UTC (rev 766) @@ -777,7 +777,8 @@ if (!externalAllocator) setDefaultAllocator(); - BAIL_IF_MACRO(!allocator.Init(), NULL, 0); + if (allocator.Init != NULL) + BAIL_IF_MACRO(!allocator.Init(), NULL, 0); BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0); @@ -889,7 +890,8 @@ __PHYSFS_platformDestroyMutex(errorLock); __PHYSFS_platformDestroyMutex(stateLock); - allocator.Deinit(); + if (allocator.Deinit != NULL) + allocator.Deinit(); errorLock = stateLock = NULL; return(1); @@ -2047,7 +2049,7 @@ } /* PHYSFS_flush */ -int PHYSFS_setAllocator(PHYSFS_Allocator *a) +int PHYSFS_setAllocator(const PHYSFS_Allocator *a) { BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); externalAllocator = (a != NULL); Modified: trunk/physfs.h =================================================================== --- trunk/physfs.h 2005-09-06 06:31:04 UTC (rev 765) +++ trunk/physfs.h 2005-09-09 14:07:43 UTC (rev 766) @@ -1847,7 +1847,7 @@ /* Everything above this line is part of the PhysicsFS 1.0 API. */ /** - * \struct PHYSFS_allocator + * \struct PHYSFS_Allocator * \brief PhysicsFS allocation function pointers. * * (This is for limited, hardcore use. If you don't immediately see a need @@ -1868,16 +1868,16 @@ */ typedef struct { - int (*Init)(void); - void (*Deinit)(void); - void *(*Malloc)(PHYSFS_uint64); - void *(*Realloc)(void *, PHYSFS_uint64); - void (*Free)(void *); + int (*Init)(void); /**< Initialize. Can be NULL. Zero on failure. */ + void (*Deinit)(void); /**< Deinitialize your allocator. Can be NULL. */ + void *(*Malloc)(PHYSFS_uint64); /**< Allocate like malloc(). */ + void *(*Realloc)(void *, PHYSFS_uint64); /**< Reallocate like realloc(). */ + void (*Free)(void *); /**< Free memory from Malloc or Realloc. */ } PHYSFS_Allocator; /** - * \fn int PHYSFS_setAllocator(PHYSFS_Allocator *allocator) + * \fn int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator) * \brief Hook your own allocation routines into PhysicsFS. * * (This is for limited, hardcore use. If you don't immediately see a need @@ -1903,7 +1903,7 @@ * \return zero on failure, non-zero on success. This call only fails * when used between PHYSFS_init() and PHYSFS_deinit() calls. */ -__EXPORT__ int PHYSFS_setAllocator(PHYSFS_Allocator *allocator); +__EXPORT__ int PHYSFS_setAllocator(const PHYSFS_Allocator *allocator); /** From DONOTREPLY at icculus.org Fri Sep 9 10:08:45 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Sep 2005 10:08:45 -0400 Subject: r767 - trunk Message-ID: <20050909140845.13204.qmail@icculus.org> Author: icculus Date: 2005-09-09 10:08:44 -0400 (Fri, 09 Sep 2005) New Revision: 767 Modified: trunk/ Log: Subversion should ignore "docs" directory if it exists. Property changes on: trunk ___________________________________________________________________ Name: svn:ignore - physfs_static_debug physfs_static_release depcomp Makefile .deps .libs aclocal.m4 config.status ltmain.sh configure libtool physfs.lo config.guess install-sh config.log config.sub missing stamp-h mkinstalldirs config.h Makefile.in config.h.in libphysfs.la stamp-h.in stamp-h1 physfs_byteorder.lo ltconfig inftrees.lo trees.lo uncompr.lo zutil.lo infcodes.lo unzip.lo inflate.lo adler32.lo posix.lo infblock.lo compress.lo dir.lo inffast.lo grp.lo test_physfs unix.lo crc32.lo zip.lo infutil.lo deflate.lo beos.lo Makefile.am config.cache autom4te.cache configure.lineno physfs.spec + physfs_static_debug physfs_static_release depcomp Makefile .deps .libs aclocal.m4 config.status ltmain.sh configure libtool physfs.lo config.guess install-sh config.log config.sub missing stamp-h mkinstalldirs config.h Makefile.in config.h.in libphysfs.la stamp-h.in stamp-h1 physfs_byteorder.lo ltconfig inftrees.lo trees.lo uncompr.lo zutil.lo infcodes.lo unzip.lo inflate.lo adler32.lo posix.lo infblock.lo compress.lo dir.lo inffast.lo grp.lo test_physfs unix.lo crc32.lo zip.lo infutil.lo deflate.lo beos.lo Makefile.am config.cache autom4te.cache configure.lineno physfs.spec docs From DONOTREPLY at icculus.org Fri Sep 9 16:35:18 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Sep 2005 16:35:18 -0400 Subject: r768 - trunk Message-ID: <20050909203518.13146.qmail@icculus.org> Author: icculus Date: 2005-09-09 16:35:18 -0400 (Fri, 09 Sep 2005) New Revision: 768 Modified: trunk/CHANGELOG trunk/configure.in Log: Hopefully fixing ABI with 1.0... Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-09 14:08:44 UTC (rev 767) +++ trunk/CHANGELOG 2005-09-09 20:35:18 UTC (rev 768) @@ -2,7 +2,9 @@ * CHANGELOG. */ -09092005 - Some tweaks to PHYSFS_Allocator. +09092005 - Some tweaks to PHYSFS_Allocator. Apparently configure.in doesn't + work like I thought for version bumps, so it thinks 1.1.0 isn't + binary compatible with 1.0...fixed, I think. 09062005 - Happy September. Changed the allocation abstraction to use PHYSFS_uint64 instead of size_t, so we don't have to include system headers inside physfs.h. Minor MingW fixes (but it's still Modified: trunk/configure.in =================================================================== --- trunk/configure.in 2005-09-09 14:08:44 UTC (rev 767) +++ trunk/configure.in 2005-09-09 20:35:18 UTC (rev 768) @@ -14,10 +14,10 @@ # set BINARY_AGE and INTERFACE_AGE to 0. MAJOR_VERSION=1 -MINOR_VERSION=1 -MICRO_VERSION=0 -INTERFACE_AGE=0 -BINARY_AGE=0 +MINOR_VERSION=0 +MICRO_VERSION=1 +INTERFACE_AGE=1 +BINARY_AGE=1 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION AC_SUBST(MAJOR_VERSION) From DONOTREPLY at icculus.org Sun Sep 18 17:44:43 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Sep 2005 17:44:43 -0400 Subject: r769 - in trunk: . archivers platform Message-ID: <20050918214443.31510.qmail@icculus.org> Author: icculus Date: 2005-09-18 17:44:42 -0400 (Sun, 18 Sep 2005) New Revision: 769 Modified: trunk/CHANGELOG trunk/archivers/dir.c trunk/archivers/grp.c trunk/archivers/hog.c trunk/archivers/mix.c trunk/archivers/mvl.c trunk/archivers/qpak.c trunk/archivers/wad.c trunk/archivers/zip.c trunk/physfs.c trunk/physfs.h trunk/physfs_internal.h trunk/platform/macclassic.c trunk/platform/os2.c trunk/platform/pocketpc.c trunk/platform/posix.c trunk/platform/skeleton.c trunk/platform/win32.c Log: API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally requested directory back to the app. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/CHANGELOG 2005-09-18 21:44:42 UTC (rev 769) @@ -2,6 +2,10 @@ * CHANGELOG. */ +09182005 - API BREAKAGE: PHYSFS_enumerateFilesCallback() now passes the + original directory name back to the app in the callback. This + API was only in 1.1.0, and wasn't promised to be stable at this + point. Please update your apps. 09092005 - Some tweaks to PHYSFS_Allocator. Apparently configure.in doesn't work like I thought for version bumps, so it thinks 1.1.0 isn't binary compatible with 1.0...fixed, I think. Modified: trunk/archivers/dir.c =================================================================== --- trunk/archivers/dir.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/dir.c 2005-09-18 21:44:42 UTC (rev 769) @@ -104,13 +104,14 @@ static void DIR_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { char *d = __PHYSFS_platformCvtToDependent((char *)opaque, dname, NULL); if (d != NULL) { - __PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata); + __PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, + origdir, callbackdata); allocator.Free(d); } /* if */ } /* DIR_enumerateFiles */ Modified: trunk/archivers/grp.c =================================================================== --- trunk/archivers/grp.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/grp.c 2005-09-18 21:44:42 UTC (rev 769) @@ -295,8 +295,8 @@ static void GRP_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { /* no directories in GRP files. */ if (*dname != '\0') @@ -307,7 +307,7 @@ PHYSFS_uint32 i; for (i = 0; i < max; i++, entry++) - cb(callbackdata, entry->name); + cb(callbackdata, origdir, entry->name); } /* if */ } /* GRP_enumerateFiles */ Modified: trunk/archivers/hog.c =================================================================== --- trunk/archivers/hog.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/hog.c 2005-09-18 21:44:42 UTC (rev 769) @@ -334,8 +334,8 @@ static void HOG_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { /* no directories in HOG files. */ if (*dname != '\0') @@ -346,7 +346,7 @@ PHYSFS_uint32 i; for (i = 0; i < max; i++, entry++) - cb(callbackdata, entry->name); + cb(callbackdata, origdir, entry->name); } /* if */ } /* HOG_enumerateFiles */ Modified: trunk/archivers/mix.c =================================================================== --- trunk/archivers/mix.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/mix.c 2005-09-18 21:44:42 UTC (rev 769) @@ -288,8 +288,8 @@ static void MIX_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { /* no directories in MIX files. */ if (*dirname != '\0') @@ -302,7 +302,7 @@ for (i = 0; i < info->header.num_files; i++, entry++) { sprintf(buffer, "%X", entry->hash); - cb(callbackdata, buffer); + cb(callbackdata, origdir, buffer); } /* for */ } /* if */ } /* MIX_enumerateFiles */ Modified: trunk/archivers/mvl.c =================================================================== --- trunk/archivers/mvl.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/mvl.c 2005-09-18 21:44:42 UTC (rev 769) @@ -291,8 +291,8 @@ static void MVL_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { /* no directories in MVL files. */ if (*dname != '\0') @@ -303,7 +303,7 @@ PHYSFS_uint32 i; for (i = 0; i < max; i++, entry++) - cb(callbackdata, entry->name); + cb(callbackdata, origdir, entry->name); } /* if */ } /* MVL_enumerateFiles */ Modified: trunk/archivers/qpak.c =================================================================== --- trunk/archivers/qpak.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/qpak.c 2005-09-18 21:44:42 UTC (rev 769) @@ -379,8 +379,8 @@ * Moved to seperate function so we can use alloca then immediately throw * away the allocated stack space... */ -static void doEnumCallback(PHYSFS_StringCallback cb, void *callbackdata, - const char *str, PHYSFS_sint32 ln) +static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata, + const char *odir, const char *str, PHYSFS_sint32 ln) { char *newstr = alloca(ln + 1); if (newstr == NULL) @@ -388,13 +388,13 @@ memcpy(newstr, str, ln); newstr[ln] = '\0'; - cb(callbackdata, newstr); + cb(callbackdata, odir, newstr); } /* doEnumCallback */ static void QPAK_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { QPAKinfo *info = ((QPAKinfo *) opaque); PHYSFS_sint32 dlen, dlen_inc, max, i; @@ -421,7 +421,7 @@ add = e + dlen_inc; ptr = strchr(add, '/'); ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add)); - doEnumCallback(cb, callbackdata, add, ln); + doEnumCallback(cb, callbackdata, origdir, add, ln); ln += dlen_inc; /* point past entry to children... */ /* increment counter and skip children of subdirs... */ Modified: trunk/archivers/wad.c =================================================================== --- trunk/archivers/wad.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/wad.c 2005-09-18 21:44:42 UTC (rev 769) @@ -322,8 +322,8 @@ static void WAD_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { WADinfo *info = ((WADinfo *) opaque); WADentry *entry = info->entries; @@ -338,7 +338,7 @@ { name = entry->name; if (strchr(name, '/') == NULL) - cb(callbackdata, name); + cb(callbackdata, origdir, name); } /* for */ } /* if */ else Modified: trunk/archivers/zip.c =================================================================== --- trunk/archivers/zip.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/archivers/zip.c 2005-09-18 21:44:42 UTC (rev 769) @@ -1178,8 +1178,8 @@ * Moved to seperate function so we can use alloca then immediately throw * away the allocated stack space... */ -static void doEnumCallback(PHYSFS_StringCallback cb, void *callbackdata, - const char *str, PHYSFS_sint32 ln) +static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata, + const char *odir, const char *str, PHYSFS_sint32 ln) { char *newstr = alloca(ln + 1); if (newstr == NULL) @@ -1187,13 +1187,13 @@ memcpy(newstr, str, ln); newstr[ln] = '\0'; - cb(callbackdata, newstr); + cb(callbackdata, odir, newstr); } /* doEnumCallback */ static void ZIP_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_StringCallback cb, - void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { ZIPinfo *info = ((ZIPinfo *) opaque); PHYSFS_sint32 dlen, dlen_inc, max, i; @@ -1221,7 +1221,7 @@ char *add = e + dlen_inc; char *ptr = strchr(add, '/'); PHYSFS_sint32 ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add)); - doEnumCallback(cb, callbackdata, add, ln); + doEnumCallback(cb, callbackdata, origdir, add, ln); ln += dlen_inc; /* point past entry to children... */ /* increment counter and skip children of subdirs... */ Modified: trunk/physfs.c =================================================================== --- trunk/physfs.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/physfs.c 2005-09-18 21:44:42 UTC (rev 769) @@ -1494,7 +1494,7 @@ } /* locateInStringList */ -static void enumFilesCallback(void *data, const char *str) +static void enumFilesCallback(void *data, const char *origdir, const char *str) { PHYSFS_uint32 pos; void *ptr; @@ -1546,7 +1546,7 @@ void PHYSFS_enumerateFilesCallback(const char *_fname, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, void *data) { DirHandle *i; @@ -1570,13 +1570,14 @@ char *end = strchr(ptr, '/'); assert(end); /* should always find a terminating '/'. */ *end = '\0'; /* !!! FIXME: not safe in a callback... */ - callback(data, ptr); + callback(data, _fname, ptr); *end = '/'; /* !!! FIXME: not safe in a callback... */ } /* if */ else if (verifyPath(i, &arcfname, 0)) { - i->funcs->enumerateFiles(i->opaque,arcfname,noSyms,callback,data); + i->funcs->enumerateFiles(i->opaque, arcfname, noSyms, + callback, _fname, data); } /* else if */ } /* for */ __PHYSFS_platformReleaseMutex(stateLock); Modified: trunk/physfs.h =================================================================== --- trunk/physfs.h 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/physfs.h 2005-09-18 21:44:42 UTC (rev 769) @@ -1978,14 +1978,15 @@ * be holding non recursive mutexes. */ /* !!! FIXME: comment! */ -typedef void (*PHYSFS_StringCallback)(void *data, const char *); +typedef void (*PHYSFS_StringCallback)(void *, const char *); +typedef void (*PHYSFS_EnumFilesCallback)(void *, const char *, const char *); __EXPORT__ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback c, void *d); __EXPORT__ void PHYSFS_getSearchPathCallback(PHYSFS_StringCallback c, void *d); __EXPORT__ void PHYSFS_enumerateFilesCallback(const char *dir, - PHYSFS_StringCallback c, + PHYSFS_EnumFilesCallback c, void *d); Modified: trunk/physfs_internal.h =================================================================== --- trunk/physfs_internal.h 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/physfs_internal.h 2005-09-18 21:44:42 UTC (rev 769) @@ -995,7 +995,8 @@ void (*enumerateFiles)(dvoid *opaque, const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata); /* @@ -1568,7 +1569,8 @@ */ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata); Modified: trunk/platform/macclassic.c =================================================================== --- trunk/platform/macclassic.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/macclassic.c 2005-09-18 21:44:42 UTC (rev 769) @@ -563,7 +563,8 @@ /* returns int so we can use BAIL*MACRO... */ static int macClassicEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { UInt16 i; @@ -618,7 +619,7 @@ size = (size_t) str255[0]; /* (convert to ASCIZ string...) */ memmove(&str255[0], &str255[1], size); str255[size] = '\0'; - callback(callbackdata, (const char *) str255); + callback(callbackdata, origdir, (const char *) str255); } /* for */ return(1); @@ -627,10 +628,12 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { - macClassicEnumerateFiles(dirname, omitSymLinks, callback, callbackdata); + macClassicEnumerateFiles(dirname, omitSymLinks, callback, + origdir, callbackdata); } /* __PHYSFS_platformEnumerateFiles */ Modified: trunk/platform/os2.c =================================================================== --- trunk/platform/os2.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/os2.c 2005-09-18 21:44:42 UTC (rev 769) @@ -398,7 +398,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { char spec[CCHMAXPATH]; @@ -427,7 +428,7 @@ while (count == 1) { if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0)) - callback(callbackdata, fb.achName); + callback(callbackdata, origdir, fb.achName); DosFindNext(hdir, &fb, sizeof (fb), &count); } /* while */ Modified: trunk/platform/pocketpc.c =================================================================== --- trunk/platform/pocketpc.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/pocketpc.c 2005-09-18 21:44:42 UTC (rev 769) @@ -296,7 +296,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { HANDLE dir; @@ -346,7 +347,7 @@ if (str == NULL) break; - callback(callbackdata, str); + callback(callbackdata, origdir, str); allocator.Free(str); } while (FindNextFile(dir, &ent) != 0); Modified: trunk/platform/posix.c =================================================================== --- trunk/platform/posix.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/posix.c 2005-09-18 21:44:42 UTC (rev 769) @@ -227,7 +227,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { DIR *dir; @@ -286,7 +287,7 @@ continue; } /* if */ - callback(callbackdata, ent->d_name); + callback(callbackdata, origdir, ent->d_name); } /* while */ if (buf != NULL) Modified: trunk/platform/skeleton.c =================================================================== --- trunk/platform/skeleton.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/skeleton.c 2005-09-18 21:44:42 UTC (rev 769) @@ -106,7 +106,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { } /* __PHYSFS_platformEnumerateFiles */ Modified: trunk/platform/win32.c =================================================================== --- trunk/platform/win32.c 2005-09-09 20:35:18 UTC (rev 768) +++ trunk/platform/win32.c 2005-09-18 21:44:42 UTC (rev 769) @@ -440,7 +440,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks, - PHYSFS_StringCallback callback, + PHYSFS_EnumFilesCallback callback, + const char *origdir, void *callbackdata) { HANDLE dir; @@ -478,7 +479,7 @@ if (strcmp(ent.cFileName, "..") == 0) continue; - callback(callbackdata, ent.cFileName); + callback(callbackdata, origdir, ent.cFileName); } while (FindNextFile(dir, &ent) != 0); FindClose(dir); From DONOTREPLY at icculus.org Sun Sep 18 18:27:05 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Sep 2005 18:27:05 -0400 Subject: r770 - trunk Message-ID: <20050918222705.3221.qmail@icculus.org> Author: icculus Date: 2005-09-18 18:27:05 -0400 (Sun, 18 Sep 2005) New Revision: 770 Modified: trunk/CHANGELOG trunk/physfs.c Log: Don't leave internal structures temporarily modified before calling an application callback, so that state is sane if they call into the API from inside the callback. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-18 21:44:42 UTC (rev 769) +++ trunk/CHANGELOG 2005-09-18 22:27:05 UTC (rev 770) @@ -5,7 +5,9 @@ 09182005 - API BREAKAGE: PHYSFS_enumerateFilesCallback() now passes the original directory name back to the app in the callback. This API was only in 1.1.0, and wasn't promised to be stable at this - point. Please update your apps. + point. Please update your apps! Cleaned out a FIXME in file + enumeration that would confuse the library under certain + circumstances. 09092005 - Some tweaks to PHYSFS_Allocator. Apparently configure.in doesn't work like I thought for version bumps, so it thinks 1.1.0 isn't binary compatible with 1.0...fixed, I think. Modified: trunk/physfs.c =================================================================== --- trunk/physfs.c 2005-09-18 21:44:42 UTC (rev 769) +++ trunk/physfs.c 2005-09-18 22:27:05 UTC (rev 770) @@ -1545,6 +1545,25 @@ } /* PHYSFS_enumerateFiles */ +/* + * Broke out to seperate function so we can use alloca() gratuitously. + */ +static void enumerateFromMountPoint(DirHandle *i, const char *arcfname, + PHYSFS_EnumFilesCallback callback, + const char *_fname, void *data) +{ + size_t len = strlen(arcfname); + char *mountPoint = (char *) alloca(strlen(i->mountPoint) + 1); + strcpy(mountPoint, i->mountPoint); + char *ptr = mountPoint + ((len) ? len + 1 : 0); + char *end = strchr(ptr, '/'); + assert(end); /* should always find a terminating '/'. */ + *end = '\0'; + callback(data, _fname, ptr); +} /* enumerateFromMountPoint */ + + + void PHYSFS_enumerateFilesCallback(const char *_fname, PHYSFS_EnumFilesCallback callback, void *data) @@ -1564,15 +1583,7 @@ { char *arcfname = fname; if (partOfMountPoint(i, arcfname)) - { - size_t len = strlen(arcfname); - char *ptr = i->mountPoint + ((len) ? len + 1 : 0); - char *end = strchr(ptr, '/'); - assert(end); /* should always find a terminating '/'. */ - *end = '\0'; /* !!! FIXME: not safe in a callback... */ - callback(data, _fname, ptr); - *end = '/'; /* !!! FIXME: not safe in a callback... */ - } /* if */ + enumerateFromMountPoint(i, arcfname, callback, _fname, data); else if (verifyPath(i, &arcfname, 0)) { From DONOTREPLY at icculus.org Sun Sep 18 18:27:57 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Sep 2005 18:27:57 -0400 Subject: r771 - trunk Message-ID: <20050918222757.3395.qmail@icculus.org> Author: icculus Date: 2005-09-18 18:27:57 -0400 (Sun, 18 Sep 2005) New Revision: 771 Modified: trunk/TODO Log: Updated. Modified: trunk/TODO =================================================================== --- trunk/TODO 2005-09-18 22:27:05 UTC (rev 770) +++ trunk/TODO 2005-09-18 22:27:57 UTC (rev 771) @@ -46,6 +46,7 @@ - Look for calloc() calls that aren't going through the allocation hooks. - maybe other stuff. - Is -Wall enabled? +- Make mutexes recursive, so callbacks can call into the API. // end of TODO ... From DONOTREPLY at icculus.org Tue Sep 20 00:01:36 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 20 Sep 2005 00:01:36 -0400 Subject: r772 - in trunk: . platform Message-ID: <20050920040136.18673.qmail@icculus.org> Author: icculus Date: 2005-09-20 00:01:36 -0400 (Tue, 20 Sep 2005) New Revision: 772 Modified: trunk/CHANGELOG trunk/platform/unix.c Log: Made unix mutexes recursive. Modified: trunk/CHANGELOG =================================================================== --- trunk/CHANGELOG 2005-09-18 22:27:57 UTC (rev 771) +++ trunk/CHANGELOG 2005-09-20 04:01:36 UTC (rev 772) @@ -2,6 +2,8 @@ * CHANGELOG. */ +09192005 - Make unix mutexes recursive above pthread layer...fixes deadlock on + MacOS X, for now. 09182005 - API BREAKAGE: PHYSFS_enumerateFilesCallback() now passes the original directory name back to the app in the callback. This API was only in 1.1.0, and wasn't promised to be stable at this Modified: trunk/platform/unix.c =================================================================== --- trunk/platform/unix.c 2005-09-18 22:27:57 UTC (rev 771) +++ trunk/platform/unix.c 2005-09-20 04:01:36 UTC (rev 772) @@ -466,6 +466,13 @@ #else +typedef struct +{ + pthread_mutex_t mutex; + pthread_t owner; + PHYSFS_uint32 count; +} PthreadMutex; + /* Just in case; this is a panic value. */ #if ((!defined SIZEOF_INT) || (SIZEOF_INT <= 0)) # define SIZEOF_INT 4 @@ -490,36 +497,61 @@ void *__PHYSFS_platformCreateMutex(void) { int rc; - pthread_mutex_t *m; - m = (pthread_mutex_t *) allocator.Malloc(sizeof (pthread_mutex_t)); + PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex)); BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); - rc = pthread_mutex_init(m, NULL); + rc = pthread_mutex_init(&m->mutex, NULL); if (rc != 0) { allocator.Free(m); BAIL_MACRO(strerror(rc), NULL); } /* if */ + m->count = 0; + m->owner = (pthread_t) 0xDEADBEEF; return((void *) m); } /* __PHYSFS_platformCreateMutex */ void __PHYSFS_platformDestroyMutex(void *mutex) { - pthread_mutex_destroy((pthread_mutex_t *) mutex); - allocator.Free(mutex); + PthreadMutex *m = (PthreadMutex *) mutex; + + /* Destroying a locked mutex is a bug, but we'll try to be helpful. */ + if ((m->owner == pthread_self()) && (m->count > 0)) + pthread_mutex_unlock(&m->mutex); + + pthread_mutex_destroy(&m->mutex); + allocator.Free(m); } /* __PHYSFS_platformDestroyMutex */ int __PHYSFS_platformGrabMutex(void *mutex) { - return(pthread_mutex_lock((pthread_mutex_t *) mutex) == 0); + PthreadMutex *m = (PthreadMutex *) mutex; + pthread_t tid = pthread_self(); + if (m->owner != tid) + { + if (pthread_mutex_lock(&m->mutex) != 0) + return(0); + m->owner = tid; + } /* if */ + + m->count++; + return(1); } /* __PHYSFS_platformGrabMutex */ void __PHYSFS_platformReleaseMutex(void *mutex) { - pthread_mutex_unlock((pthread_mutex_t *) mutex); + PthreadMutex *m = (PthreadMutex *) mutex; + if (m->owner == pthread_self()) + { + if (--m->count == 0) + { + m->owner = (pthread_t) 0xDEADBEEF; + pthread_mutex_unlock(&m->mutex); + } /* if */ + } /* if */ } /* __PHYSFS_platformReleaseMutex */ #endif /* !PHYSFS_NO_PTHREADS_SUPPORT */