diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:55:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:55:22 -0300 |
| commit | 29d883b9bd8f35bf65443517371326a6021e20c1 (patch) | |
| tree | 20467b048ed798d436141dc1c6152fd88a89ceca | |
| parent | b0d5bd8c70150e1887256683c3fd6312fc1775b6 (diff) | |
| download | lua-29d883b9bd8f35bf65443517371326a6021e20c1.tar.gz lua-29d883b9bd8f35bf65443517371326a6021e20c1.tar.bz2 lua-29d883b9bd8f35bf65443517371326a6021e20c1.zip | |
avoid augmenting alignment of pointers
| -rw-r--r-- | ltests.c | 20 |
1 files changed, 10 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.87 2001/07/05 20:31:14 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.88 2001/07/12 18:11:58 roberto Exp $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -64,7 +64,7 @@ static void setnameval (lua_State *L, const l_char *name, int val) { | |||
| 64 | #define MARK 0x55 /* 01010101 (a nice pattern) */ | 64 | #define MARK 0x55 /* 01010101 (a nice pattern) */ |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | #define blocksize(b) ((size_t *)((l_char *)(b) - HEADER)) | 67 | #define blocksize(b) ((size_t *)(b) - HEADER/sizeof(size_t)) |
| 68 | 68 | ||
| 69 | unsigned long memdebug_numblocks = 0; | 69 | unsigned long memdebug_numblocks = 0; |
| 70 | unsigned long memdebug_total = 0; | 70 | unsigned long memdebug_total = 0; |
| @@ -77,7 +77,7 @@ static void *checkblock (void *block) { | |||
| 77 | size_t size = *b; | 77 | size_t size = *b; |
| 78 | int i; | 78 | int i; |
| 79 | for (i=0;i<MARKSIZE;i++) | 79 | for (i=0;i<MARKSIZE;i++) |
| 80 | lua_assert(*(((l_char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ | 80 | lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ |
| 81 | return b; | 81 | return b; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| @@ -103,27 +103,27 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) { | |||
| 103 | else if (memdebug_total+size-oldsize > memdebug_memlimit) | 103 | else if (memdebug_total+size-oldsize > memdebug_memlimit) |
| 104 | return NULL; /* to test memory allocation errors */ | 104 | return NULL; /* to test memory allocation errors */ |
| 105 | else { | 105 | else { |
| 106 | l_char *newblock; | 106 | void *newblock; |
| 107 | int i; | 107 | int i; |
| 108 | size_t realsize = HEADER+size+MARKSIZE; | 108 | size_t realsize = HEADER+size+MARKSIZE; |
| 109 | if (realsize < size) return NULL; /* overflow! */ | 109 | if (realsize < size) return NULL; /* overflow! */ |
| 110 | newblock = (l_char *)malloc(realsize); /* alloc a new block */ | 110 | newblock = malloc(realsize); /* alloc a new block */ |
| 111 | if (newblock == NULL) return NULL; | 111 | if (newblock == NULL) return NULL; |
| 112 | if (oldsize > size) oldsize = size; | 112 | if (oldsize > size) oldsize = size; |
| 113 | if (block) { | 113 | if (block) { |
| 114 | memcpy(newblock+HEADER, block, oldsize); | 114 | memcpy((char *)newblock+HEADER, block, oldsize); |
| 115 | freeblock(block); /* erase (and check) old copy */ | 115 | freeblock(block); /* erase (and check) old copy */ |
| 116 | } | 116 | } |
| 117 | /* initialize new part of the block with something `weird' */ | 117 | /* initialize new part of the block with something `weird' */ |
| 118 | memset(newblock+HEADER+oldsize, -MARK, size-oldsize); | 118 | memset((char *)newblock+HEADER+oldsize, -MARK, size-oldsize); |
| 119 | memdebug_total += size; | 119 | memdebug_total += size; |
| 120 | if (memdebug_total > memdebug_maxmem) | 120 | if (memdebug_total > memdebug_maxmem) |
| 121 | memdebug_maxmem = memdebug_total; | 121 | memdebug_maxmem = memdebug_total; |
| 122 | memdebug_numblocks++; | 122 | memdebug_numblocks++; |
| 123 | *(size_t *)newblock = size; | 123 | *(size_t *)newblock = size; |
| 124 | for (i=0;i<MARKSIZE;i++) | 124 | for (i=0;i<MARKSIZE;i++) |
| 125 | *(newblock+HEADER+size+i) = (l_char)(MARK+i); | 125 | *((char *)newblock+HEADER+size+i) = (char)(MARK+i); |
| 126 | return newblock+HEADER; | 126 | return (char *)newblock+HEADER; |
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | 129 | ||
| @@ -486,7 +486,7 @@ static int getnum (lua_State *L, const l_char **pc) { | |||
| 486 | sig = -1; | 486 | sig = -1; |
| 487 | (*pc)++; | 487 | (*pc)++; |
| 488 | } | 488 | } |
| 489 | while (isdigit(**pc)) res = res*10 + (*(*pc)++) - l_c('0'); | 489 | while (isdigit((int)**pc)) res = res*10 + (*(*pc)++) - l_c('0'); |
| 490 | return sig*res; | 490 | return sig*res; |
| 491 | } | 491 | } |
| 492 | 492 | ||
