aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-04 11:45:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-04 11:45:26 -0300
commit5ca1075b714e825006e8ba4f8e7ea5544879bb41 (patch)
treead085afa58f29e8e96071ae88c1e6e1dd73e0750 /ldebug.c
parent38425e069243fe6d991f2e99b4bba192af3563c7 (diff)
downloadlua-5ca1075b714e825006e8ba4f8e7ea5544879bb41.tar.gz
lua-5ca1075b714e825006e8ba4f8e7ea5544879bb41.tar.bz2
lua-5ca1075b714e825006e8ba4f8e7ea5544879bb41.zip
Added field 'srclen' to structure 'lua_Debug'
This new field gets the length of 'source' in the same structure. Unlike the other strings in that structure, 'source' can be relatively large, and Lua already has its length readily available.
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/ldebug.c b/ldebug.c
index bd471e0c..6cd4e071 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -262,18 +262,26 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
262static void funcinfo (lua_Debug *ar, Closure *cl) { 262static void funcinfo (lua_Debug *ar, Closure *cl) {
263 if (noLuaClosure(cl)) { 263 if (noLuaClosure(cl)) {
264 ar->source = "=[C]"; 264 ar->source = "=[C]";
265 ar->srclen = LL("=[C]");
265 ar->linedefined = -1; 266 ar->linedefined = -1;
266 ar->lastlinedefined = -1; 267 ar->lastlinedefined = -1;
267 ar->what = "C"; 268 ar->what = "C";
268 } 269 }
269 else { 270 else {
270 const Proto *p = cl->l.p; 271 const Proto *p = cl->l.p;
271 ar->source = p->source ? getstr(p->source) : "=?"; 272 if (p->source) {
273 ar->source = getstr(p->source);
274 ar->srclen = tsslen(p->source);
275 }
276 else {
277 ar->source = "=?";
278 ar->srclen = LL("=?");
279 }
272 ar->linedefined = p->linedefined; 280 ar->linedefined = p->linedefined;
273 ar->lastlinedefined = p->lastlinedefined; 281 ar->lastlinedefined = p->lastlinedefined;
274 ar->what = (ar->linedefined == 0) ? "main" : "Lua"; 282 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
275 } 283 }
276 luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); 284 luaO_chunkid(ar->short_src, ar->source, ar->srclen);
277} 285}
278 286
279 287
@@ -750,7 +758,7 @@ const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
750 int line) { 758 int line) {
751 char buff[LUA_IDSIZE]; 759 char buff[LUA_IDSIZE];
752 if (src) 760 if (src)
753 luaO_chunkid(buff, getstr(src), LUA_IDSIZE); 761 luaO_chunkid(buff, getstr(src), tsslen(src));
754 else { /* no source available; use "?" instead */ 762 else { /* no source available; use "?" instead */
755 buff[0] = '?'; buff[1] = '\0'; 763 buff[0] = '?'; buff[1] = '\0';
756 } 764 }