aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-06 10:03:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-06 10:03:45 -0200
commit617be660158490c7f6558e82d9be2c667c48d9a4 (patch)
tree27c0c29cb550d576cef2b4953ff4c4622f852503
parentf356eb010b6785cf22e8d5f1d4f7761e0789ae51 (diff)
downloadlua-617be660158490c7f6558e82d9be2c667c48d9a4.tar.gz
lua-617be660158490c7f6558e82d9be2c667c48d9a4.tar.bz2
lua-617be660158490c7f6558e82d9be2c667c48d9a4.zip
better control (and error recovery) for begin/end blocks
-rw-r--r--lapi.c11
-rw-r--r--ldo.c10
-rw-r--r--lstate.c3
3 files changed, 13 insertions, 11 deletions
diff --git a/lapi.c b/lapi.c
index b4f17b37..953c066e 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.61 1999/12/01 19:50:08 roberto Exp roberto $ 2** $Id: lapi.c,v 1.62 1999/12/02 16:24:45 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -592,19 +592,16 @@ const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) {
592*/ 592*/
593 593
594 594
595#ifndef MAX_C_BLOCKS
596#define MAX_C_BLOCKS 1000 /* arbitrary limit */
597#endif
598
599
600void lua_beginblock (lua_State *L) { 595void lua_beginblock (lua_State *L) {
601 luaM_growvector(L, L->Cblocks, L->numCblocks, 1, struct C_Lua_Stack, 596 luaM_growvector(L, L->Cblocks, L->numCblocks, 1, struct C_Lua_Stack,
602 "too many nested blocks", MAX_C_BLOCKS); 597 "too many nested blocks", L->stacksize);
603 L->Cblocks[L->numCblocks] = L->Cstack; 598 L->Cblocks[L->numCblocks] = L->Cstack;
604 L->numCblocks++; 599 L->numCblocks++;
605} 600}
606 601
607void lua_endblock (lua_State *L) { 602void lua_endblock (lua_State *L) {
603 if (L->numCblocks <= 0)
604 lua_error(L, "API error - no block to end");
608 --L->numCblocks; 605 --L->numCblocks;
609 L->Cstack = L->Cblocks[L->numCblocks]; 606 L->Cstack = L->Cblocks[L->numCblocks];
610 L->top = L->Cstack.base; 607 L->top = L->Cstack.base;
diff --git a/ldo.c b/ldo.c
index 71e19e0f..384bd244 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.56 1999/12/02 16:41:29 roberto Exp roberto $ 2** $Id: ldo.c,v 1.57 1999/12/06 11:43:58 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -243,12 +243,13 @@ void lua_error (lua_State *L, const char *s) {
243 243
244 244
245/* 245/*
246** Execute a protected call. Assumes that function is at L->Cstack.base and 246** Execute a protected call. Assumes that function is at Cstack.base and
247** parameters are on top of it. Leave nResults on the stack. 247** parameters are on top of it.
248*/ 248*/
249int luaD_protectedrun (lua_State *L) { 249int luaD_protectedrun (lua_State *L) {
250 struct lua_longjmp myErrorJmp; 250 struct lua_longjmp myErrorJmp;
251 volatile StkId base = L->Cstack.base; 251 volatile StkId base = L->Cstack.base;
252 volatile int numCblocks = L->numCblocks;
252 volatile int status; 253 volatile int status;
253 struct lua_longjmp *volatile oldErr = L->errorJmp; 254 struct lua_longjmp *volatile oldErr = L->errorJmp;
254 L->errorJmp = &myErrorJmp; 255 L->errorJmp = &myErrorJmp;
@@ -262,6 +263,7 @@ int luaD_protectedrun (lua_State *L) {
262 else { /* an error occurred: restore the stack */ 263 else { /* an error occurred: restore the stack */
263 L->Cstack.num = 0; /* no results */ 264 L->Cstack.num = 0; /* no results */
264 L->top = L->Cstack.base = L->Cstack.lua2C = base; 265 L->top = L->Cstack.base = L->Cstack.lua2C = base;
266 L->numCblocks = numCblocks;
265 restore_stack_limit(L); 267 restore_stack_limit(L);
266 status = 1; 268 status = 1;
267 } 269 }
@@ -276,6 +278,7 @@ int luaD_protectedrun (lua_State *L) {
276static int protectedparser (lua_State *L, ZIO *z, int bin) { 278static int protectedparser (lua_State *L, ZIO *z, int bin) {
277 struct lua_longjmp myErrorJmp; 279 struct lua_longjmp myErrorJmp;
278 volatile StkId base = L->Cstack.base; 280 volatile StkId base = L->Cstack.base;
281 volatile int numCblocks = L->numCblocks;
279 volatile int status; 282 volatile int status;
280 TProtoFunc *volatile tf; 283 TProtoFunc *volatile tf;
281 struct lua_longjmp *volatile oldErr = L->errorJmp; 284 struct lua_longjmp *volatile oldErr = L->errorJmp;
@@ -288,6 +291,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
288 else { /* an error occurred: restore Cstack and top */ 291 else { /* an error occurred: restore Cstack and top */
289 L->Cstack.num = 0; /* no results */ 292 L->Cstack.num = 0; /* no results */
290 L->top = L->Cstack.base = L->Cstack.lua2C = base; 293 L->top = L->Cstack.base = L->Cstack.lua2C = base;
294 L->numCblocks = numCblocks;
291 tf = NULL; 295 tf = NULL;
292 status = 1; 296 status = 1;
293 } 297 }
diff --git a/lstate.c b/lstate.c
index 3306c780..04e7d419 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.19 1999/12/01 19:50:08 roberto Exp roberto $ 2** $Id: lstate.c,v 1.20 1999/12/06 11:41:28 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -99,6 +99,7 @@ void lua_close (lua_State *L) {
99 luaM_free(L, L->refArray); 99 luaM_free(L, L->refArray);
100 luaM_free(L, L->Mbuffer); 100 luaM_free(L, L->Mbuffer);
101 luaM_free(L, L->Cblocks); 101 luaM_free(L, L->Cblocks);
102 LUA_ASSERT(L, L->numCblocks == 0, "Cblocks still open");
102 LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks"); 103 LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks");
103 LUA_ASSERT(L, L != lua_state || L->Cstack.lua2C == L->stack, "bad stack"); 104 LUA_ASSERT(L, L != lua_state || L->Cstack.lua2C == L->stack, "bad stack");
104 LUA_ASSERT(L, L != lua_state || L->Cstack.base == L->stack, "bad stack"); 105 LUA_ASSERT(L, L != lua_state || L->Cstack.base == L->stack, "bad stack");