Ejemplo n.º 1
0
Archivo: lgc.c Proyecto: 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);
  }
}
Ejemplo n.º 2
0
/* Persist all stack members
 */
static void persistthread(PersistInfo *pi) {
	int posremaining;
	lua_State *L2;
	/* perms reftbl ... thr */
	L2 = lua_tothread(pi->L, -1);
	if(pi->L == L2) {
		lua_pushstring(pi->L, "Can't persist currently running thread");
		lua_error(pi->L);
		return; /* not reached */
	}
	posremaining = revappendstack(L2, pi->L);
	/* perms reftbl ... thr (rev'ed contents of L2) */
	pi->writer(pi->L, &posremaining, sizeof(int), pi->ud);
	for(; posremaining > 0; posremaining--) {
		persist(pi);
		lua_pop(pi->L, 1);
	}
	/* perms reftbl ... thr */
	/* Now, persist the CallInfo stack. */
	{
		int i, numframes = (L2->ci - L2->base_ci) + 1;
		pi->writer(pi->L, &numframes, sizeof(int), pi->ud);
		for(i=0; i<numframes; i++) {
			CallInfo *ci = L2->base_ci + i;
			int stackbase = ci->base - L2->stack;
			int stacktop = ci->top - L2->stack;
			int pc = (ci != L2->base_ci) ?
			         ci->u.l.savedpc - ci_func(ci)->l.p->code :
			         0;
			pi->writer(pi->L, &stackbase, sizeof(int), pi->ud);
			pi->writer(pi->L, &stacktop, sizeof(int), pi->ud);
			pi->writer(pi->L, &pc, sizeof(int), pi->ud);
			pi->writer(pi->L, &(ci->state), sizeof(int), pi->ud);
		}
	}

	/* Serialize the state's top and base */
	{
		int stackbase = L2->base - L2->stack;
		int stacktop = L2->top - L2->stack;
		pi->writer(pi->L, &stackbase, sizeof(int), pi->ud);
		pi->writer(pi->L, &stacktop, sizeof(int), pi->ud);
	}

	/* Finally, record upvalues which need to be reopened */
	/* See the comment above persistupval() for why we do this */
	{
		UpVal *uv;
		/* perms reftbl ... thr */
		for(uv = gcotouv(L2->openupval); uv != NULL; uv = gcotouv(uv->next)) {
			int stackpos;
			/* Make sure upvalue is really open */
			lua_assert(uv->v != &uv->value);
			pushupval(pi->L, uv);
			/* perms reftbl ... thr uv */
			persist(pi);
			lua_pop(pi->L, 1);
			/* perms reftbl ... thr */
			stackpos = uv->v - L2->stack;
			pi->writer(pi->L, &stackpos, sizeof(int), pi->ud);
		}
		/* perms reftbl ... thr */
		lua_pushnil(pi->L);
		/* perms reftbl ... thr nil */
		persist(pi);
		lua_pop(pi->L, 1);
		/* perms reftbl ... thr */
	}
	/* perms reftbl ... thr */
}
Ejemplo n.º 3
0
static UpVal *toupval(lua_State *L, int stackpos) {
	return gcotouv(getobject(L, stackpos)->value.gc);
}