aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-29 19:03:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-29 19:03:06 -0300
commit994aba062b5cae032c751afc7cc35053ec4e2b94 (patch)
tree6a0fa353949a7417655e9034aa50603dc2375da5
parente869d17eb1309bfd81802a21b546a76e7ed6c38a (diff)
downloadlua-994aba062b5cae032c751afc7cc35053ec4e2b94.tar.gz
lua-994aba062b5cae032c751afc7cc35053ec4e2b94.tar.bz2
lua-994aba062b5cae032c751afc7cc35053ec4e2b94.zip
when debuging, blocks must be kept in double allignment.
-rw-r--r--lmem.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/lmem.c b/lmem.c
index 40a86309..854ad7d2 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.5 1998/03/09 21:49:52 roberto Exp roberto $ 2** $Id: lmem.c,v 1.6 1998/06/19 16:14:09 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*/
@@ -60,6 +60,8 @@ void *luaM_realloc (void *block, unsigned long size)
60#include <string.h> 60#include <string.h>
61 61
62 62
63#define HEADER (sizeof(double))
64
63#define MARK 55 65#define MARK 55
64 66
65unsigned long numblocks = 0; 67unsigned long numblocks = 0;
@@ -68,9 +70,9 @@ unsigned long totalmem = 0;
68 70
69static void *checkblock (void *block) 71static void *checkblock (void *block)
70{ 72{
71 unsigned long *b = (unsigned long *)block - 1; 73 unsigned long *b = (unsigned long *)((char *)block - HEADER);
72 unsigned long size = *b; 74 unsigned long size = *b;
73 LUA_ASSERT(*(((char *)b)+size+sizeof(unsigned long)) == MARK, 75 LUA_ASSERT(*(((char *)b)+size+HEADER) == MARK,
74 "corrupted block"); 76 "corrupted block");
75 numblocks--; 77 numblocks--;
76 totalmem -= size; 78 totalmem -= size;
@@ -80,12 +82,13 @@ static void *checkblock (void *block)
80 82
81void *luaM_realloc (void *block, unsigned long size) 83void *luaM_realloc (void *block, unsigned long size)
82{ 84{
83 unsigned long realsize = sizeof(unsigned long)+size+sizeof(char); 85 unsigned long realsize = HEADER+size+1;
84 if (realsize != (size_t)realsize) 86 if (realsize != (size_t)realsize)
85 lua_error("Allocation Error: Block too big"); 87 lua_error("Allocation Error: Block too big");
86 if (size == 0) { /* ANSI dosen't need this, but some machines... */ 88 if (size == 0) { /* ANSI dosen't need this, but some machines... */
87 if (block) { 89 if (block) {
88 memset(block, -1, *((unsigned long *)block-1)); /* erase block */ 90 unsigned long *b = (unsigned long *)((char *)block - HEADER);
91 memset(block, -1, *b); /* erase block */
89 block = checkblock(block); 92 block = checkblock(block);
90 free(block); 93 free(block);
91 } 94 }
@@ -102,8 +105,8 @@ void *luaM_realloc (void *block, unsigned long size)
102 totalmem += size; 105 totalmem += size;
103 numblocks++; 106 numblocks++;
104 *(unsigned long *)block = size; 107 *(unsigned long *)block = size;
105 *(((char *)block)+size+sizeof(unsigned long)) = MARK; 108 *(((char *)block)+size+HEADER) = MARK;
106 return (unsigned long *)block+1; 109 return (unsigned long *)((char *)block+HEADER);
107} 110}
108 111
109 112