aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-08 15:28:25 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-08 15:28:25 -0200
commite663a24ab03a54fa221c20a793812e5c5ffdf94f (patch)
tree8fbd40f779f0eed29d46f26c07e1234fd5df8bae /lapi.c
parent40f823ec907fd725617e37199199b3ed424bd88c (diff)
downloadlua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.gz
lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.bz2
lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.zip
more freedom in handling memory-allocation errors (not all allocations
automatically raise an error), which allows fixing a bug when resizing a table.
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/lapi.c b/lapi.c
index 3098cb9c..d6aaf8a8 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.277 2017/11/23 19:29:04 roberto Exp roberto $ 2** $Id: lapi.c,v 2.278 2017/12/06 18:08:03 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -99,16 +99,6 @@ static StkId index2stack (lua_State *L, int idx) {
99} 99}
100 100
101 101
102/*
103** to be called by 'lua_checkstack' in protected mode, to grow stack
104** capturing memory errors
105*/
106static void growstack (lua_State *L, void *ud) {
107 int size = *(int *)ud;
108 luaD_growstack(L, size);
109}
110
111
112LUA_API int lua_checkstack (lua_State *L, int n) { 102LUA_API int lua_checkstack (lua_State *L, int n) {
113 int res; 103 int res;
114 CallInfo *ci = L->ci; 104 CallInfo *ci = L->ci;
@@ -121,7 +111,7 @@ LUA_API int lua_checkstack (lua_State *L, int n) {
121 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */ 111 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */
122 res = 0; /* no */ 112 res = 0; /* no */
123 else /* try to grow stack */ 113 else /* try to grow stack */
124 res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK); 114 res = luaD_growstack(L, n, 0);
125 } 115 }
126 if (res && ci->top < L->top + n) 116 if (res && ci->top < L->top + n)
127 ci->top = L->top + n; /* adjust frame top */ 117 ci->top = L->top + n; /* adjust frame top */