| 492 | |
| 493 | |
| 494 | static lu_mem traversestack (global_State *g, lua_State *th) { |
| 495 | int n = 0; |
| 496 | StkId o = th->stack; |
| 497 | if (o == NULL) |
| 498 | return 1; /* stack not completely built yet */ |
| 499 | for (; o < th->top; o++) /* mark live elements in the stack */ |
| 500 | markvalue(g, o); |
| 501 | if (g->gcstate == GCSatomic) { /* final traversal? */ |
| 502 | StkId lim = th->stack + th->stacksize; /* real end of stack */ |
| 503 | for (; o < lim; o++) /* clear not-marked stack slice */ |
| 504 | setnilvalue(o); |
| 505 | } |
| 506 | else { /* count call infos to compute size */ |
| 507 | CallInfo *ci; |
| 508 | for (ci = &th->base_ci; ci != th->ci; ci = ci->next) |
| 509 | n++; |
| 510 | } |
| 511 | return sizeof(lua_State) + sizeof(TValue) * th->stacksize + |
| 512 | sizeof(CallInfo) * n; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | /* |