diff options
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/contents.html | 3 | ||||
-rw-r--r-- | doc/manual.html | 76 | ||||
-rw-r--r-- | src/lapi.c | 6 | ||||
-rw-r--r-- | src/lauxlib.c | 37 | ||||
-rw-r--r-- | src/lauxlib.h | 8 | ||||
-rw-r--r-- | src/lbaselib.c | 35 | ||||
-rw-r--r-- | src/ldo.c | 29 | ||||
-rw-r--r-- | src/ldo.h | 5 | ||||
-rw-r--r-- | src/lgc.c | 18 | ||||
-rw-r--r-- | src/llimits.h | 4 | ||||
-rw-r--r-- | src/loadlib.c | 4 | ||||
-rw-r--r-- | src/loslib.c | 28 | ||||
-rw-r--r-- | src/ltable.c | 6 | ||||
-rw-r--r-- | src/ltablib.c | 5 | ||||
-rw-r--r-- | src/lua.h | 5 | ||||
-rw-r--r-- | src/luac.c | 4 | ||||
-rw-r--r-- | src/luaconf.h | 3 | ||||
-rw-r--r-- | src/lvm.c | 9 |
19 files changed, 158 insertions, 129 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.2, released on 24 Nov 2011. +This is Lua 5.2, released on 29 Nov 2011. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/contents.html b/doc/contents.html index 9f7043d4..5342723f 100644 --- a/doc/contents.html +++ b/doc/contents.html @@ -483,6 +483,7 @@ Freely available under the terms of the <A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR> <A HREF="manual.html#luaL_len">luaL_len</A><BR> <A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR> +<A HREF="manual.html#luaL_loadbufferx">luaL_loadbufferx</A><BR> <A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR> <A HREF="manual.html#luaL_loadfilex">luaL_loadfilex</A><BR> <A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR> @@ -520,7 +521,7 @@ Freely available under the terms of the <HR> <SMALL CLASS="footer"> Last update: -Wed Nov 23 16:14:28 BRST 2011 +Tue Nov 29 22:30:23 BRST 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 diff --git a/doc/manual.html b/doc/manual.html index 8b3a85e5..90bb0fc8 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.89 2011/11/25 12:59:54 roberto Exp $ --> +<!-- $Id: manual.of,v 1.90 2011/11/29 17:14:45 roberto Exp $ --> @@ -3659,15 +3659,19 @@ The result is pushed on the stack. <pre>int lua_load (lua_State *L, lua_Reader reader, void *data, - const char *source);</pre> + const char *source, + const char *mode);</pre> <p> -Loads a Lua chunk. +Loads a Lua chunk (without running it). If there are no errors, -<a href="#lua_load"><code>lua_load</code></a> pushes the compiled chunk as a Lua +<code>lua_load</code> pushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message. -The return values of <a href="#lua_load"><code>lua_load</code></a> are: + + +<p> +The return values of <code>lua_load</code> are: <ul> @@ -3688,17 +3692,7 @@ It is generated by the garbage collector.) </ul> <p> -This function only loads a chunk; -it does not run it. - - -<p> -<a href="#lua_load"><code>lua_load</code></a> automatically detects whether the chunk is text or binary -and loads it accordingly (see program <code>luac</code>). - - -<p> -The <a href="#lua_load"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function +The <code>lua_load</code> function uses a user-supplied <code>reader</code> function to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>). The <code>data</code> argument is an opaque value passed to the reader function. @@ -3709,6 +3703,14 @@ which is used for error messages and in debug information (see <a href="#4.9">&s <p> +id{lua_load} automatically detects whether the chunk is text or binary +and loads it accordingly (see program <code>luac</code>). +The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>, +with the addition that +a <code>NULL</code> value is equivalent to the string "<code>bt</code>". + + +<p> If the resulting function has one upvalue, this upvalue is set to the value of the global environment stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">§4.5</a>). @@ -6119,6 +6121,21 @@ Raises an error if the result of the operation is not a number. const char *name);</pre> <p> +Equivalent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>. + + + + + +<hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p> +<span class="apii">[-0, +1, –]</span> +<pre>int luaL_loadbufferx (lua_State *L, + const char *buff, + size_t sz, + const char *name, + const char *mode);</pre> + +<p> Loads a buffer as a Lua chunk. This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the buffer pointed to by <code>buff</code> with size <code>sz</code>. @@ -6128,6 +6145,7 @@ buffer pointed to by <code>buff</code> with size <code>sz</code>. This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>. <code>name</code> is the chunk name, used for debug information and error messages. +The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>. @@ -6135,12 +6153,15 @@ used for debug information and error messages. <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p> <span class="apii">[-0, +1, <em>m</em>]</span> -<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre><p> +<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre> + +<p> Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>. + <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p> <span class="apii">[-0, +1, <em>m</em>]</span> <pre>int luaL_loadfilex (lua_State *L, const char *filename, @@ -6156,9 +6177,7 @@ The first line in the file is ignored if it starts with a <code>#</code>. <p> -The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>, -with the addition that -a <code>NULL</code> value is equivalent to the string "<code>bt</code>". +The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>. <p> @@ -8292,7 +8311,6 @@ of list <code>t</code>. <p> Returns a new table with all parameters stored into keys 1, 2, etc. and with a field "<code>n</code>" with the total number of parameters. -Also returns, as a second result, the total number of parameters. Note that the resulting table may not be a sequence. @@ -9376,6 +9394,11 @@ the host system and on the current locale (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>). +<p> +On some systems, +this function may be not thread safe. + + <p> @@ -10184,8 +10207,8 @@ are potentially insecure when loading untrusted binary data. (Actually, those functions were already insecure because of flaws in the verification algorithm.) When in doubt, -use the <code>mode</code> argument in function <a href="#pdf-load"><code>load</code></a> -to restrict it to loading textual chunks. +use the <code>mode</code> argument of those functions +to restrict them to loading textual chunks. </li> <li> @@ -10260,6 +10283,11 @@ Use the new <a href="#lua_compare"><code>lua_compare</code></a> with appropriate Function <code>lua_objlen</code> was renamed <a href="#lua_rawlen"><code>lua_rawlen</code></a>. </li> +<li> +Function <a href="#lua_load"><code>lua_load</code></a> has an extra parameter, <code>mode</code>. +Pass <code>NULL</code> to simulate the old behavior. +</li> + </ul> @@ -10352,7 +10380,7 @@ Here is the complete syntax of Lua in extended BNF. <HR> <SMALL CLASS="footer"> Last update: -Fri Nov 25 11:37:49 BRST 2011 +Tue Nov 29 15:37:33 BRST 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.157 2011/11/16 18:51:36 roberto Exp $ +** $Id: lapi.c,v 2.158 2011/11/29 15:55:08 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -968,13 +968,13 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, - const char *chunkname) { + const char *chunkname, const char *mode) { ZIO z; int status; lua_lock(L); if (!chunkname) chunkname = "?"; luaZ_init(L, &z, reader, data); - status = luaD_protectedparser(L, &z, chunkname); + status = luaD_protectedparser(L, &z, chunkname, mode); if (status == LUA_OK) { /* no errors? */ LClosure *f = clLvalue(L->top - 1); /* get newly created function */ if (f->nupvalues == 1) { /* does it have one upvalue? */ diff --git a/src/lauxlib.c b/src/lauxlib.c index d61a8ef8..15730b69 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.236 2011/11/14 17:10:24 roberto Exp $ +** $Id: lauxlib.c,v 1.237 2011/11/29 15:55:08 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -592,16 +592,6 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { } -static int checkmode (lua_State *L, const char *mode, const char *x) { - if (mode && strchr(mode, x[0]) == NULL) { - lua_pushfstring(L, - "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); - return LUA_ERRFILE; - } - else return LUA_OK; -} - - static int skipBOM (LoadF *lf) { const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */ int c; @@ -651,23 +641,14 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, } if (skipcomment(&lf, &c)) /* read initial portion */ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ - if (c == LUA_SIGNATURE[0]) { /* binary file? */ - if ((status = checkmode(L, mode, "binary")) != LUA_OK) - goto closefile; - if (filename) { - lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ - if (lf.f == NULL) return errfile(L, "reopen", fnameindex); - skipcomment(&lf, &c); /* re-read initial portion */ - } - } - else { /* text file */ - if ((status = checkmode(L, mode, "text")) != LUA_OK) - goto closefile; + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + skipcomment(&lf, &c); /* re-read initial portion */ } if (c != EOF) lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ - status = lua_load(L, getF, &lf, lua_tostring(L, -1)); - closefile: + status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); readstatus = ferror(lf.f); if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { @@ -695,12 +676,12 @@ static const char *getS (lua_State *L, void *ud, size_t *size) { } -LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, - const char *name) { +LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, + const char *name, const char *mode) { LoadS ls; ls.s = buff; ls.size = size; - return lua_load(L, getS, &ls, name); + return lua_load(L, getS, &ls, name, mode); } diff --git a/src/lauxlib.h b/src/lauxlib.h index 48b1afa0..ac4d15fb 100644 --- a/src/lauxlib.h +++ b/src/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.119 2011/11/14 17:10:24 roberto Exp $ +** $Id: lauxlib.h,v 1.120 2011/11/29 15:55:08 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -77,8 +77,8 @@ LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) -LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, - const char *name); +LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, + const char *name, const char *mode); LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); LUALIB_API lua_State *(luaL_newstate) (void); @@ -131,6 +131,8 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) +#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) + /* ** {====================================================== diff --git a/src/lbaselib.c b/src/lbaselib.c index 472a96c8..5db05e21 100644 --- a/src/lbaselib.c +++ b/src/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.270 2011/11/23 17:29:04 roberto Exp $ +** $Id: lbaselib.c,v 1.271 2011/11/29 15:55:08 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -273,25 +273,6 @@ static int luaB_loadfile (lua_State *L) { */ -typedef struct { - const char *mode; -} loaddata; - - -/* -** check whether a chunk (prefix in 's') satisfies given 'mode' -** ('t' for text, 'b' for binary). Returns error message (also -** pushed on the stack) in case of errors. -*/ -static const char *checkrights (lua_State *L, const char *mode, const char *s) { - const char *x = (*s == LUA_SIGNATURE[0]) ? "binary" : "text"; - if (strchr(mode, x[0]) == NULL) - return lua_pushfstring(L, - "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); - else return NULL; -} - - /* ** reserved slot, above all arguments, to hold a copy of the returned ** string to avoid it being collected while parsed. 'load' has four @@ -308,7 +289,7 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) { */ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { const char *s; - loaddata *ld = (loaddata *)ud; + (void)(ud); /* not used */ luaL_checkstack(L, 2, "too many nested functions"); lua_pushvalue(L, 1); /* get function */ lua_call(L, 0, 1); /* call it */ @@ -317,11 +298,6 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { return NULL; } else if ((s = lua_tostring(L, -1)) != NULL) { - if (ld->mode != NULL) { /* first time? */ - s = checkrights(L, ld->mode, s); /* check mode */ - ld->mode = NULL; /* to avoid further checks */ - if (s) luaL_error(L, s); - } lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ return lua_tolstring(L, RESERVEDSLOT, size); } @@ -340,16 +316,13 @@ static int luaB_load (lua_State *L) { const char *mode = luaL_optstring(L, 3, "bt"); if (s != NULL) { /* loading a string? */ const char *chunkname = luaL_optstring(L, 2, s); - status = (checkrights(L, mode, s) != NULL) - || luaL_loadbuffer(L, s, l, chunkname); + status = luaL_loadbufferx(L, s, l, chunkname, mode); } else { /* loading from a reader function */ const char *chunkname = luaL_optstring(L, 2, "=(load)"); - loaddata ld; - ld.mode = mode; luaL_checktype(L, 1, LUA_TFUNCTION); lua_settop(L, RESERVEDSLOT); /* create reserved slot */ - status = lua_load(L, generic_reader, &ld, chunkname); + status = lua_load(L, generic_reader, NULL, chunkname, mode); } if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */ lua_pushvalue(L, 4); /* environment for loaded function */ @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.101 2011/10/07 20:45:19 roberto Exp $ +** $Id: ldo.c,v 2.102 2011/11/29 15:55:08 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -611,18 +611,34 @@ struct SParser { /* data to `f_parser' */ ZIO *z; Mbuffer buff; /* dynamic structure used by the scanner */ Dyndata dyd; /* dynamic structures used by the parser */ + const char *mode; const char *name; }; + +static void checkmode (lua_State *L, const char *mode, const char *x) { + if (mode && strchr(mode, x[0]) == NULL) { + luaO_pushfstring(L, + "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); + luaD_throw(L, LUA_ERRSYNTAX); + } +} + + static void f_parser (lua_State *L, void *ud) { int i; Proto *tf; Closure *cl; struct SParser *p = cast(struct SParser *, ud); int c = zgetc(p->z); /* read first character */ - tf = (c == LUA_SIGNATURE[0]) - ? luaU_undump(L, p->z, &p->buff, p->name) - : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); + if (c == LUA_SIGNATURE[0]) { + checkmode(L, p->mode, "binary"); + tf = luaU_undump(L, p->z, &p->buff, p->name); + } + else { + checkmode(L, p->mode, "text"); + tf = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); + } setptvalue2s(L, L->top, tf); incr_top(L); cl = luaF_newLclosure(L, tf); @@ -632,11 +648,12 @@ static void f_parser (lua_State *L, void *ud) { } -int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, + const char *mode) { struct SParser p; int status; L->nny++; /* cannot yield during parsing */ - p.z = z; p.name = name; + p.z = z; p.name = name; p.mode = mode; p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; p.dyd.label.arr = NULL; p.dyd.label.size = 0; @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 2.19 2011/10/07 20:45:19 roberto Exp $ +** $Id: ldo.h,v 2.20 2011/11/29 15:55:08 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -26,7 +26,8 @@ /* type of protected functions, to be ran by `runprotected' */ typedef void (*Pfunc) (lua_State *L, void *ud); -LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, + const char *mode); LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.114 2011/10/03 17:54:25 roberto Exp $ +** $Id: lgc.c,v 2.115 2011/11/28 17:25:48 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -94,6 +94,12 @@ static void reallymarkobject (global_State *g, GCObject *o); /* +** one after last element in a hash array +*/ +#define gnodelast(h) gnode(h, cast(size_t, sizenode(h))) + + +/* ** link table 'h' into list pointed by 'p' */ #define linktable(h,p) ((h)->gclist = *(p), *(p) = obj2gco(h)) @@ -342,7 +348,7 @@ static void markroot (global_State *g) { */ static void traverseweakvalue (global_State *g, Table *h) { - Node *n, *limit = gnode(h, sizenode(h)); + Node *n, *limit = gnodelast(h); /* if there is array part, assume it may have white values (do not traverse it just to check) */ int hasclears = (h->sizearray > 0); @@ -368,7 +374,7 @@ static int traverseephemeron (global_State *g, Table *h) { int marked = 0; /* true if an object is marked in this traversal */ int hasclears = 0; /* true if table has white keys */ int prop = 0; /* true if table has entry "white-key -> white-value" */ - Node *n, *limit = gnode(h, sizenode(h)); + Node *n, *limit = gnodelast(h); int i; /* traverse array part (numeric keys are 'strong') */ for (i = 0; i < h->sizearray; i++) { @@ -403,7 +409,7 @@ static int traverseephemeron (global_State *g, Table *h) { static void traversestrongtable (global_State *g, Table *h) { - Node *n, *limit = gnode(h, sizenode(h)); + Node *n, *limit = gnodelast(h); int i; for (i = 0; i < h->sizearray; i++) /* traverse array part */ markvalue(g, &h->array[i]); @@ -596,7 +602,7 @@ static void convergeephemerons (global_State *g) { static void clearkeys (GCObject *l, GCObject *f) { for (; l != f; l = gco2t(l)->gclist) { Table *h = gco2t(l); - Node *n, *limit = gnode(h, sizenode(h)); + Node *n, *limit = gnodelast(h); for (n = gnode(h, 0); n < limit; n++) { if (!ttisnil(gval(n)) && (iscleared(gkey(n)))) { setnilvalue(gval(n)); /* remove value ... */ @@ -614,7 +620,7 @@ static void clearkeys (GCObject *l, GCObject *f) { static void clearvalues (GCObject *l, GCObject *f) { for (; l != f; l = gco2t(l)->gclist) { Table *h = gco2t(l); - Node *n, *limit = gnode(h, sizenode(h)); + Node *n, *limit = gnodelast(h); int i; for (i = 0; i < h->sizearray; i++) { TValue *o = &h->array[i]; diff --git a/src/llimits.h b/src/llimits.h index 17293ca0..ec2ca896 100644 --- a/src/llimits.h +++ b/src/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.93 2011/10/07 20:45:19 roberto Exp $ +** $Id: llimits.h,v 1.94 2011/11/29 15:39:48 roberto Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ @@ -228,7 +228,7 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; #define luai_hashnum(i,n) \ { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \ - (i) = u.l_p[0] + u.l_p[1]; } /* add double bits for his hash */ + (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */ #define lua_number2int(i,n) lua_number2int32(i, n, int) #define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer) diff --git a/src/loadlib.c b/src/loadlib.c index 28fda6e5..158fb0e3 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.105 2011/11/25 12:52:03 roberto Exp $ +** $Id: loadlib.c,v 1.106 2011/11/28 17:27:51 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -132,7 +132,7 @@ static void ll_unloadlib (void *lib) { static void *ll_load (lua_State *L, const char *path, int seeglb) { - void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : 0)); + void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL)); if (lib == NULL) lua_pushstring(L, dlerror()); return lib; } diff --git a/src/loslib.c b/src/loslib.c index 585ba781..69d33e3a 100644 --- a/src/loslib.c +++ b/src/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.35 2011/06/20 16:50:59 roberto Exp $ +** $Id: loslib.c,v 1.37 2011/11/29 17:15:42 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -58,6 +58,23 @@ #endif +/* +** By default, Lua uses gmtime/localtime, except when POSIX is available, +** where it uses gmtime_r/localtime_r +*/ +#if defined(lUA_USE_GMTIME_R) + +#define l_gmtime(t,r) gmtime_r(t,r) +#define l_localtime(t,r) localtime_r(t,r) + +#elif !defined(l_gmtime) + +#define l_gmtime(t,r) ((void)r, gmtime(t)) +#define l_localtime(t,r) ((void)r, localtime(t)) + +#endif + + static int os_execute (lua_State *L) { const char *cmd = luaL_optstring(L, 1, NULL); @@ -177,13 +194,13 @@ static const char *checkoption (lua_State *L, const char *conv, char *buff) { static int os_date (lua_State *L) { const char *s = luaL_optstring(L, 1, "%c"); time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); - struct tm *stm; + struct tm tmr, *stm; if (*s == '!') { /* UTC? */ - stm = gmtime(&t); + stm = l_gmtime(&t, &tmr); s++; /* skip `!' */ } else - stm = localtime(&t); + stm = l_localtime(&t, &tmr); if (stm == NULL) /* invalid date? */ lua_pushnil(L); else if (strcmp(s, "*t") == 0) { @@ -274,7 +291,8 @@ static int os_exit (lua_State *L) { status = luaL_optint(L, 1, EXIT_SUCCESS); if (lua_toboolean(L, 2)) lua_close(L); - exit(status); + if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */ + return 0; } diff --git a/src/ltable.c b/src/ltable.c index d96d2558..b4aa26c0 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.65 2011/09/30 12:45:27 roberto Exp $ +** $Id: ltable.c,v 2.66 2011/11/28 17:25:48 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -322,7 +322,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { } } if (!isdummy(nold)) - luaM_freearray(L, nold, twoto(oldhsize)); /* free old array */ + luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */ } @@ -370,7 +370,7 @@ Table *luaH_new (lua_State *L) { void luaH_free (lua_State *L, Table *t) { if (!isdummy(t->node)) - luaM_freearray(L, t->node, sizenode(t)); + luaM_freearray(L, t->node, cast(size_t, sizenode(t))); luaM_freearray(L, t->array, t->sizearray); luaM_free(L, t); } diff --git a/src/ltablib.c b/src/ltablib.c index 5c3abc35..a52add03 100644 --- a/src/ltablib.c +++ b/src/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.62 2011/09/30 12:45:45 roberto Exp $ +** $Id: ltablib.c,v 1.63 2011/11/28 17:26:30 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -129,8 +129,7 @@ static int pack (lua_State *L) { for (i = n; i >= 2; i--) /* assign other elements */ lua_rawseti(L, 1, i); } - lua_pushinteger(L, n); - return 2; /* return table and number of elements */ + return 1; /* return table */ } @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.281 2011/10/24 16:53:05 roberto Exp $ +** $Id: lua.h,v 1.282 2011/11/29 15:55:08 roberto Exp $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -254,7 +254,8 @@ LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, - const char *chunkname); + const char *chunkname, + const char *mode); LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); @@ -1,5 +1,5 @@ /* -** $Id: luac.c,v 1.68 2011/11/23 17:48:18 lhf Exp $ +** $Id: luac.c,v 1.69 2011/11/29 17:46:33 lhf Exp $ ** Lua compiler (saves bytecodes to files; also list bytecodes) ** See Copyright Notice in lua.h */ @@ -141,7 +141,7 @@ static const Proto* combine(lua_State* L, int n) { Proto* f; int i=n; - if (lua_load(L,reader,&i,"=(" PROGNAME ")")!=LUA_OK) fatal(lua_tostring(L,-1)); + if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1)); f=toproto(L,-1); for (i=0; i<n; i++) { diff --git a/src/luaconf.h b/src/luaconf.h index 5cdb7b7b..5417bc61 100644 --- a/src/luaconf.h +++ b/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.167 2011/11/25 12:52:27 roberto Exp $ +** $Id: luaconf.h,v 1.168 2011/11/29 17:15:42 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -70,6 +70,7 @@ #define LUA_USE_ISATTY #define LUA_USE_POPEN #define LUA_USE_ULONGJMP +#define lUA_USE_GMTIME_R #endif @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.144 2011/10/07 20:45:19 roberto Exp $ +** $Id: lvm.c,v 2.146 2011/11/29 15:54:38 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -515,6 +515,7 @@ void luaV_finishOp (lua_State *L) { #define vmdispatch(o) switch(o) #define vmcase(l,b) case l: {b} break; +#define vmcasenb(l,b) case l: {b} /* nb = no break */ void luaV_execute (lua_State *L) { CallInfo *ci = L->ci; @@ -534,7 +535,7 @@ void luaV_execute (lua_State *L) { (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { Protect(traceexec(L)); } - /* warning!! several calls may realloc the stack and invalidate `ra' */ + /* WARNING: several calls may realloc the stack and invalidate `ra' */ ra = RA(i); lua_assert(base == ci->u.l.base); lua_assert(base <= L->top && L->top < L->stack + L->stacksize); @@ -741,7 +742,7 @@ void luaV_execute (lua_State *L) { goto newframe; /* restart luaV_execute over new Lua function */ } ) - vmcase(OP_RETURN, + vmcasenb(OP_RETURN, int b = GETARG_B(i); if (b != 0) L->top = ra+b-1; if (cl->p->sizep > 0) luaF_close(L, base); @@ -780,7 +781,7 @@ void luaV_execute (lua_State *L) { setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep))); ci->u.l.savedpc += GETARG_sBx(i); ) - vmcase(OP_TFORCALL, + vmcasenb(OP_TFORCALL, StkId cb = ra + 3; /* call base */ setobjs2s(L, cb+2, ra+2); setobjs2s(L, cb+1, ra+1); |