commit 617be660158490c7f6558e82d9be2c667c48d9a4
parent f356eb010b6785cf22e8d5f1d4f7761e0789ae51
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 6 Dec 1999 10:03:23 -0200
better control (and error recovery) for begin/end blocks
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.61 1999/12/01 19:50:08 roberto Exp roberto $
+** $Id: lapi.c,v 1.62 1999/12/02 16:24:45 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -592,19 +592,16 @@ const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) {
*/
-#ifndef MAX_C_BLOCKS
-#define MAX_C_BLOCKS 1000 /* arbitrary limit */
-#endif
-
-
void lua_beginblock (lua_State *L) {
luaM_growvector(L, L->Cblocks, L->numCblocks, 1, struct C_Lua_Stack,
- "too many nested blocks", MAX_C_BLOCKS);
+ "too many nested blocks", L->stacksize);
L->Cblocks[L->numCblocks] = L->Cstack;
L->numCblocks++;
}
void lua_endblock (lua_State *L) {
+ if (L->numCblocks <= 0)
+ lua_error(L, "API error - no block to end");
--L->numCblocks;
L->Cstack = L->Cblocks[L->numCblocks];
L->top = L->Cstack.base;
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.56 1999/12/02 16:41:29 roberto Exp roberto $
+** $Id: ldo.c,v 1.57 1999/12/06 11:43:58 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -243,12 +243,13 @@ void lua_error (lua_State *L, const char *s) {
/*
-** Execute a protected call. Assumes that function is at L->Cstack.base and
-** parameters are on top of it. Leave nResults on the stack.
+** Execute a protected call. Assumes that function is at Cstack.base and
+** parameters are on top of it.
*/
int luaD_protectedrun (lua_State *L) {
struct lua_longjmp myErrorJmp;
volatile StkId base = L->Cstack.base;
+ volatile int numCblocks = L->numCblocks;
volatile int status;
struct lua_longjmp *volatile oldErr = L->errorJmp;
L->errorJmp = &myErrorJmp;
@@ -262,6 +263,7 @@ int luaD_protectedrun (lua_State *L) {
else { /* an error occurred: restore the stack */
L->Cstack.num = 0; /* no results */
L->top = L->Cstack.base = L->Cstack.lua2C = base;
+ L->numCblocks = numCblocks;
restore_stack_limit(L);
status = 1;
}
@@ -276,6 +278,7 @@ int luaD_protectedrun (lua_State *L) {
static int protectedparser (lua_State *L, ZIO *z, int bin) {
struct lua_longjmp myErrorJmp;
volatile StkId base = L->Cstack.base;
+ volatile int numCblocks = L->numCblocks;
volatile int status;
TProtoFunc *volatile tf;
struct lua_longjmp *volatile oldErr = L->errorJmp;
@@ -288,6 +291,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
else { /* an error occurred: restore Cstack and top */
L->Cstack.num = 0; /* no results */
L->top = L->Cstack.base = L->Cstack.lua2C = base;
+ L->numCblocks = numCblocks;
tf = NULL;
status = 1;
}
diff --git a/lstate.c b/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.19 1999/12/01 19:50:08 roberto Exp roberto $
+** $Id: lstate.c,v 1.20 1999/12/06 11:41:28 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -99,6 +99,7 @@ void lua_close (lua_State *L) {
luaM_free(L, L->refArray);
luaM_free(L, L->Mbuffer);
luaM_free(L, L->Cblocks);
+ LUA_ASSERT(L, L->numCblocks == 0, "Cblocks still open");
LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks");
LUA_ASSERT(L, L != lua_state || L->Cstack.lua2C == L->stack, "bad stack");
LUA_ASSERT(L, L != lua_state || L->Cstack.base == L->stack, "bad stack");