diff options
author | Lua Team <team@lua.org> | 2012-06-01 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2012-06-01 12:00:00 +0000 |
commit | 850623c5e6a01fa1e8541c03b123fe6e35e02feb (patch) | |
tree | 472f02e44038add9ee5433cde9c38cded49ee5f0 | |
parent | 5a152a0a57f98f38472fac54b62fa8cdb9708d29 (diff) | |
download | lua-github-850623c5e6a01fa1e8541c03b123fe6e35e02feb.tar.gz |
Lua 5.2.1-rc35.2.1-rc3
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/manual.html | 91 | ||||
-rw-r--r-- | doc/readme.html | 3 | ||||
-rw-r--r-- | src/lauxlib.c | 6 | ||||
-rw-r--r-- | src/lgc.c | 87 | ||||
-rw-r--r-- | src/loadlib.c | 6 | ||||
-rw-r--r-- | src/lstate.c | 4 |
7 files changed, 114 insertions, 85 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.2.1, released on 23 May 2012. +This is Lua 5.2.1, released on 01 Jun 2012. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/manual.html b/doc/manual.html index 71b607d4..fd6d988a 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -33,7 +33,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> -<!-- $Id: manual.of,v 1.97 2012/05/23 15:50:01 roberto Exp $ --> +<!-- $Id: manual.of,v 1.98 2012/05/31 13:01:09 roberto Exp $ --> @@ -2828,8 +2828,7 @@ by looking only at its arguments The third field, <code>x</code>, tells whether the function may throw errors: '<code>-</code>' means the function never throws any error; -'<code>m</code>' means the function may throw only memory allocation errors; -'<code>e</code>' means the function may throw other kinds of errors; +'<code>e</code>' means the function may throw errors; '<code>v</code>' means the function may throw an error on purpose. @@ -3191,7 +3190,7 @@ without shifting any element <hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre> <p> @@ -3210,7 +3209,7 @@ Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</c <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p> -<span class="apii">[-0, +0, <em>m</em>]</span> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre> <p> @@ -3748,7 +3747,7 @@ passes to the allocator in every call. <hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void lua_newtable (lua_State *L);</pre> <p> @@ -3760,7 +3759,7 @@ It is equivalent to <code>lua_createtable(L, 0, 0)</code>. <hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>lua_State *lua_newthread (lua_State *L);</pre> <p> @@ -3781,7 +3780,7 @@ like any Lua object. <hr><h3><a name="lua_newuserdata"><code>lua_newuserdata</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void *lua_newuserdata (lua_State *L, size_t size);</pre> <p> @@ -3967,7 +3966,7 @@ Pushes a boolean value with value <code>b</code> onto the stack. <hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p> -<span class="apii">[-n, +1, <em>m</em>]</span> +<span class="apii">[-n, +1, <em>e</em>]</span> <pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre> <p> @@ -4033,7 +4032,7 @@ Note that <code>f</code> is used twice. <hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre> <p> @@ -4100,7 +4099,7 @@ light userdata with the same C address. <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre> <p> @@ -4113,7 +4112,7 @@ It automatically provides the string length. <hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre> <p> @@ -4156,7 +4155,7 @@ Pushes a number with value <code>n</code> onto the stack. <hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *lua_pushstring (lua_State *L, const char *s);</pre> <p> @@ -4203,7 +4202,7 @@ onto the stack. <hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);</pre> @@ -4290,7 +4289,7 @@ for other values, it is 0. <hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p> -<span class="apii">[-2, +0, <em>m</em>]</span> +<span class="apii">[-2, +0, <em>e</em>]</span> <pre>void lua_rawset (lua_State *L, int index);</pre> <p> @@ -4302,7 +4301,7 @@ Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw <hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p> -<span class="apii">[-1, +0, <em>m</em>]</span> +<span class="apii">[-1, +0, <em>e</em>]</span> <pre>void lua_rawseti (lua_State *L, int index, int n);</pre> <p> @@ -4321,7 +4320,7 @@ that is, it does not invoke metamethods. <hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p> -<span class="apii">[-1, +0, <em>m</em>]</span> +<span class="apii">[-1, +0, <em>e</em>]</span> <pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre> <p> @@ -4669,7 +4668,7 @@ indicates whether the operation succeeded. <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p> -<span class="apii">[-0, +0, <em>m</em>]</span> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre> <p> @@ -4752,7 +4751,7 @@ Typically this function is used only for debug information. <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p> -<span class="apii">[-0, +0, <em>m</em>]</span> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>const char *lua_tostring (lua_State *L, int index);</pre> <p> @@ -5154,7 +5153,7 @@ Returns the current hook mask. <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p> -<span class="apii">[-(0|1), +(0|1|2), <em>m</em>]</span> +<span class="apii">[-(0|1), +(0|1|2), <em>e</em>]</span> <pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre> <p> @@ -5553,7 +5552,7 @@ in alphabetical order. <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre> <p> @@ -5565,7 +5564,7 @@ Adds the byte <code>c</code> to the buffer <code>B</code> <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre> <p> @@ -5579,7 +5578,7 @@ The string can contain embedded zeros. <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre> <p> @@ -5592,7 +5591,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre> <p> @@ -5606,7 +5605,7 @@ The string cannot contain embedded zeros. <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p> -<span class="apii">[-1, +?, <em>m</em>]</span> +<span class="apii">[-1, +?, <em>e</em>]</span> <pre>void luaL_addvalue (luaL_Buffer *B);</pre> <p> @@ -5743,7 +5742,7 @@ the buffer must be declared as a variable <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre> <p> @@ -5970,7 +5969,7 @@ are using the same address space. <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p> -<span class="apii">[-0, +?, <em>m</em>]</span> +<span class="apii">[-0, +?, <em>e</em>]</span> <pre>int luaL_dofile (lua_State *L, const char *filename);</pre> <p> @@ -6029,7 +6028,7 @@ as <code>return luaL_error(<em>args</em>)</code>. <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p> -<span class="apii">[-0, +3, <em>m</em>]</span> +<span class="apii">[-0, +3, <em>e</em>]</span> <pre>int luaL_execresult (lua_State *L, int stat);</pre> <p> @@ -6042,7 +6041,7 @@ process-related functions in the standard library <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p> -<span class="apii">[-0, +(1|3), <em>m</em>]</span> +<span class="apii">[-0, +(1|3), <em>e</em>]</span> <pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre> <p> @@ -6055,7 +6054,7 @@ file-related functions in the standard library <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p> -<span class="apii">[-0, +(0|1), <em>m</em>]</span> +<span class="apii">[-0, +(0|1), <em>e</em>]</span> <pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre> <p> @@ -6082,7 +6081,7 @@ in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code> <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre> <p> @@ -6098,7 +6097,7 @@ and false if it creates a new table. <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>const char *luaL_gsub (lua_State *L, const char *s, const char *p, @@ -6168,7 +6167,7 @@ The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_ <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_loadfile (lua_State *L, const char *filename);</pre> <p> @@ -6179,7 +6178,7 @@ Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <co <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_loadfilex (lua_State *L, const char *filename, const char *mode);</pre> @@ -6233,7 +6232,7 @@ it does not run it. <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_newlib (lua_State *L, const luaL_Reg *l);</pre> <p> @@ -6249,7 +6248,7 @@ It is implemented as the following macro: <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre> <p> @@ -6270,7 +6269,7 @@ not a pointer to it. <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre> <p> @@ -6442,7 +6441,7 @@ Otherwise, raises an error. <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre> <p> @@ -6454,7 +6453,7 @@ with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</co <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p> -<span class="apii">[-?, +?, <em>m</em>]</span> +<span class="apii">[-?, +?, <em>e</em>]</span> <pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre> <p> @@ -6470,7 +6469,7 @@ it to the buffer. <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p> -<span class="apii">[-?, +1, <em>m</em>]</span> +<span class="apii">[-?, +1, <em>e</em>]</span> <pre>void luaL_pushresult (luaL_Buffer *B);</pre> <p> @@ -6482,7 +6481,7 @@ the top of the stack. <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p> -<span class="apii">[-?, +1, <em>m</em>]</span> +<span class="apii">[-?, +1, <em>e</em>]</span> <pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre> <p> @@ -6493,7 +6492,7 @@ Equivalent to the sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a> <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p> -<span class="apii">[-1, +0, <em>m</em>]</span> +<span class="apii">[-1, +0, <em>e</em>]</span> <pre>int luaL_ref (lua_State *L, int t);</pre> <p> @@ -6597,7 +6596,7 @@ in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code> <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p> -<span class="apii">[-0, +0, <em>m</em>]</span> +<span class="apii">[-0, +0, <em>e</em>]</span> <pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre> <p> @@ -6633,7 +6632,7 @@ and uses the result of the call as its result. <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level);</pre> @@ -6680,7 +6679,7 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p> -<span class="apii">[-0, +1, <em>m</em>]</span> +<span class="apii">[-0, +1, <em>e</em>]</span> <pre>void luaL_where (lua_State *L, int lvl);</pre> <p> @@ -10407,7 +10406,7 @@ Here is the complete syntax of Lua in extended BNF. <HR> <SMALL CLASS="footer"> Last update: -Wed May 23 13:28:41 BRT 2012 +Fri Jun 1 12:38:38 BRT 2012 </SMALL> <!-- Last change: revised for Lua 5.2.1 diff --git a/doc/readme.html b/doc/readme.html index 7bd1829d..2ff294ec 100644 --- a/doc/readme.html +++ b/doc/readme.html @@ -43,7 +43,6 @@ Welcome to Lua 5.2 <A HREF="#license">license</A> · <A HREF="contents.html">reference manual</A> -<HR> <H2><A NAME="about">About Lua</A></H2> @@ -401,7 +400,7 @@ THE SOFTWARE. <HR> <SMALL CLASS="footer"> Last update: -Thu May 17 11:09:49 BRT 2012 +Tue May 29 21:57:51 BRT 2012 </SMALL> <!-- Last change: revised for Lua 5.2.1 diff --git a/src/lauxlib.c b/src/lauxlib.c index 24d4abb2..36ae7e62 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.243 2012/04/20 17:05:17 roberto Exp $ +** $Id: lauxlib.c,v 1.244 2012/05/31 20:28:45 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -520,11 +520,11 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { LUALIB_API int luaL_ref (lua_State *L, int t) { int ref; - t = lua_absindex(L, t); if (lua_isnil(L, -1)) { lua_pop(L, 1); /* remove from stack */ return LUA_REFNIL; /* `nil' has a unique fixed reference */ } + t = lua_absindex(L, t); lua_rawgeti(L, t, freelist); /* get first free element */ ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ lua_pop(L, 1); /* remove it from stack */ @@ -866,8 +866,8 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { lua_getfield(L, idx, fname); if (lua_istable(L, -1)) return 1; /* table already there */ else { - idx = lua_absindex(L, idx); lua_pop(L, 1); /* remove previous result */ + idx = lua_absindex(L, idx); lua_newtable(L); lua_pushvalue(L, -1); /* copy to be left at top */ lua_setfield(L, idx, fname); /* assign new table to field */ @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.129 2012/05/28 20:41:00 roberto Exp $ +** $Id: lgc.c,v 2.133 2012/05/31 21:28:59 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -753,6 +753,21 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { return (*p == NULL) ? NULL : p; } + +/* +** sweep a list until a live object (or end of list) +*/ +static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) { + GCObject ** old = p; + int i = 0; + do { + i++; + p = sweeplist(L, p, 1); + } while (p == old); + if (n) *n += i; + return p; +} + /* }====================================================== */ @@ -812,12 +827,14 @@ static void GCTM (lua_State *L, int propagateerrors) { L->allowhook = oldah; /* restore hooks */ g->gcrunning = running; /* restore state */ if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ - if (status == LUA_ERRRUN) { /* is there an error msg.? */ - luaO_pushfstring(L, "error in __gc metamethod (%s)", - lua_tostring(L, -1)); + if (status == LUA_ERRRUN) { /* is there an error object? */ + const char *msg = (ttisstring(L->top - 1)) + ? svalue(L->top - 1) + : "no message"; + luaO_pushfstring(L, "error in __gc metamethod (%s)", msg); status = LUA_ERRGCMM; /* error in __gc metamethod */ } - luaD_throw(L, status); /* re-send error */ + luaD_throw(L, status); /* re-throw error */ } } } @@ -864,10 +881,9 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { else { /* move 'o' to 'finobj' list */ GCObject **p; GCheader *ho = gch(o); - /* avoid removing current sweep object */ - if (g->sweepgc == &ho->next) { - /* step to next object in the list */ - g->sweepgc = (ho->next == NULL) ? NULL : &gch(ho->next)->next; + if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */ + lua_assert(issweepphase(g)); + g->sweepgc = sweeptolive(L, g->sweepgc, NULL); } /* search for pointer pointing to 'o' */ for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } @@ -875,7 +891,10 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { ho->next = g->finobj; /* link it in list 'finobj' */ g->finobj = o; l_setbit(ho->marked, SEPARATED); /* mark it as such */ - resetoldbit(o); /* see MOVE OLD rule */ + if (!keepinvariant(g)) /* not keeping invariant? */ + makewhite(g, o); /* "sweep" object */ + else + resetoldbit(o); /* see MOVE OLD rule */ } } @@ -895,18 +914,22 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { /* ** enter first sweep phase (strings) and prepare pointers for other -** sweep phases. The calls to 'sweeplist' attempt to make pointers -** point to an object inside the list (instead of to the header), so -** that the real sweep do not need to skip objects created between "now" -** and the start of the real sweep. +** sweep phases. The calls to 'sweeptolive' make pointers point to an +** object inside the list (instead of to the header), so that the real +** sweep do not need to skip objects created between "now" and the start +** of the real sweep. +** Returns how many objects it sweeped. */ -static void entersweep (lua_State *L) { +static int entersweep (lua_State *L) { global_State *g = G(L); + int n = 0; g->gcstate = GCSsweepstring; lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); - g->sweepstrgc = 0; /* prepare to sweep strings, ... */ - g->sweepfin = sweeplist(L, &g->finobj, 1); /* finalizable objects, ... */ - g->sweepgc = sweeplist(L, &g->allgc, 1); /* and regular objects */ + /* prepare to sweep strings, finalizable objects, and regular objects */ + g->sweepstrgc = 0; + g->sweepfin = sweeptolive(L, &g->finobj, &n); + g->sweepgc = sweeptolive(L, &g->allgc, &n); + return n; } @@ -962,7 +985,7 @@ void luaC_freeallobjects (lua_State *L) { static l_mem atomic (lua_State *L) { global_State *g = G(L); - l_mem trav = g->GCmemtrav; + l_mem work = -g->GCmemtrav; /* start counting work */ GCObject *origweak, *origall; lua_assert(!iswhite(obj2gco(g->mainthread))); markobject(g, L); /* mark running thread */ @@ -971,18 +994,22 @@ static l_mem atomic (lua_State *L) { markmt(g); /* mark basic metatables */ /* remark occasional upvalues of (maybe) dead threads */ remarkupvals(g); + propagateall(g); /* propagate changes */ + work += g->GCmemtrav; /* stop counting (do not (re)count grays) */ /* traverse objects caught by write barrier and by 'remarkupvals' */ retraversegrays(g); + work -= g->GCmemtrav; /* restart counting */ convergeephemerons(g); /* at this point, all strongly accessible objects are marked. */ /* clear values from weak tables, before checking finalizers */ clearvalues(g, g->weak, NULL); clearvalues(g, g->allweak, NULL); origweak = g->weak; origall = g->allweak; + work += g->GCmemtrav; /* stop counting (objects being finalized) */ separatetobefnz(L, 0); /* separate objects to be finalized */ - markbeingfnz(g); /* mark userdata that will be finalized */ + markbeingfnz(g); /* mark objects that will be finalized */ propagateall(g); /* remark, to propagate `preserveness' */ - trav = g->GCmemtrav - trav; /* avoid adding convergence twice */ + work -= g->GCmemtrav; /* restart counting */ convergeephemerons(g); /* at this point, all resurrected objects are marked. */ /* remove dead objects from weak tables */ @@ -992,9 +1019,8 @@ static l_mem atomic (lua_State *L) { clearvalues(g, g->weak, origweak); clearvalues(g, g->allweak, origall); g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ - entersweep(L); /* prepare to sweep strings */ - /*lua_checkmemory(L);*/ - return trav; /* reasonable estimate of the work done by 'atomic' */ + work += g->GCmemtrav; /* complete counting */ + return work; /* estimate of memory marked by 'atomic' */ } @@ -1018,9 +1044,14 @@ static lu_mem singlestep (lua_State *L) { return g->GCmemtrav - oldtrav; /* memory traversed in this step */ } else { /* no more `gray' objects */ + lu_mem work; + int sw; g->gcstate = GCSatomic; /* finish mark phase */ - g->GCestimate = g->GCmemtrav; /* save what was counted */ - return atomic(L); + g->GCestimate = g->GCmemtrav; /* save what was counted */; + work = atomic(L); /* add what was traversed by 'atomic' */ + g->GCestimate += work; /* estimate of total memory traversed */ + sw = entersweep(L); + return work + sw * GCSWEEPCOST; } } case GCSsweepstring: { @@ -1089,7 +1120,7 @@ static void generationalcollection (lua_State *L) { } -static void step (lua_State *L) { +static void incstep (lua_State *L) { global_State *g = G(L); l_mem debt = g->GCdebt; int stepmul = g->gcstepmul; @@ -1116,7 +1147,7 @@ void luaC_forcestep (lua_State *L) { global_State *g = G(L); int i; if (isgenerational(g)) generationalcollection(L); - else step(L); + else incstep(L); /* run a few finalizers (or all of them at the end of a collect cycle) */ for (i = 0; g->tobefnz && (i < GCFINALIZENUM || g->gcstate == GCSpause); i++) GCTM(L, 1); /* call one finalizer */ diff --git a/src/loadlib.c b/src/loadlib.c index ea332f44..a9959277 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.110 2012/04/26 19:38:52 roberto Exp $ +** $Id: loadlib.c,v 1.111 2012/05/30 12:33:44 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -482,9 +482,9 @@ static void findloader (lua_State *L, const char *name) { lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */ if (!lua_istable(L, 3)) luaL_error(L, LUA_QL("package.searchers") " must be a table"); - /* iterate over available seachers to find a loader */ + /* iterate over available searchers to find a loader */ for (i = 1; ; i++) { - lua_rawgeti(L, 3, i); /* get a seacher */ + lua_rawgeti(L, 3, i); /* get a searcher */ if (lua_isnil(L, -1)) { /* no more searchers? */ lua_pop(L, 1); /* remove nil */ luaL_pushresult(&msg); /* create error message */ diff --git a/src/lstate.c b/src/lstate.c index 1a165003..3c00c285 100644 --- a/src/lstate.c +++ b/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.97 2012/05/23 15:37:09 roberto Exp $ +** $Id: lstate.c,v 2.98 2012/05/30 12:33:44 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -79,7 +79,7 @@ typedef struct LG { /* ** Compute an initial seed as random as possible. In ANSI, rely on -** Address Space Layour Randomization (if present) to increase +** Address Space Layout Randomization (if present) to increase ** randomness.. */ #define addbuff(b,p,e) \ |