More disciplined use of 'getstr' and 'tsslen'

We may want to add other string variants in the future; this change
documents better where the code may need to handle those variants.
This commit is contained in:
Roberto Ierusalimschy
2023-08-17 15:59:28 -03:00
parent f4211a5ea4
commit 9b4f39ab14
9 changed files with 37 additions and 33 deletions

8
lgc.c
View File

@@ -542,10 +542,12 @@ static void traversestrongtable (global_State *g, Table *h) {
static lu_mem traversetable (global_State *g, Table *h) {
const char *weakkey, *weakvalue;
const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
TString *smode;
markobjectN(g, h->metatable);
if (mode && ttisstring(mode) && /* is there a weak mode? */
(cast_void(weakkey = strchr(svalue(mode), 'k')),
cast_void(weakvalue = strchr(svalue(mode), 'v')),
if (mode && ttisshrstring(mode) && /* is there a weak mode? */
(cast_void(smode = tsvalue(mode)),
cast_void(weakkey = strchr(getshrstr(smode), 'k')),
cast_void(weakvalue = strchr(getshrstr(smode), 'v')),
(weakkey || weakvalue))) { /* is really weak? */
if (!weakkey) /* strong keys? */
traverseweakvalue(g, h);