** Traverse a table with weak values and link it to proper list. During ** propagate phase, keep it in 'grayagain' list, to be revisited in the ** atomic phase. In the atomic phase, if table has any white value, ** put it in 'weak' list, to be cleared. */
| 438 | ** put it in 'weak' list, to be cleared. |
| 439 | */ |
| 440 | static void traverseweakvalue (global_State *g, Table *h) { |
| 441 | Node *n, *limit = gnodelast(h); |
| 442 | /* if there is array part, assume it may have white values (it is not |
| 443 | worth traversing it now just to check) */ |
| 444 | int hasclears = (h->alimit > 0); |
| 445 | for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ |
| 446 | if (isempty(gval(n))) /* entry is empty? */ |
| 447 | clearkey(n); /* clear its key */ |
| 448 | else { |
| 449 | lua_assert(!keyisnil(n)); |
| 450 | markkey(g, n); |
| 451 | if (!hasclears && iscleared(g, gcvalueN(gval(n)))) /* a white value? */ |
| 452 | hasclears = 1; /* table will have to be cleared */ |
| 453 | } |
| 454 | } |
| 455 | if (g->gcstate == GCSatomic && hasclears) |
| 456 | linkgclist(h, g->weak); /* has to be cleared later */ |
| 457 | else |
| 458 | linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /* |
no test coverage detected