aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-12-14 09:59:27 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-12-14 09:59:27 -0200
commitbda090b96168eb2080259cad70f1d830e42f2cb4 (patch)
tree958fb625707c805b666d9b0c15a3b6767b46bf30 /lauxlib.c
parente3839416526b41c1d3f859a79760f8ff22794293 (diff)
downloadlua-bda090b96168eb2080259cad70f1d830e42f2cb4.tar.gz
lua-bda090b96168eb2080259cad70f1d830e42f2cb4.tar.bz2
lua-bda090b96168eb2080259cad70f1d830e42f2cb4.zip
comments + small code changes around stack usage when 'luaL_checkstack'
raises an error (and needs the stack to create the error message...)
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/lauxlib.c b/lauxlib.c
index e6d83cd9..ca2dd749 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.283 2015/10/06 16:10:22 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.284 2015/11/19 19:16:22 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -198,6 +198,10 @@ static void tag_error (lua_State *L, int arg, int tag) {
198} 198}
199 199
200 200
201/*
202** The use of 'lua_pushfstring' ensures this function does not
203** need reserved stack space when called.
204*/
201LUALIB_API void luaL_where (lua_State *L, int level) { 205LUALIB_API void luaL_where (lua_State *L, int level) {
202 lua_Debug ar; 206 lua_Debug ar;
203 if (lua_getstack(L, level, &ar)) { /* check function at level */ 207 if (lua_getstack(L, level, &ar)) { /* check function at level */
@@ -207,10 +211,14 @@ LUALIB_API void luaL_where (lua_State *L, int level) {
207 return; 211 return;
208 } 212 }
209 } 213 }
210 lua_pushliteral(L, ""); /* else, no information available... */ 214 lua_pushfstring(L, ""); /* else, no information available... */
211} 215}
212 216
213 217
218/*
219** Again, the use of 'lua_pushvfstring' ensures this function does
220** not need reserved stack space when called.
221*/
214LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { 222LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
215 va_list argp; 223 va_list argp;
216 va_start(argp, fmt); 224 va_start(argp, fmt);
@@ -349,9 +357,17 @@ LUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,
349} 357}
350 358
351 359
360/*
361** Ensures the stack has at least 'space' extra slots, raising
362** an error if it cannot fulfill the request. It adds some
363** extra space so that, next time it is called (this function
364** is typically called inside a loop), it has space to format
365** the error message. (In case of an error without this extra
366** space, Lua will generate the same 'stack overflow' error,
367** but without 'msg'.)
368*/
352LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { 369LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {
353 /* keep some extra space to run error routines, if needed */ 370 const int extra = 5; /* extra space to run error routines */
354 const int extra = LUA_MINSTACK;
355 if (!lua_checkstack(L, space + extra)) { 371 if (!lua_checkstack(L, space + extra)) {
356 if (msg) 372 if (msg)
357 luaL_error(L, "stack overflow (%s)", msg); 373 luaL_error(L, "stack overflow (%s)", msg);
@@ -678,7 +694,7 @@ static int skipcomment (LoadF *lf, int *cp) {
678 if (c == '#') { /* first line is a comment (Unix exec. file)? */ 694 if (c == '#') { /* first line is a comment (Unix exec. file)? */
679 do { /* skip first line */ 695 do { /* skip first line */
680 c = getc(lf->f); 696 c = getc(lf->f);
681 } while (c != EOF && c != '\n') ; 697 } while (c != EOF && c != '\n');
682 *cp = getc(lf->f); /* skip end-of-line, if present */ 698 *cp = getc(lf->f); /* skip end-of-line, if present */
683 return 1; /* there was a comment */ 699 return 1; /* there was a comment */
684 } 700 }