diff --git a/include/mem.h b/include/mem.h index 4bafece..2979f15 100644 --- a/include/mem.h +++ b/include/mem.h @@ -13,15 +13,15 @@ extern const Exception out_of_memory; // OOM Exception -extern void *mem_alloc (size_t nbytes,const char *file, int line); -extern void *mem_calloc(size_t count, size_t nbytes,const char *file, int line); +extern void *mem_alloc (ptrdiff_t nbytes,const char *file, int line); +extern void *mem_calloc(ptrdiff_t count, ptrdiff_t nbytes,const char *file, int line); extern void mem_free(void *ptr, const char *file, int line); -extern void *mem_realloc(void *ptr, size_t nbytes, const char *file, int line); +extern void *mem_realloc(void *ptr, ptrdiff_t nbytes, const char *file, int line); #define ALLOC(nbytes) mem_alloc((nbytes), __FILE__, __LINE__) #define CALLOC(count, nbytes) mem_calloc((count), (nbytes), __FILE__, __LINE__) -#define NEW(p) ((p) = ALLOC((size_t)sizeof *(p))) -#define NEW0(p) ((p) = CALLOC(1, (size_t)sizeof *(p))) +#define NEW(p) ((p) = ALLOC((ptrdiff_t)sizeof *(p))) +#define NEW0(p) ((p) = CALLOC(1, (ptrdiff_t)sizeof *(p))) #define FREE(ptr) ((void)(mem_free((ptr), __FILE__, __LINE__), (ptr) = 0)) #define REALLOC(ptr, nbytes) ((ptr) = mem_realloc((ptr), (nbytes), __FILE__, __LINE__)) diff --git a/src/mem.c b/src/mem.c index 270587e..eadafeb 100644 --- a/src/mem.c +++ b/src/mem.c @@ -4,7 +4,7 @@ const Exception out_of_memory = { "Out Of Memory" }; // OOM Exception. -void *mem_alloc(size_t nbytes, const char *file, int line){ +void *mem_alloc(ptrdiff_t nbytes, const char *file, int line){ void *ptr; // Memory to allocate. ASSERTED(nbytes > 0); ptr = malloc(nbytes); // Attempt allocation. @@ -17,7 +17,7 @@ void *mem_alloc(size_t nbytes, const char *file, int line){ // Success, return allocated memory. return ptr; } -void *mem_calloc(size_t count, size_t nbytes,const char *file, int line) { +void *mem_calloc(ptrdiff_t count, ptrdiff_t nbytes,const char *file, int line) { void *ptr; // Memory to allocate. ASSERTED(count > 0); ASSERTED(nbytes > 0); @@ -39,7 +39,7 @@ void mem_free(void *ptr, const char *file, int line) { ptr = NULL; } } -void *mem_realloc(void *ptr, size_t nbytes, const char *file, int line) { +void *mem_realloc(void *ptr, ptrdiff_t nbytes, const char *file, int line) { ASSERTED(ptr); ASSERTED(nbytes > 0); ptr = realloc(ptr, nbytes); // Attempt reallocation.