Little tweaks to __PHYSFS_initSmallAlloc().

This commit is contained in:
Ryan C. Gordon 2017-08-14 13:57:57 -04:00
parent 8db27a1236
commit f425f051db
2 changed files with 5 additions and 5 deletions

View File

@ -3040,7 +3040,7 @@ int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
} /* __PHYSFS_readAll */ } /* __PHYSFS_readAll */
void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len) void *__PHYSFS_initSmallAlloc(void *ptr, const size_t len)
{ {
void *useHeap = ((ptr == NULL) ? ((void *) 1) : ((void *) 0)); void *useHeap = ((ptr == NULL) ? ((void *) 1) : ((void *) 0));
if (useHeap) /* too large for stack allocation or alloca() failed. */ if (useHeap) /* too large for stack allocation or alloca() failed. */
@ -3049,8 +3049,8 @@ void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len)
if (ptr != NULL) if (ptr != NULL)
{ {
void **retval = (void **) ptr; void **retval = (void **) ptr;
/*printf("%s alloc'd (%d) bytes at (%p).\n", /*printf("%s alloc'd (%lld) bytes at (%p).\n",
useHeap ? "heap" : "stack", (int) len, ptr);*/ useHeap ? "heap" : "stack", (long long) len, ptr);*/
*retval = useHeap; *retval = useHeap;
return retval + 1; return retval + 1;
} /* if */ } /* if */
@ -3064,7 +3064,7 @@ void __PHYSFS_smallFree(void *ptr)
if (ptr != NULL) if (ptr != NULL)
{ {
void **block = ((void **) ptr) - 1; void **block = ((void **) ptr) - 1;
const int useHeap = (*block != 0); const int useHeap = (*block != NULL);
if (useHeap) if (useHeap)
allocator.Free(block); allocator.Free(block);
/*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/ /*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/

View File

@ -145,7 +145,7 @@ int __PHYSFS_ATOMIC_DECR(int *ptrval);
* NEVER forget to check for NULL...allocation can fail here, of course! * NEVER forget to check for NULL...allocation can fail here, of course!
*/ */
#define __PHYSFS_SMALLALLOCTHRESHOLD 256 #define __PHYSFS_SMALLALLOCTHRESHOLD 256
void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len); void *__PHYSFS_initSmallAlloc(void *ptr, const size_t len);
#define __PHYSFS_smallAlloc(bytes) ( \ #define __PHYSFS_smallAlloc(bytes) ( \
__PHYSFS_initSmallAlloc( \ __PHYSFS_initSmallAlloc( \