소스 검색

array Cblocks should grow dynamically

Roberto Ierusalimschy 26 년 전
부모
커밋
6eb1399a1c
3개의 변경된 파일22개의 추가작업 그리고 16개의 파일을 삭제
  1. 15 11
      lapi.c
  2. 4 1
      lstate.c
  3. 3 4
      lstate.h

+ 15 - 11
lapi.c

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -637,16 +637,22 @@ char *lua_getobjname (lua_Object o, char **name)
 */
 
 
-void lua_beginblock (void)
-{
-  if (L->numCblocks >= MAX_C_BLOCKS)
-    lua_error("too many nested blocks");
+#ifndef	MAX_C_BLOCKS
+#define MAX_C_BLOCKS	500
+#endif
+
+
+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->numCblocks++;
 }
 
-void lua_endblock (void)
-{
+void lua_endblock (void) {
   --L->numCblocks;
   L->Cstack = L->Cblocks[L->numCblocks];
   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;
   checkCparams(1);
   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);
   return (o ? put_luaObject(o) : LUA_NOOBJECT);
 }

+ 4 - 1
lstate.c

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -32,6 +32,8 @@ void lua_open (void)
   L->Mbuffbase = 0;
   L->Mbuffsize = 0;
   L->Mbuffnext = 0;
+  L->Cblocks = NULL;
+  L->sizeCblocks = 0;
   L->numCblocks = 0;
   L->debug = 0;
   L->callhook = NULL;
@@ -73,6 +75,7 @@ void lua_close (void)
   luaM_free(L->IMtable);
   luaM_free(L->refArray);
   luaM_free(L->Mbuffer);
+  luaM_free(L->Cblocks);
   luaM_free(L);
   L = NULL;
 #ifdef DEBUG

+ 3 - 4
lstate.h

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -14,8 +14,6 @@
 #include "luadebug.h"
 
 
-#define MAX_C_BLOCKS 10
-
 #define GARBAGE_BLOCK 150
 
 
@@ -69,7 +67,8 @@ struct lua_State {
   int Mbuffbase;  /* current first position of Mbuffer */
   int Mbuffsize;  /* size of 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 debug;
   lua_CHFunction callhook;