예제 #1
0
파일: lapi.c 프로젝트: AdunSG/Pktgen-DPDK
/*
** to be called by 'lua_checkstack' in protected mode, to grow stack
** capturing memory errors
*/
static void growstack (lua_State *L, void *ud) {
  int size = *(int *)ud;
  luaD_growstack(L, size);
}
예제 #2
0
파일: pluto.c 프로젝트: CeRiAl/DreamZZT
static void unpersistthread(int ref, UnpersistInfo *upi) {
	/* perms reftbl ... */
	lua_State *L2;
	L2 = lua_newthread(upi->L);
	/* L1: perms reftbl ... thr */
	/* L2: (empty) */
	registerobject(ref, upi);

	/* First, deserialize the object stack. */
	{
		int i, stacksize;
		verify(luaZ_read(&upi->zio, &stacksize, sizeof(int)) == 0);
		luaD_growstack(L2, stacksize);
		/* Make sure that the first stack element (a nil, representing
		 * the imaginary top-level C function) is written to the very,
		 * very bottom of the stack */
		L2->top--;
		for(i=0; i<stacksize; i++) {
			unpersist(upi);
			/* L1: perms reftbl ... thr obj* */
		}
		lua_xmove(upi->L, L2, stacksize);
		/* L1: perms reftbl ... thr */
		/* L2: obj* */
	}

	/* Now, deserialize the CallInfo stack. */
	{
		int i, numframes;
		verify(luaZ_read(&upi->zio, &numframes, sizeof(int)) == 0);
		luaD_reallocCI(L2,numframes*2);
		for(i=0; i<numframes; i++) {
			CallInfo *ci = L2->base_ci + i;
			int stackbase, stacktop, pc;
			verify(luaZ_read(&upi->zio, &stackbase, sizeof(int)) == 0);
			verify(luaZ_read(&upi->zio, &stacktop, sizeof(int)) == 0);
			verify(luaZ_read(&upi->zio, &pc, sizeof(int)) == 0);
			verify(luaZ_read(&upi->zio, &(ci->state), sizeof(int)) == 0);

			ci->base = L2->stack+stackbase;
			ci->top = L2->stack+stacktop;
			if(!(ci->state & CI_C)) {
				ci->u.l.savedpc = ci_func(ci)->l.p->code + pc;
			}
			ci->u.l.tailcalls = 0;
			/* Update the pointer each time, to keep the GC
			 * happy*/
			L2->ci = ci;
		}
	}
	/* L1: perms reftbl ... thr */
	{
		int stackbase, stacktop;
		verify(luaZ_read(&upi->zio, &stackbase, sizeof(int)) == 0);
		verify(luaZ_read(&upi->zio, &stacktop, sizeof(int)) == 0);
		L2->base = L2->stack + stackbase;
		L2->top = L2->stack + stacktop;
	}
	/* Finally, "reopen" upvalues (see persistupval() for why) */
	{
		UpVal* uv;
		GCObject **nextslot = &L2->openupval;
		while(1) {
			int stackpos;
			unpersist(upi);
			/* perms reftbl ... thr uv/nil */
			if(lua_isnil(upi->L, -1)) {
				/* perms reftbl ... thr nil */
				lua_pop(upi->L, 1);
				/* perms reftbl ... thr */
				break;
			}
			/* perms reftbl ... thr boxeduv */
			unboxupval(upi->L);
			/* perms reftbl ... thr uv */
			uv = toupval(upi->L, -1);
			lua_pop(upi->L, 1);
			/* perms reftbl ... thr */

			verify(luaZ_read(&upi->zio, &stackpos, sizeof(int)) == 0);
			uv->v = L2->stack + stackpos;
			gcunlink(upi->L, valtogco(uv));
			uv->marked = 1;
			*nextslot = valtogco(uv);
			nextslot = &uv->next;
		}
		*nextslot = NULL;
	}
}