예제 #1
0
파일: lstate.c 프로젝트: dodong471520/pap
static void close_state (lua_State *L) {
  global_State globalState;
  lua_State luaState;

  luaF_close(L, L->stack);  /* close all upvalues for this thread */

  luaState.l_G = &globalState;
  globalState.reallocFunc = G(L)->reallocFunc;
  globalState.freeFunc = G(L)->freeFunc;
  globalState.memData = G(L)->memData;

  if (G(L)) {  /* close global state */
    luaC_sweep(L, 1);  /* collect all elements */
#if !LUA_REFCOUNT
    lua_assert(G(L)->rootgc == NULL);
    lua_assert(G(L)->rootudata == NULL);
#endif LUA_REFCOUNT
    luaS_freeall(L);
    luaZ_freebuffer(L, &G(L)->buff);
  }
  freestack(L, L);
  if (G(L)) {
//jj This check doesn't work anymore, because LuaState variables are allocated through the
//jj memory interface, too.
//jj    lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State));
    luaM_freelem(&luaState, G(L));
  }
  freestate(&luaState, L);
}
예제 #2
0
파일: lgc.c 프로젝트: gitrider/wxsj2
static void freeobj (lua_State *L, GCObject *o) {
  switch (o->gch.tt) {
    case LUA_TPROTO: luaF_freeproto(L, gcotop(o)); break;
    case LUA_TFUNCTION: luaF_freeclosure(L, gcotocl(o)); break;
    case LUA_TUPVAL: luaM_freelem(L, gcotouv(o)); break;
    case LUA_TTABLE: luaH_free(L, gcotoh(o)); break;
    case LUA_TTHREAD: {
      lua_assert(gcototh(o) != L && gcototh(o) != G(L)->mainthread);
      luaE_freethread(L, gcototh(o));
      break;
    }
    case LUA_TSTRING: {
      luaM_free(L, o, sizestring(gcotots(o)->tsv.len));
      break;
    }
    case LUA_TWSTRING: {
      luaM_free(L, o, sizewstring(gcototws(o)->tsv.len));
      break;
    }
    case LUA_TUSERDATA: {
      luaM_free(L, o, sizeudata(gcotou(o)->uv.len));
      break;
    }
#if LUA_REFCOUNT
	case LUA_TNIL: {
      break;  // Do nothing.
    }
#endif LUA_REFCOUNT
    default: lua_assert(0);
  }
}
예제 #3
0
파일: lfunc.c 프로젝트: dodong471520/pap
void luaF_freeproto (lua_State *L, Proto *f) {
  luaM_freearray(L, f->code, f->sizecode, Instruction);
  luaM_freearray(L, f->p, f->sizep, Proto *);
  luaM_freearray(L, f->k, f->sizek, TObject);
  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
  luaM_freelem(L, f);
}
예제 #4
0
파일: lstate.c 프로젝트: zlandau/lua-safe
static void close_state (lua_State *L) {
  luaF_close(L, L->stack);  /* close all upvalues for this thread */
  if (G(L)) {  /* close global state */
    luaC_sweep(L, 1);  /* collect all elements */
    lua_assert(G(L)->rootgc == NULL);
    lua_assert(G(L)->rootudata == NULL);
    luaS_freeall(L);
    luaZ_freebuffer(L, &G(L)->buff);
  }
  freestack(L, L);
  if (G(L)) {
    lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State));
    luaM_freelem(NULL, G(L));
  }
  freestate(NULL, L);
}