diff options
Diffstat (limited to 'src/lj_state.c')
-rw-r--r-- | src/lj_state.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lj_state.c b/src/lj_state.c index 87f2cfe9..f7647f33 100644 --- a/src/lj_state.c +++ b/src/lj_state.c | |||
@@ -52,16 +52,18 @@ | |||
52 | /* Resize stack slots and adjust pointers in state. */ | 52 | /* Resize stack slots and adjust pointers in state. */ |
53 | static void resizestack(lua_State *L, MSize n) | 53 | static void resizestack(lua_State *L, MSize n) |
54 | { | 54 | { |
55 | TValue *st, *oldst = L->stack; | 55 | TValue *st, *oldst = tvref(L->stack); |
56 | ptrdiff_t delta; | 56 | ptrdiff_t delta; |
57 | MSize oldsize = L->stacksize; | 57 | MSize oldsize = L->stacksize; |
58 | MSize realsize = n + 1 + LJ_STACK_EXTRA; | 58 | MSize realsize = n + 1 + LJ_STACK_EXTRA; |
59 | GCobj *up; | 59 | GCobj *up; |
60 | lua_assert((MSize)(L->maxstack-L->stack) == L->stacksize-LJ_STACK_EXTRA-1); | 60 | lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1); |
61 | lj_mem_reallocvec(L, L->stack, L->stacksize, realsize, TValue); | 61 | st = (TValue *)lj_mem_realloc(L, tvref(L->stack), |
62 | st = L->stack; | 62 | (MSize)(L->stacksize*sizeof(TValue)), |
63 | (MSize)(realsize*sizeof(TValue))); | ||
64 | setmref(L->stack, st); | ||
63 | delta = (char *)st - (char *)oldst; | 65 | delta = (char *)st - (char *)oldst; |
64 | L->maxstack = st + n; | 66 | setmref(L->maxstack, st + n); |
65 | while (oldsize < realsize) /* Clear new slots. */ | 67 | while (oldsize < realsize) /* Clear new slots. */ |
66 | setnilV(st + oldsize++); | 68 | setnilV(st + oldsize++); |
67 | L->stacksize = realsize; | 69 | L->stacksize = realsize; |
@@ -76,7 +78,7 @@ static void resizestack(lua_State *L, MSize n) | |||
76 | /* Relimit stack after error, in case the limit was overdrawn. */ | 78 | /* Relimit stack after error, in case the limit was overdrawn. */ |
77 | void lj_state_relimitstack(lua_State *L) | 79 | void lj_state_relimitstack(lua_State *L) |
78 | { | 80 | { |
79 | if (L->stacksize > LJ_STACK_MAXEX && L->top - L->stack < LJ_STACK_MAX-1) | 81 | if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1) |
80 | resizestack(L, LJ_STACK_MAX); | 82 | resizestack(L, LJ_STACK_MAX); |
81 | } | 83 | } |
82 | 84 | ||
@@ -118,11 +120,11 @@ void LJ_FASTCALL lj_state_growstack1(lua_State *L) | |||
118 | /* Allocate basic stack for new state. */ | 120 | /* Allocate basic stack for new state. */ |
119 | static void stack_init(lua_State *L1, lua_State *L) | 121 | static void stack_init(lua_State *L1, lua_State *L) |
120 | { | 122 | { |
121 | TValue *st, *stend; | 123 | TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue); |
122 | L1->stack = st = lj_mem_newvec(L, LJ_STACK_START + LJ_STACK_EXTRA, TValue); | 124 | setmref(L1->stack, st); |
123 | L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA; | 125 | L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA; |
124 | stend = st + L1->stacksize; | 126 | stend = st + L1->stacksize; |
125 | L1->maxstack = stend - LJ_STACK_EXTRA - 1; | 127 | setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1); |
126 | L1->base = L1->top = st+1; | 128 | L1->base = L1->top = st+1; |
127 | setthreadV(L1, st, L1); /* Needed for curr_funcisL() on empty stack. */ | 129 | setthreadV(L1, st, L1); /* Needed for curr_funcisL() on empty stack. */ |
128 | while (st < stend) /* Clear new slots. */ | 130 | while (st < stend) /* Clear new slots. */ |
@@ -162,14 +164,14 @@ static void close_state(lua_State *L) | |||
162 | } else | 164 | } else |
163 | #endif | 165 | #endif |
164 | { | 166 | { |
165 | lj_func_closeuv(L, L->stack); | 167 | lj_func_closeuv(L, tvref(L->stack)); |
166 | lj_gc_freeall(g); | 168 | lj_gc_freeall(g); |
167 | lua_assert(gcref(g->gc.root) == obj2gco(L)); | 169 | lua_assert(gcref(g->gc.root) == obj2gco(L)); |
168 | lua_assert(g->strnum == 0); | 170 | lua_assert(g->strnum == 0); |
169 | lj_trace_freestate(g); | 171 | lj_trace_freestate(g); |
170 | lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); | 172 | lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef); |
171 | lj_str_freebuf(g, &g->tmpbuf); | 173 | lj_str_freebuf(g, &g->tmpbuf); |
172 | lj_mem_freevec(g, L->stack, L->stacksize, TValue); | 174 | lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); |
173 | lua_assert(g->gc.total == sizeof(GG_State)); | 175 | lua_assert(g->gc.total == sizeof(GG_State)); |
174 | g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); | 176 | g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); |
175 | } | 177 | } |
@@ -234,7 +236,7 @@ LUA_API void lua_close(lua_State *L) | |||
234 | { | 236 | { |
235 | global_State *g = G(L); | 237 | global_State *g = G(L); |
236 | L = mainthread(g); /* Only the main thread can be closed. */ | 238 | L = mainthread(g); /* Only the main thread can be closed. */ |
237 | lj_func_closeuv(L, L->stack); | 239 | lj_func_closeuv(L, tvref(L->stack)); |
238 | lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */ | 240 | lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */ |
239 | #if LJ_HASJIT | 241 | #if LJ_HASJIT |
240 | G2J(g)->flags &= ~JIT_F_ON; | 242 | G2J(g)->flags &= ~JIT_F_ON; |
@@ -245,7 +247,7 @@ LUA_API void lua_close(lua_State *L) | |||
245 | hook_enter(g); | 247 | hook_enter(g); |
246 | L->status = 0; | 248 | L->status = 0; |
247 | L->cframe = NULL; | 249 | L->cframe = NULL; |
248 | L->base = L->top = L->stack + 1; | 250 | L->base = L->top = tvref(L->stack) + 1; |
249 | } while (lj_vm_cpcall(L, NULL, NULL, cpfinalize) != 0); | 251 | } while (lj_vm_cpcall(L, NULL, NULL, cpfinalize) != 0); |
250 | close_state(L); | 252 | close_state(L); |
251 | } | 253 | } |
@@ -257,7 +259,7 @@ lua_State *lj_state_new(lua_State *L) | |||
257 | L1->dummy_ffid = FF_C; | 259 | L1->dummy_ffid = FF_C; |
258 | L1->status = 0; | 260 | L1->status = 0; |
259 | L1->stacksize = 0; | 261 | L1->stacksize = 0; |
260 | L1->stack = NULL; | 262 | setmref(L1->stack, NULL); |
261 | L1->cframe = NULL; | 263 | L1->cframe = NULL; |
262 | /* NOBARRIER: The lua_State is new (marked white). */ | 264 | /* NOBARRIER: The lua_State is new (marked white). */ |
263 | setgcrefnull(L1->openupval); | 265 | setgcrefnull(L1->openupval); |
@@ -271,9 +273,9 @@ lua_State *lj_state_new(lua_State *L) | |||
271 | void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L) | 273 | void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L) |
272 | { | 274 | { |
273 | lua_assert(L != mainthread(g)); | 275 | lua_assert(L != mainthread(g)); |
274 | lj_func_closeuv(L, L->stack); | 276 | lj_func_closeuv(L, tvref(L->stack)); |
275 | lua_assert(gcref(L->openupval) == NULL); | 277 | lua_assert(gcref(L->openupval) == NULL); |
276 | lj_mem_freevec(g, L->stack, L->stacksize, TValue); | 278 | lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue); |
277 | lj_mem_freet(g, L); | 279 | lj_mem_freet(g, L); |
278 | } | 280 | } |
279 | 281 | ||