aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-04 16:40:53 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-04 16:40:53 -0300
commit2db966fcbf757775c842bc66449d7e697826aa1d (patch)
tree8eba3e6289af6a2038802754de4197931c5d3ec3
parentae9a0cbbb446499e759acae47664d1d136d7ba90 (diff)
downloadlua-2db966fcbf757775c842bc66449d7e697826aa1d.tar.gz
lua-2db966fcbf757775c842bc66449d7e697826aa1d.tar.bz2
lua-2db966fcbf757775c842bc66449d7e697826aa1d.zip
Bug: luaL_traceback may need more than 5 stack slots
-rw-r--r--lauxlib.c1
-rw-r--r--ltests.c5
-rw-r--r--testes/errors.lua15
3 files changed, 20 insertions, 1 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 28bff274..baa67ce6 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -80,6 +80,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
80 int top = lua_gettop(L); 80 int top = lua_gettop(L);
81 lua_getinfo(L, "f", ar); /* push function */ 81 lua_getinfo(L, "f", ar); /* push function */
82 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); 82 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
83 luaL_checkstack(L, 6, "not enough stack"); /* slots for 'findfield' */
83 if (findfield(L, top + 1, 2)) { 84 if (findfield(L, top + 1, 2)) {
84 const char *name = lua_tostring(L, -1); 85 const char *name = lua_tostring(L, -1);
85 if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */ 86 if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */
diff --git a/ltests.c b/ltests.c
index c2943a4f..a27cdb07 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1650,6 +1650,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1650 int nres; 1650 int nres;
1651 status = lua_resume(lua_tothread(L1, i), L, getnum, &nres); 1651 status = lua_resume(lua_tothread(L1, i), L, getnum, &nres);
1652 } 1652 }
1653 else if EQ("traceback") {
1654 const char *msg = getstring;
1655 int level = getnum;
1656 luaL_traceback(L1, L1, msg, level);
1657 }
1653 else if EQ("return") { 1658 else if EQ("return") {
1654 int n = getnum; 1659 int n = getnum;
1655 if (L1 != L) { 1660 if (L1 != L) {
diff --git a/testes/errors.lua b/testes/errors.lua
index 01cfe906..80d91a92 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -91,7 +91,7 @@ end
91 91
92if not T then 92if not T then
93 (Message or print) 93 (Message or print)
94 ('\n >>> testC not active: skipping memory message test <<<\n') 94 ('\n >>> testC not active: skipping tests for messages in C <<<\n')
95else 95else
96 print "testing memory error message" 96 print "testing memory error message"
97 local a = {} 97 local a = {}
@@ -104,6 +104,19 @@ else
104 end) 104 end)
105 T.totalmem(0) 105 T.totalmem(0)
106 assert(not st and msg == "not enough" .. " memory") 106 assert(not st and msg == "not enough" .. " memory")
107
108 -- stack space for luaL_traceback (bug in 5.4.6)
109 local res = T.testC[[
110 # push 16 elements on the stack
111 pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
112 pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
113 pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
114 pushnum 1;
115 # traceback should work with 4 remaining slots
116 traceback xuxu 1;
117 return 1
118 ]]
119 assert(string.find(res, "xuxu.-main chunk"))
107end 120end
108 121
109 122