lua-users home
lua-l archive

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


Hi, I have a problem with Lua cleaning up on a lua_close(). I get p == -1
and a memory exception in collectstrings(). ie. the line "while ((next = *p)
!= NULL) {" in collectstrings. When I turn LUA_DEBUG on
"LUA_ASSERT(L->udt.nuse==0, "non-empty udata table");" fails in
luaS_freeall. I have no idea what this means :-). Please help! Both fns
enclosed.

Thanks, Nick



static void collectstrings (lua_State *L, int all) {            /* lstring.c
*/
  int i;
  for (i=0; i<L->strt.size; i++) {  /* for each list */
    TString **p = &L->strt.hash[i];
    TString *next;
    while ((next = *p) != NULL) {
      if (next->marked && !all) {  /* preserve? */
        if (next->marked < FIXMARK)  /* does not change FIXMARKs */
          next->marked = 0;
        p = &next->nexthash;
      }
      else {  /* collect */
        *p = next->nexthash;
        L->strt.nuse--;
        L->nblocks -= sizestring(next->len);
        luaM_free(L, next);
      }
    }
  }
  checktab(L, &L->strt);
}


void luaS_freeall (lua_State *L) {   /* lgc.c */
  LUA_ASSERT(L->strt.nuse==0, "non-empty string table");
  L->nblocks -= (L->strt.size + L->udt.size)*sizeof(TString *);
  luaM_free(L, L->strt.hash);
  LUA_ASSERT(L->udt.nuse==0, "non-empty udata table");
  luaM_free(L, L->udt.hash);
}



---
Analyzing humor is like dissecting a frog. Few people are interested and the
frog dies of it.
 - E. B. White