aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-17 15:59:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-17 15:59:28 -0300
commit9b4f39ab14fb2e55345c3d23537d129dac23b091 (patch)
treec7e11448e4d6eb1fec6e0a6d58544f17b1a39e10 /lgc.c
parentf4211a5ea4e235ccfa8b8dfa46031c23e9e839e2 (diff)
downloadlua-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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lgc.c b/lgc.c
index f8f43393..253a2892 100644
--- a/lgc.c
+++ b/lgc.c
@@ -542,10 +542,12 @@ static void traversestrongtable (global_State *g, Table *h) {
542static lu_mem traversetable (global_State *g, Table *h) { 542static 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);