array Cblocks should grow dynamically

This commit is contained in:
Roberto Ierusalimschy 1999-05-11 11:19:32 -03:00
parent c390f73e3b
commit 6eb1399a1c
3 changed files with 22 additions and 16 deletions

26
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 1.41 1999/03/04 21:17:26 roberto Exp roberto $ ** $Id: lapi.c,v 1.42 1999/03/26 13:14:00 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -637,16 +637,22 @@ char *lua_getobjname (lua_Object o, char **name)
*/ */
void lua_beginblock (void) #ifndef MAX_C_BLOCKS
{ #define MAX_C_BLOCKS 500
if (L->numCblocks >= MAX_C_BLOCKS) #endif
lua_error("too many nested blocks");
void lua_beginblock (void) {
if (L->numCblocks >= L->sizeCblocks) {
luaM_growvector(L->Cblocks, L->numCblocks, 1, struct C_Lua_Stack,
"too many nested blocks", MAX_C_BLOCKS);
L->sizeCblocks++;
}
L->Cblocks[L->numCblocks] = L->Cstack; L->Cblocks[L->numCblocks] = L->Cstack;
L->numCblocks++; L->numCblocks++;
} }
void lua_endblock (void) void lua_endblock (void) {
{
--L->numCblocks; --L->numCblocks;
L->Cstack = L->Cblocks[L->numCblocks]; L->Cstack = L->Cblocks[L->numCblocks];
luaD_adjusttop(L->Cstack.base); luaD_adjusttop(L->Cstack.base);
@ -654,8 +660,7 @@ void lua_endblock (void)
int lua_ref (int lock) int lua_ref (int lock) {
{
int ref; int ref;
checkCparams(1); checkCparams(1);
ref = luaC_ref(L->stack.top-1, lock); ref = luaC_ref(L->stack.top-1, lock);
@ -665,8 +670,7 @@ int lua_ref (int lock)
lua_Object lua_getref (int ref) lua_Object lua_getref (int ref) {
{
TObject *o = luaC_getref(ref); TObject *o = luaC_getref(ref);
return (o ? put_luaObject(o) : LUA_NOOBJECT); return (o ? put_luaObject(o) : LUA_NOOBJECT);
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 1.9 1999/02/25 15:17:01 roberto Exp roberto $ ** $Id: lstate.c,v 1.10 1999/04/13 19:30:51 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -32,6 +32,8 @@ void lua_open (void)
L->Mbuffbase = 0; L->Mbuffbase = 0;
L->Mbuffsize = 0; L->Mbuffsize = 0;
L->Mbuffnext = 0; L->Mbuffnext = 0;
L->Cblocks = NULL;
L->sizeCblocks = 0;
L->numCblocks = 0; L->numCblocks = 0;
L->debug = 0; L->debug = 0;
L->callhook = NULL; L->callhook = NULL;
@ -73,6 +75,7 @@ void lua_close (void)
luaM_free(L->IMtable); luaM_free(L->IMtable);
luaM_free(L->refArray); luaM_free(L->refArray);
luaM_free(L->Mbuffer); luaM_free(L->Mbuffer);
luaM_free(L->Cblocks);
luaM_free(L); luaM_free(L);
L = NULL; L = NULL;
#ifdef DEBUG #ifdef DEBUG

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 1.16 1999/04/13 19:30:51 roberto Exp roberto $ ** $Id: lstate.h,v 1.17 1999/05/10 13:54:01 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -14,8 +14,6 @@
#include "luadebug.h" #include "luadebug.h"
#define MAX_C_BLOCKS 10
#define GARBAGE_BLOCK 150 #define GARBAGE_BLOCK 150
@ -69,7 +67,8 @@ struct lua_State {
int Mbuffbase; /* current first position of Mbuffer */ int Mbuffbase; /* current first position of Mbuffer */
int Mbuffsize; /* size of Mbuffer */ int Mbuffsize; /* size of Mbuffer */
int Mbuffnext; /* next position to fill in Mbuffer */ int Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; struct C_Lua_Stack *Cblocks;
int sizeCblocks; /* size of Cblocks */
int numCblocks; /* number of nested Cblocks */ int numCblocks; /* number of nested Cblocks */
int debug; int debug;
lua_CHFunction callhook; lua_CHFunction callhook;