aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-23 15:14:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-23 15:14:03 -0300
commitc815c2f0eb7a4ac01d4f664f3db44c199ee4e211 (patch)
tree63cdeea69af0df9ff82303d05c517068eb54e56e /lvm.c
parentab6a94952215b1f66436d8eeebded1dad9fa5409 (diff)
parent9363a8b9901a5643c9da061ea8dda8a86cdc7ef1 (diff)
downloadlua-c815c2f0eb7a4ac01d4f664f3db44c199ee4e211.tar.gz
lua-c815c2f0eb7a4ac01d4f664f3db44c199ee4e211.tar.bz2
lua-c815c2f0eb7a4ac01d4f664f3db44c199ee4e211.zip
Merge branch 'master' into nextversion
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/lvm.c b/lvm.c
index a3128c3d..256d689f 100644
--- a/lvm.c
+++ b/lvm.c
@@ -91,8 +91,10 @@ static int l_strton (const TValue *obj, TValue *result) {
91 lua_assert(obj != result); 91 lua_assert(obj != result);
92 if (!cvt2num(obj)) /* is object not a string? */ 92 if (!cvt2num(obj)) /* is object not a string? */
93 return 0; 93 return 0;
94 else 94 else {
95 return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1); 95 TString *st = tsvalue(obj);
96 return (luaO_str2num(getstr(st), result) == tsslen(st) + 1);
97 }
96} 98}
97 99
98 100
@@ -627,8 +629,9 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
627static void copy2buff (StkId top, int n, char *buff) { 629static void copy2buff (StkId top, int n, char *buff) {
628 size_t tl = 0; /* size already copied */ 630 size_t tl = 0; /* size already copied */
629 do { 631 do {
630 size_t l = vslen(s2v(top - n)); /* length of string being copied */ 632 TString *st = tsvalue(s2v(top - n));
631 memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char)); 633 size_t l = tsslen(st); /* length of string being copied */
634 memcpy(buff + tl, getstr(st), l * sizeof(char));
632 tl += l; 635 tl += l;
633 } while (--n > 0); 636 } while (--n > 0);
634} 637}
@@ -654,11 +657,11 @@ void luaV_concat (lua_State *L, int total) {
654 } 657 }
655 else { 658 else {
656 /* at least two non-empty string values; get as many as possible */ 659 /* at least two non-empty string values; get as many as possible */
657 size_t tl = vslen(s2v(top - 1)); 660 size_t tl = tsslen(tsvalue(s2v(top - 1)));
658 TString *ts; 661 TString *ts;
659 /* collect total length and number of strings */ 662 /* collect total length and number of strings */
660 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { 663 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
661 size_t l = vslen(s2v(top - n - 1)); 664 size_t l = tsslen(tsvalue(s2v(top - n - 1)));
662 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) { 665 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
663 L->top.p = top - total; /* pop strings to avoid wasting stack */ 666 L->top.p = top - total; /* pop strings to avoid wasting stack */
664 luaG_runerror(L, "string length overflow"); 667 luaG_runerror(L, "string length overflow");
@@ -672,7 +675,7 @@ void luaV_concat (lua_State *L, int total) {
672 } 675 }
673 else { /* long string; copy strings directly to final result */ 676 else { /* long string; copy strings directly to final result */
674 ts = luaS_createlngstrobj(L, tl); 677 ts = luaS_createlngstrobj(L, tl);
675 copy2buff(top, n, getstr(ts)); 678 copy2buff(top, n, getlngstr(ts));
676 } 679 }
677 setsvalue2s(L, top - n, ts); /* create result */ 680 setsvalue2s(L, top - n, ts); /* create result */
678 } 681 }
@@ -1158,18 +1161,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1158 startfunc: 1161 startfunc:
1159 trap = L->hookmask; 1162 trap = L->hookmask;
1160 returning: /* trap already set */ 1163 returning: /* trap already set */
1161 cl = clLvalue(s2v(ci->func.p)); 1164 cl = ci_func(ci);
1162 k = cl->p->k; 1165 k = cl->p->k;
1163 pc = ci->u.l.savedpc; 1166 pc = ci->u.l.savedpc;
1164 if (l_unlikely(trap)) { 1167 if (l_unlikely(trap))
1165 if (pc == cl->p->code) { /* first instruction (not resuming)? */ 1168 trap = luaG_tracecall(L);
1166 if (cl->p->is_vararg)
1167 trap = 0; /* hooks will start after VARARGPREP instruction */
1168 else /* check 'call' hook */
1169 luaD_hookcall(L, ci);
1170 }
1171 ci->u.l.trap = 1; /* assume trap is on, for now */
1172 }
1173 base = ci->func.p + 1; 1169 base = ci->func.p + 1;
1174 /* main loop of interpreter */ 1170 /* main loop of interpreter */
1175 for (;;) { 1171 for (;;) {