Selaa lähdekoodia

`global' tables (registry, etc.) stored in proper place, not in the stack

Roberto Ierusalimschy 23 vuotta sitten
vanhempi
commit
01f1ac36b1
3 muutettua tiedostoa jossa 16 lisäystä ja 13 poistoa
  1. 4 2
      lgc.c
  2. 2 2
      lstate.c
  3. 10 9
      lstate.h

+ 4 - 2
lgc.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lgc.c,v 1.134 2002/04/05 18:54:31 roberto Exp roberto $
+** $Id: lgc.c,v 1.135 2002/04/23 15:04:39 roberto Exp roberto $
 ** Garbage Collector
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -100,7 +100,6 @@ static void marktable (GCState *st, Table *h) {
   if (!ismarked(h)) {
   if (!ismarked(h)) {
     h->mark = st->tmark;  /* chain it for later traversal */
     h->mark = st->tmark;  /* chain it for later traversal */
     st->tmark = h;
     st->tmark = h;
-    marktable(st, h->metatable);
   }
   }
 }
 }
 
 
@@ -153,6 +152,9 @@ static void markstacks (GCState *st) {
       luaE_closethread(st->L, L1->previous);  /* collect it */
       luaE_closethread(st->L, L1->previous);  /* collect it */
       continue;
       continue;
     }
     }
+    markobject(st, defaultmeta(L1));
+    markobject(st, gt(L1));
+    markobject(st, registry(L1));
     for (o=L1->stack; o<L1->top; o++)
     for (o=L1->stack; o<L1->top; o++)
       markobject(st, o);
       markobject(st, o);
     lim = o;
     lim = o;

+ 2 - 2
lstate.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstate.c,v 1.92 2002/05/01 20:40:42 roberto Exp roberto $
+** $Id: lstate.c,v 1.93 2002/05/07 17:36:56 roberto Exp roberto $
 ** Global State
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -38,7 +38,7 @@ static int default_panic (lua_State *L) {
 static void stack_init (lua_State *L, lua_State *OL) {
 static void stack_init (lua_State *L, lua_State *OL) {
   L->stack = luaM_newvector(OL, BASIC_STACK_SIZE, TObject);
   L->stack = luaM_newvector(OL, BASIC_STACK_SIZE, TObject);
   L->stacksize = BASIC_STACK_SIZE;
   L->stacksize = BASIC_STACK_SIZE;
-  L->top = L->stack + RESERVED_STACK_PREFIX;
+  L->top = L->stack;
   L->stack_last = L->stack+(BASIC_STACK_SIZE-EXTRA_STACK)-1;
   L->stack_last = L->stack+(BASIC_STACK_SIZE-EXTRA_STACK)-1;
   L->base_ci = luaM_newvector(OL, BASIC_CI_SIZE, CallInfo);
   L->base_ci = luaM_newvector(OL, BASIC_CI_SIZE, CallInfo);
   L->ci = L->base_ci;
   L->ci = L->base_ci;

+ 10 - 9
lstate.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstate.h,v 1.83 2002/04/16 17:08:28 roberto Exp roberto $
+** $Id: lstate.h,v 1.84 2002/04/23 15:04:39 roberto Exp roberto $
 ** Global State
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -50,23 +50,23 @@ struct lua_longjmp;  /* defined in ldo.c */
 
 
 
 
 /*
 /*
-** reserve init of stack to store some global values
+** array of `global' objects
 */
 */
 
 
+#define NUMGLOBS	3
+
 /* default meta table (both for tables and udata) */
 /* default meta table (both for tables and udata) */
-#define defaultmeta(L)	(L->stack)
+#define defaultmeta(L)	(L->globs)
 
 
 /* table of globals */
 /* table of globals */
-#define gt(L)	(L->stack + 1)
+#define gt(L)	(L->globs + 1)
 
 
 /* registry */
 /* registry */
-#define registry(L)	(L->stack + 2)
-
-#define RESERVED_STACK_PREFIX	3
+#define registry(L)	(L->globs + 2)
 
 
 
 
-/* space to handle TM calls */
-#define EXTRA_STACK   4
+/* space to handle TM calls and other temporary overflows */
+#define EXTRA_STACK   5
 
 
 
 
 #define BASIC_CI_SIZE           8
 #define BASIC_CI_SIZE           8
@@ -130,6 +130,7 @@ struct lua_State {
   CallInfo *end_ci;  /* points after end of ci array*/
   CallInfo *end_ci;  /* points after end of ci array*/
   CallInfo *base_ci;  /* array of CallInfo's */
   CallInfo *base_ci;  /* array of CallInfo's */
   global_State *l_G;
   global_State *l_G;
+  TObject globs[NUMGLOBS];  /* registry, table of globals, etc. */
   struct lua_longjmp *errorJmp;  /* current error recover point */
   struct lua_longjmp *errorJmp;  /* current error recover point */
   UpVal *openupval;  /* list of open upvalues in this stack */
   UpVal *openupval;  /* list of open upvalues in this stack */
   lua_State *next;  /* circular double linked list of states */
   lua_State *next;  /* circular double linked list of states */