lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, 4 Jan 2005 14:36:18 -0700, Spencer Schumann
<gauchopuro@gmail.com> wrote:
> Perhaps the best way to fix
> it, without adding additional overhead, would be to maintain a
> separate GC list for thread objects, and sweep that list before
> sweeping the main GC list.

I've created a patch with the above change, and it seems to solve the
assertion problem.  I can now run my original code without crashes or
assertions.  The following patch contains both the new change and the
change I posted previously.

diff -u lua-5.0.2/src/lgc.c lua-5.0.2-bugfix/src/lgc.c
--- lua-5.0.2/src/lgc.c 2004-10-12 13:47:58.000000000 -0600
+++ lua-5.0.2-bugfix/src/lgc.c  2005-01-04 15:09:17.255477200 -0700
@@ -218,10 +218,8 @@
     markvalue(st, cl->l.p);
     for (i=0; i<cl->l.nupvalues; i++) {  /* mark its upvalues */
       UpVal *u = cl->l.upvals[i];
-      if (!u->marked) {
-        markobject(st, &u->value);
-        u->marked = 1;
-      }
+      markobject(st, u->v);
+      u->marked = 1;
     }
   }
 }
@@ -439,6 +437,7 @@
   if (all) all = 256;  /* larger than any mark */
   sweeplist(L, &G(L)->rootudata, all);
   sweepstrings(L, all);
+  sweeplist(L, &G(L)->threads, all);
   sweeplist(L, &G(L)->rootgc, all);
 }

@@ -496,3 +495,9 @@
   o->gch.tt = tt;
 }

+void luaC_linkthread (lua_State *L, GCObject *o) {
+  o->gch.next = G(L)->threads;
+  G(L)->threads = o;
+  o->gch.marked = 0;
+  o->gch.tt = LUA_TTHREAD;
+}
diff -u lua-5.0.2/src/lgc.h lua-5.0.2-bugfix/src/lgc.h
--- lua-5.0.2/src/lgc.h 2004-10-12 13:47:58.000000000 -0600
+++ lua-5.0.2-bugfix/src/lgc.h  2005-01-04 15:22:45.646308800 -0700
@@ -20,6 +20,7 @@
 void luaC_sweep (lua_State *L, int all);
 void luaC_collectgarbage (lua_State *L);
 void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
+void luaC_linkthread (lua_State *L, GCObject *o);


 #endif
diff -u lua-5.0.2/src/lstate.c lua-5.0.2-bugfix/src/lstate.c
--- lua-5.0.2/src/lstate.c      2004-10-12 13:47:58.000000000 -0600
+++ lua-5.0.2-bugfix/src/lstate.c       2005-01-04 15:10:03.472452400 -0700
@@ -102,6 +102,7 @@
   luaZ_initbuffer(L, &g->buff);
   g->panic = default_panic;
   g->rootgc = NULL;
+  g->threads = NULL;
   g->rootudata = NULL;
   g->tmudata = NULL;
   setnilvalue(gkey(g->dummynode));
@@ -161,7 +162,7 @@

 lua_State *luaE_newthread (lua_State *L) {
   lua_State *L1 = mallocstate(L);
-  luaC_link(L, valtogco(L1), LUA_TTHREAD);
+  luaC_linkthread(L, valtogco(L1));
   preinit_state(L1);
   L1->l_G = L->l_G;
   stack_init(L1, L);  /* init stack */
diff -u lua-5.0.2/src/lstate.h lua-5.0.2-bugfix/src/lstate.h
--- lua-5.0.2/src/lstate.h      2004-10-12 13:47:58.000000000 -0600
+++ lua-5.0.2-bugfix/src/lstate.h       2005-01-04 15:02:09.912512800 -0700
@@ -111,6 +111,7 @@
 typedef struct global_State {
   stringtable strt;  /* hash table for strings */
   GCObject *rootgc;  /* list of (almost) all collectable objects */
+  GCObject *threads; /* list of all thread objects */
   GCObject *rootudata;   /* (separated) list of all userdata */
   GCObject *tmudata;  /* list of userdata to be GC */
   Mbuffer buff;  /* temporary buffer for string concatentation */

Again, I have not tested these changes extensively.  My previous
comment about the need for further testing in this area still applies.

Any ideas about the timeline for an official patch for these bugs?