diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
| commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
| tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /lmem.c | |
| parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
| download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip | |
"const" !!!
Diffstat (limited to 'lmem.c')
| -rw-r--r-- | lmem.c | 30 |
1 files changed, 14 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.16 1999/05/20 20:43:06 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.17 1999/05/24 17:51:05 roberto Exp roberto $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,7 +35,7 @@ static unsigned long power2 (unsigned long n) { | |||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, | 37 | void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, |
| 38 | char *errormsg, unsigned long limit) { | 38 | const char *errormsg, unsigned long limit) { |
| 39 | unsigned long newn = nelems+inc; | 39 | unsigned long newn = nelems+inc; |
| 40 | if (newn >= limit) lua_error(errormsg); | 40 | if (newn >= limit) lua_error(errormsg); |
| 41 | if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ | 41 | if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ |
| @@ -86,25 +86,23 @@ unsigned long totalmem = 0; | |||
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | static void *checkblock (void *block) { | 88 | static void *checkblock (void *block) { |
| 89 | if (block == NULL) | 89 | unsigned long *b = blocksize(block); |
| 90 | return NULL; | 90 | unsigned long size = *b; |
| 91 | else { | 91 | int i; |
| 92 | unsigned long *b = blocksize(block); | 92 | for (i=0;i<MARKSIZE;i++) |
| 93 | unsigned long size = *b; | 93 | LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block"); |
| 94 | int i; | 94 | numblocks--; |
| 95 | for (i=0;i<MARKSIZE;i++) | 95 | totalmem -= size; |
| 96 | LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block"); | 96 | return b; |
| 97 | numblocks--; | ||
| 98 | totalmem -= size; | ||
| 99 | return b; | ||
| 100 | } | ||
| 101 | } | 97 | } |
| 102 | 98 | ||
| 103 | 99 | ||
| 104 | static void freeblock (void *block) { | 100 | static void freeblock (void *block) { |
| 105 | if (block) | 101 | if (block) { |
| 106 | memset(block, -1, *blocksize(block)); /* erase block */ | 102 | memset(block, -1, *blocksize(block)); /* erase block */ |
| 107 | free(checkblock(block)); | 103 | block = checkblock(block); |
| 104 | free(block); | ||
| 105 | } | ||
| 108 | } | 106 | } |
| 109 | 107 | ||
| 110 | 108 | ||
