diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-30 15:29:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-30 15:29:08 -0300 |
| commit | 1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a (patch) | |
| tree | 699f68a1d92ac448779a3196f30bc8d491b7f379 | |
| parent | 72a1d81b510797759a8a5b9e701eb4b791aa8a84 (diff) | |
| download | lua-1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a.tar.gz lua-1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a.tar.bz2 lua-1d7857bc635c0bfe7c5b1f325d31feb7660e9a5a.zip | |
free(b) is equivalent to realloc(b, 0)
| -rw-r--r-- | luamem.c | 8 | ||||
| -rw-r--r-- | luamem.h | 4 |
2 files changed, 8 insertions, 4 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_luamem = "$Id: luamem.c,v 1.15 1997/03/31 14:17:09 roberto Exp roberto $"; | 6 | char *rcs_luamem = "$Id: luamem.c,v 1.16 1997/04/01 21:23:20 roberto Exp $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| @@ -15,7 +15,7 @@ char *rcs_luamem = "$Id: luamem.c,v 1.15 1997/03/31 14:17:09 roberto Exp roberto | |||
| 15 | 15 | ||
| 16 | #if !DEBUG | 16 | #if !DEBUG |
| 17 | 17 | ||
| 18 | void luaI_free (void *block) | 18 | static void lfree (void *block) |
| 19 | { | 19 | { |
| 20 | if (block) | 20 | if (block) |
| 21 | { | 21 | { |
| @@ -31,6 +31,10 @@ void *luaI_realloc (void *oldblock, unsigned long size) | |||
| 31 | size_t s = (size_t)size; | 31 | size_t s = (size_t)size; |
| 32 | if (s != size) | 32 | if (s != size) |
| 33 | lua_error("Allocation Error: Block too big"); | 33 | lua_error("Allocation Error: Block too big"); |
| 34 | if (size == 0) { /* ANSI doen't need this, but some machines... */ | ||
| 35 | lfree(oldblock); | ||
| 36 | return NULL; | ||
| 37 | } | ||
| 34 | block = oldblock ? realloc(oldblock, s) : malloc(s); | 38 | block = oldblock ? realloc(oldblock, s) : malloc(s); |
| 35 | if (block == NULL) | 39 | if (block == NULL) |
| 36 | lua_error(memEM); | 40 | lua_error(memEM); |
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** mem.c | 2 | ** mem.c |
| 3 | ** memory manager for lua | 3 | ** memory manager for lua |
| 4 | ** $Id: luamem.h,v 1.9 1997/03/31 14:10:11 roberto Exp roberto $ | 4 | ** $Id: luamem.h,v 1.10 1997/07/29 20:38:45 roberto Exp roberto $ |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #ifndef luamem_h | 7 | #ifndef luamem_h |
| @@ -23,12 +23,12 @@ | |||
| 23 | #define memEM "not enough memory" | 23 | #define memEM "not enough memory" |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | void luaI_free (void *block); | ||
| 27 | void *luaI_realloc (void *oldblock, unsigned long size); | 26 | void *luaI_realloc (void *oldblock, unsigned long size); |
| 28 | void *luaI_buffer (unsigned long size); | 27 | void *luaI_buffer (unsigned long size); |
| 29 | int luaI_growvector (void **block, unsigned long nelems, int size, | 28 | int luaI_growvector (void **block, unsigned long nelems, int size, |
| 30 | char *errormsg, unsigned long limit); | 29 | char *errormsg, unsigned long limit); |
| 31 | 30 | ||
| 31 | #define luaI_free(b) luaI_realloc((b), 0) | ||
| 32 | #define luaI_malloc(s) luaI_realloc(NULL, (s)) | 32 | #define luaI_malloc(s) luaI_realloc(NULL, (s)) |
| 33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) | 33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) |
| 34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) | 34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) |
