diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-17 15:59:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-17 15:59:28 -0300 |
commit | 9b4f39ab14fb2e55345c3d23537d129dac23b091 (patch) | |
tree | c7e11448e4d6eb1fec6e0a6d58544f17b1a39e10 /lgc.c | |
parent | f4211a5ea4e235ccfa8b8dfa46031c23e9e839e2 (diff) | |
download | lua-9b4f39ab14fb2e55345c3d23537d129dac23b091.tar.gz lua-9b4f39ab14fb2e55345c3d23537d129dac23b091.tar.bz2 lua-9b4f39ab14fb2e55345c3d23537d129dac23b091.zip |
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.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -542,10 +542,12 @@ static void traversestrongtable (global_State *g, Table *h) { | |||
542 | static lu_mem traversetable (global_State *g, Table *h) { | 542 | static lu_mem traversetable (global_State *g, Table *h) { |
543 | const char *weakkey, *weakvalue; | 543 | const char *weakkey, *weakvalue; |
544 | const TValue *mode = gfasttm(g, h->metatable, TM_MODE); | 544 | const TValue *mode = gfasttm(g, h->metatable, TM_MODE); |
545 | TString *smode; | ||
545 | markobjectN(g, h->metatable); | 546 | markobjectN(g, h->metatable); |
546 | if (mode && ttisstring(mode) && /* is there a weak mode? */ | 547 | if (mode && ttisshrstring(mode) && /* is there a weak mode? */ |
547 | (cast_void(weakkey = strchr(svalue(mode), 'k')), | 548 | (cast_void(smode = tsvalue(mode)), |
548 | cast_void(weakvalue = strchr(svalue(mode), 'v')), | 549 | cast_void(weakkey = strchr(getshrstr(smode), 'k')), |
550 | cast_void(weakvalue = strchr(getshrstr(smode), 'v')), | ||
549 | (weakkey || weakvalue))) { /* is really weak? */ | 551 | (weakkey || weakvalue))) { /* is really weak? */ |
550 | if (!weakkey) /* strong keys? */ | 552 | if (!weakkey) /* strong keys? */ |
551 | traverseweakvalue(g, h); | 553 | traverseweakvalue(g, h); |