aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-04-17 14:58:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-04-17 14:58:55 -0300
commit50fd8d03c33bbe52ac5b34c4eb748197b349cedd (patch)
treeef63c627346c7609fea578cd9d8399ae500c00b2
parent3dbb1a4b894c0744a331d4319d8d1704dc4ad943 (diff)
downloadlua-50fd8d03c33bbe52ac5b34c4eb748197b349cedd.tar.gz
lua-50fd8d03c33bbe52ac5b34c4eb748197b349cedd.tar.bz2
lua-50fd8d03c33bbe52ac5b34c4eb748197b349cedd.zip
Function 'luaK_semerror' made vararg
All calls to 'luaK_semerror' were using 'luaO_pushfstring' to create the error messages.
-rw-r--r--lcode.c9
-rw-r--r--lcode.h2
-rw-r--r--lparser.c30
3 files changed, 21 insertions, 20 deletions
diff --git a/lcode.c b/lcode.c
index 8c04d8ab..d22a081a 100644
--- a/lcode.c
+++ b/lcode.c
@@ -40,7 +40,14 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
40 40
41 41
42/* semantic error */ 42/* semantic error */
43l_noret luaK_semerror (LexState *ls, const char *msg) { 43l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
44 const char *msg;
45 va_list argp;
46 va_start(argp, fmt);
47 msg = luaO_pushvfstring(ls->L, fmt, argp);
48 va_end(argp);
49 if (msg == NULL) /* error? */
50 luaD_throw(ls->L, LUA_ERRMEM);
44 ls->t.token = 0; /* remove "near <token>" from final message */ 51 ls->t.token = 0; /* remove "near <token>" from final message */
45 luaX_syntaxerror(ls, msg); 52 luaX_syntaxerror(ls, msg);
46} 53}
diff --git a/lcode.h b/lcode.h
index 414ebe39..94fc2417 100644
--- a/lcode.h
+++ b/lcode.h
@@ -97,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
97 int ra, int asize, int hsize); 97 int ra, int asize, int hsize);
98LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 98LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
99LUAI_FUNC void luaK_finish (FuncState *fs); 99LUAI_FUNC void luaK_finish (FuncState *fs);
100LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); 100LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *fmt, ...);
101 101
102 102
103#endif 103#endif
diff --git a/lparser.c b/lparser.c
index 380e45f5..e71d7212 100644
--- a/lparser.c
+++ b/lparser.c
@@ -306,11 +306,9 @@ static void check_readonly (LexState *ls, expdesc *e) {
306 default: 306 default:
307 return; /* other cases cannot be read-only */ 307 return; /* other cases cannot be read-only */
308 } 308 }
309 if (varname) { 309 if (varname)
310 const char *msg = luaO_pushfstring(ls->L, 310 luaK_semerror(ls, "attempt to assign to const variable '%s'",
311 "attempt to assign to const variable '%s'", getstr(varname)); 311 getstr(varname));
312 luaK_semerror(ls, msg); /* error */
313 }
314} 312}
315 313
316 314
@@ -523,9 +521,9 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
523static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) { 521static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
524 TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name; 522 TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
525 const char *varname = getstr(tsname); 523 const char *varname = getstr(tsname);
526 const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'"; 524 luaK_semerror(ls,
527 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname); 525 "<goto %s> at line %d jumps into the scope of local '%s'",
528 luaK_semerror(ls, msg); /* raise the error */ 526 getstr(gt->name), gt->line, varname); /* raise the error */
529} 527}
530 528
531 529
@@ -677,11 +675,10 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
677** generates an error for an undefined 'goto'. 675** generates an error for an undefined 'goto'.
678*/ 676*/
679static l_noret undefgoto (LexState *ls, Labeldesc *gt) { 677static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
680 const char *msg = "no visible label '%s' for <goto> at line %d";
681 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
682 /* breaks are checked when created, cannot be undefined */ 678 /* breaks are checked when created, cannot be undefined */
683 lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break"))); 679 lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break")));
684 luaK_semerror(ls, msg); 680 luaK_semerror(ls, "no visible label '%s' for <goto> at line %d",
681 getstr(gt->name), gt->line);
685} 682}
686 683
687 684
@@ -1479,11 +1476,9 @@ static void breakstat (LexState *ls, int line) {
1479*/ 1476*/
1480static void checkrepeated (LexState *ls, TString *name) { 1477static void checkrepeated (LexState *ls, TString *name) {
1481 Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel); 1478 Labeldesc *lb = findlabel(ls, name, ls->fs->firstlabel);
1482 if (l_unlikely(lb != NULL)) { /* already defined? */ 1479 if (l_unlikely(lb != NULL)) /* already defined? */
1483 const char *msg = "label '%s' already defined on line %d"; 1480 luaK_semerror(ls, "label '%s' already defined on line %d",
1484 msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line); 1481 getstr(name), lb->line); /* error */
1485 luaK_semerror(ls, msg); /* error */
1486 }
1487} 1482}
1488 1483
1489 1484
@@ -1718,8 +1713,7 @@ static lu_byte getlocalattribute (LexState *ls) {
1718 else if (strcmp(attr, "close") == 0) 1713 else if (strcmp(attr, "close") == 0)
1719 return RDKTOCLOSE; /* to-be-closed variable */ 1714 return RDKTOCLOSE; /* to-be-closed variable */
1720 else 1715 else
1721 luaK_semerror(ls, 1716 luaK_semerror(ls, "unknown attribute '%s'", attr);
1722 luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
1723 } 1717 }
1724 return VDKREG; /* regular variable */ 1718 return VDKREG; /* regular variable */
1725} 1719}