From 29ede6aa13144ff7b69c57a87be1ee93f57ae896 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 22 Nov 1999 11:12:07 -0200 Subject: first implementation of multiple states (reentrant code). --- lmem.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lmem.c') diff --git a/lmem.c b/lmem.c index 3f309ed4..cfdf7ac6 100644 --- a/lmem.c +++ b/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.18 1999/08/16 20:52:00 roberto Exp roberto $ +** $Id: lmem.c,v 1.19 1999/10/19 13:33:22 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -7,6 +7,8 @@ #include +#define LUA_REENTRANT + #include "lmem.h" #include "lstate.h" #include "lua.h" @@ -34,15 +36,15 @@ static unsigned long power2 (unsigned long n) { } -void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, +void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, int inc, int size, const char *errormsg, unsigned long limit) { unsigned long newn = nelems+inc; - if (newn >= limit) lua_error(errormsg); + if (newn >= limit) lua_error(L, errormsg); if ((newn ^ nelems) <= nelems || /* still the same power of 2 limit? */ (nelems > 0 && newn < MINSIZE)) /* or block already is MINSIZE? */ return block; /* do not need to reallocate */ else /* it crossed a power of 2 boundary; grow to next power */ - return luaM_realloc(block, power2(newn)*size); + return luaM_realloc(L, block, power2(newn)*size); } @@ -51,17 +53,17 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, /* ** generic allocation routine. */ -void *luaM_realloc (void *block, unsigned long size) { +void *luaM_realloc (lua_State *L, void *block, unsigned long size) { size_t s = (size_t)size; if (s != size) - lua_error("memory allocation error: block too big"); + lua_error(L, "memory allocation error: block too big"); if (size == 0) { free(block); /* block may be NULL, that is OK for free */ return NULL; } block = realloc(block, s); if (block == NULL) - lua_error(memEM); + lua_error(L, memEM); return block; } @@ -90,7 +92,7 @@ static void *checkblock (void *block) { unsigned long size = *b; int i; for (i=0;i