MODLANG-87 - Update to lua 5.1.4 release

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10100 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-10-21 19:39:57 +00:00
parent 350fca115f
commit 38dc44dc84
10 changed files with 81 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.55.1.3 2008/01/03 15:20:39 roberto Exp $ ** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -93,15 +93,14 @@ void luaA_pushobject (lua_State *L, const TValue *o) {
LUA_API int lua_checkstack (lua_State *L, int size) { LUA_API int lua_checkstack (lua_State *L, int size) {
int res; int res = 1;
lua_lock(L); lua_lock(L);
if ((L->top - L->base + size) > LUAI_MAXCSTACK) if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
res = 0; /* stack overflow */ res = 0; /* stack overflow */
else { else if (size > 0) {
luaD_checkstack(L, size); luaD_checkstack(L, size);
if (L->ci->top < L->top + size) if (L->ci->top < L->top + size)
L->ci->top = L->top + size; L->ci->top = L->top + size;
res = 1;
} }
lua_unlock(L); lua_unlock(L);
return res; return res;
@ -930,12 +929,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
g->GCthreshold = g->totalbytes - a; g->GCthreshold = g->totalbytes - a;
else else
g->GCthreshold = 0; g->GCthreshold = 0;
while (g->GCthreshold <= g->totalbytes) while (g->GCthreshold <= g->totalbytes) {
luaC_step(L); luaC_step(L);
if (g->gcstate == GCSpause) /* end of cycle? */ if (g->gcstate == GCSpause) { /* end of cycle? */
res = 1; /* signal it */ res = 1; /* signal it */
break; break;
} }
}
break;
}
case LUA_GCSETPAUSE: { case LUA_GCSETPAUSE: {
res = g->gcpause; res = g->gcpause;
g->gcpause = data; g->gcpause = data;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.191.1.4 2008/01/20 13:53:22 roberto Exp $ ** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -344,10 +344,12 @@ static int luaB_unpack (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
i = luaL_optint(L, 2, 1); i = luaL_optint(L, 2, 1);
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
if (i > e) return 0; /* empty range */
n = e - i + 1; /* number of elements */ n = e - i + 1; /* number of elements */
if (n <= 0) return 0; /* empty range */ if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
luaL_checkstack(L, n, "table too big to unpack"); return luaL_error(L, "too many results to unpack");
for (; i<=e; i++) /* push arg[i...e] */ lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
while (i++ < e) /* push arg[i + 1...e] */
lua_rawgeti(L, 1, i); lua_rawgeti(L, 1, i);
return n; return n;
} }
@ -526,7 +528,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
status = lua_resume(co, narg); status = lua_resume(co, narg);
if (status == 0 || status == LUA_YIELD) { if (status == 0 || status == LUA_YIELD) {
int nres = lua_gettop(co); int nres = lua_gettop(co);
if (!lua_checkstack(L, nres)) if (!lua_checkstack(L, nres + 1))
luaL_error(L, "too many results to resume"); luaL_error(L, "too many results to resume");
lua_xmove(co, L, nres); /* move yielded values */ lua_xmove(co, L, nres); /* move yielded values */
return nres; return nres;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 2.29.1.3 2007/12/28 15:32:23 roberto Exp $ ** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -275,12 +275,12 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
static int precheck (const Proto *pt) { static int precheck (const Proto *pt) {
check(pt->maxstacksize <= MAXSTACK); check(pt->maxstacksize <= MAXSTACK);
lua_assert(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
lua_assert(!(pt->is_vararg & VARARG_NEEDSARG) || check(!(pt->is_vararg & VARARG_NEEDSARG) ||
(pt->is_vararg & VARARG_HASARG)); (pt->is_vararg & VARARG_HASARG));
check(pt->sizeupvalues <= pt->nups); check(pt->sizeupvalues <= pt->nups);
check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
return 1; return 1;
} }
@ -346,9 +346,18 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
int dest = pc+1+b; int dest = pc+1+b;
check(0 <= dest && dest < pt->sizecode); check(0 <= dest && dest < pt->sizecode);
if (dest > 0) { if (dest > 0) {
/* cannot jump to a setlist count */ int j;
Instruction d = pt->code[dest-1]; /* check that it does not jump to a setlist count; this
check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)); is tricky, because the count from a previous setlist may
have the same value of an invalid setlist; so, we must
go all the way back to the first of them (if any) */
for (j = 0; j < dest; j++) {
Instruction d = pt->code[dest-1-j];
if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
}
/* if 'j' is even, previous value is not a setlist (even if
it looks like one) */
check((j&1) == 0);
} }
} }
break; break;
@ -363,7 +372,11 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
} }
switch (op) { switch (op) {
case OP_LOADBOOL: { case OP_LOADBOOL: {
check(c == 0 || pc+2 < pt->sizecode); /* check its jump */ if (c == 1) { /* does it jump? */
check(pc+2 < pt->sizecode); /* check its jump */
check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||
GETARG_C(pt->code[pc+1]) != 0);
}
break; break;
} }
case OP_LOADNIL: { case OP_LOADNIL: {
@ -428,7 +441,10 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
} }
case OP_SETLIST: { case OP_SETLIST: {
if (b > 0) checkreg(pt, a + b); if (b > 0) checkreg(pt, a + b);
if (c == 0) pc++; if (c == 0) {
pc++;
check(pc < pt->sizecode - 1);
}
break; break;
} }
case OP_CLOSURE: { case OP_CLOSURE: {

View File

@ -1,5 +1,5 @@
/* /*
** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $ ** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $
** Dynamic library loader for Lua ** Dynamic library loader for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
** **
@ -506,8 +506,10 @@ static int ll_require (lua_State *L) {
static void setfenv (lua_State *L) { static void setfenv (lua_State *L) {
lua_Debug ar; lua_Debug ar;
lua_getstack(L, 1, &ar); if (lua_getstack(L, 1, &ar) == 0 ||
lua_getinfo(L, "f", &ar); lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
lua_iscfunction(L, -1))
luaL_error(L, LUA_QL("module") " not called from a Lua function");
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_setfenv(L, -2); lua_setfenv(L, -2);
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -208,7 +208,7 @@ typedef union TString {
#define getstr(ts) cast(const char *, (ts) + 1) #define getstr(ts) cast(const char *, (ts) + 1)
#define svalue(o) getstr(tsvalue(o)) #define svalue(o) getstr(rawtsvalue(o))

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $ ** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -35,7 +35,8 @@ static int str_len (lua_State *L) {
static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
/* relative string position: negative means back from end */ /* relative string position: negative means back from end */
return (pos>=0) ? pos : (ptrdiff_t)len+pos+1; if (pos < 0) pos += (ptrdiff_t)len + 1;
return (pos >= 0) ? pos : 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltablib.c,v 1.38.1.2 2007/12/28 15:32:23 roberto Exp $ ** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $
** Library for Table Manipulation ** Library for Table Manipulation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -132,6 +132,15 @@ static int tremove (lua_State *L) {
} }
static void addfield (lua_State *L, luaL_Buffer *b, int i) {
lua_rawgeti(L, 1, i);
if (!lua_isstring(L, -1))
luaL_error(L, "invalid value (%s) at index %d in table for "
LUA_QL("concat"), luaL_typename(L, -1), i);
luaL_addvalue(b);
}
static int tconcat (lua_State *L) { static int tconcat (lua_State *L) {
luaL_Buffer b; luaL_Buffer b;
size_t lsep; size_t lsep;
@ -141,13 +150,12 @@ static int tconcat (lua_State *L) {
i = luaL_optint(L, 3, 1); i = luaL_optint(L, 3, 1);
last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1)); last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (; i <= last; i++) { for (; i < last; i++) {
lua_rawgeti(L, 1, i); addfield(L, &b, i);
luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings");
luaL_addvalue(&b);
if (i != last)
luaL_addlstring(&b, sep, lsep); luaL_addlstring(&b, sep, lsep);
} }
if (i == last) /* add last value (if interval was not empty) */
addfield(L, &b, i);
luaL_pushresult(&b); luaL_pushresult(&b);
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.218.1.4 2008/01/03 15:41:15 roberto Exp $ ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file ** See Copyright Notice at the end of this file
@ -17,7 +17,7 @@
#define LUA_VERSION "Lua 5.1" #define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.3" #define LUA_RELEASE "Lua 5.1.4"
#define LUA_VERSION_NUM 501 #define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"

View File

@ -1,5 +1,5 @@
/* /*
** $Id: luaconf.h,v 1.82.1.6 2008/01/18 17:07:48 roberto Exp $ ** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
** Configuration file for Lua ** Configuration file for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -91,7 +91,7 @@
".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
#define LUA_CPATH_DEFAULT \ #define LUA_CPATH_DEFAULT \
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" ".\\?.dll;" ".\\?51.dll;" LUA_CDIR"?.dll;" LUA_CDIR"?51.dll;" LUA_CDIR"clibs\\?.dll;" LUA_CDIR"clibs\\?51.dll;" LUA_CDIR"loadall.dll;" LUA_CDIR"clibs\\loadall.dll"
#else #else
#define LUA_ROOT "/usr/local/" #define LUA_ROOT "/usr/local/"
@ -101,7 +101,7 @@
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
#define LUA_CPATH_DEFAULT \ #define LUA_CPATH_DEFAULT \
"./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" "./?.so;" "./lib?51.so;" LUA_CDIR"?.so;" LUA_CDIR"lib?51.so;" LUA_CDIR"loadall.so"
#endif #endif
@ -440,10 +440,10 @@
@* can use. @* can use.
** CHANGE it if you need lots of (Lua) stack space for your C ** CHANGE it if you need lots of (Lua) stack space for your C
** functions. This limit is arbitrary; its only purpose is to stop C ** functions. This limit is arbitrary; its only purpose is to stop C
** functions to consume unlimited stack space. ** functions to consume unlimited stack space. (must be smaller than
** -LUA_REGISTRYINDEX)
*/ */
#define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER)))) #define LUAI_MAXCSTACK 8000
#define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX)

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 2.7.1.2 2008/01/18 16:39:11 roberto Exp $ ** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
** load precompiled Lua chunks ** load precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -48,7 +48,6 @@ static void error(LoadState* S, const char* why)
static void LoadBlock(LoadState* S, void* b, size_t size) static void LoadBlock(LoadState* S, void* b, size_t size)
{ {
size_t r=luaZ_read(S->Z,b,size); size_t r=luaZ_read(S->Z,b,size);
UNUSED(r);
IF (r!=0, "unexpected end"); IF (r!=0, "unexpected end");
} }
@ -115,7 +114,7 @@ static void LoadConstants(LoadState* S, Proto* f)
setnilvalue(o); setnilvalue(o);
break; break;
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
setbvalue(o,LoadChar(S)); setbvalue(o,LoadChar(S)!=0);
break; break;
case LUA_TNUMBER: case LUA_TNUMBER:
setnvalue(o,LoadNumber(S)); setnvalue(o,LoadNumber(S));
@ -161,7 +160,9 @@ static void LoadDebug(LoadState* S, Proto* f)
static Proto* LoadFunction(LoadState* S, TString* p) static Proto* LoadFunction(LoadState* S, TString* p)
{ {
Proto* f=luaF_newproto(S->L); Proto* f;
if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
f=luaF_newproto(S->L);
setptvalue2s(S->L,S->L->top,f); incr_top(S->L); setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
f->source=LoadString(S); if (f->source==NULL) f->source=p; f->source=LoadString(S); if (f->source==NULL) f->source=p;
f->linedefined=LoadInt(S); f->linedefined=LoadInt(S);
@ -175,6 +176,7 @@ static Proto* LoadFunction(LoadState* S, TString* p)
LoadDebug(S,f); LoadDebug(S,f);
IF (!luaG_checkcode(f), "bad code"); IF (!luaG_checkcode(f), "bad code");
S->L->top--; S->L->top--;
S->L->nCcalls--;
return f; return f;
} }