# # # patch "lua/lapi.cc" # from [b40fccca3348e17c067e242b561bac8f695e76ba] # to [233c7eeec692e096b50a93cd9531a7788d3418fb] # # patch "lua/lapi.h" # from [e2a03294339035e7747833d64ba72a23c7212935] # to [c9ef6db904b74061af447bffae9482e5040488c0] # # patch "lua/lauxlib.cc" # from [aec1f02474cca684decfbe8b3146f1c327448344] # to [8b9200394c552623f83dcd543e919223bec6033a] # # patch "lua/lauxlib.h" # from [d4240105ac4ed1d0d040a16cc4d3a7ee25c7b246] # to [02a10281004072779e88a6689daceaf34e7cd572] # # patch "lua/lbaselib.cc" # from [2d74fd901a61936cc6c6dd6b27ce74e4cf6b27bf] # to [1b18d1b5ff9aa5f619790ca2321b603b8c820fb0] # # patch "lua/lcode.cc" # from [e6eacb14c3868e1c1ed01971a2c34f47c60c0f7e] # to [19839aefded482af7963a4d2eac183b0691db520] # # patch "lua/lcode.h" # from [dcca16be29919622475922d21c9517365143172b] # to [062429f2031f802f7211d7fd3443e34c2aa93bce] # # patch "lua/ldblib.cc" # from [3030235ffb2046498e521cc0650bb46b121d8176] # to [38debe80a0006ef4efbe6db9cd4a7805991fe3f1] # # patch "lua/ldebug.cc" # from [12397d0afadabc35c580b4031b9a1223d7efd02d] # to [39d5e3e301f18b29c641eb67280023063a99cdb8] # # patch "lua/ldebug.h" # from [989e9b1011b17b7e470c911f9828118f580edd75] # to [c99005b7cf9ccc459c186e6301a71d115adfa459] # # patch "lua/ldo.cc" # from [dfa3815380568d4ebd38d95e292c41926cf8b77b] # to [5545986bbacd2b59b4ffa691e72434fb42e8d8bc] # # patch "lua/ldo.h" # from [fb197f91ae723ebf6078a818b360ac8e405cccf8] # to [a1ccddad924343d3b38951e9e4b96d735a6faa2d] # # patch "lua/ldump.cc" # from [fe3a3e76f6656f5936928d4ca3fcb762fc253dcb] # to [2593a17ee49d7809d7a1b94a9733cb02862b5c28] # # patch "lua/lfunc.cc" # from [8bf49521d76d9fc9b948d818e027806d305976b5] # to [8442f6114be3e777b601f11848154d5423fb9068] # # patch "lua/lfunc.h" # from [a785376a53128d2dd9fb73ca77d254b4fa1109a1] # to [c4ee020120d392b5feb10977d760681c09933bd0] # # patch "lua/lgc.cc" # from [31430b99360a8854902099b169766c458ac99f1d] # to [a5069b4901eac9eae03f4e5b57060471bef1508c] # # patch "lua/lgc.h" # from [9d7cd2b8aa1796b8cac3670243a758ee02947d55] # to [e8c4c314dc26ef41b36c914ffad2a0d1c9c02780] # # patch "lua/linit.cc" # from [0395394d3abe2bef704269e41f6b1d92b073dc5c] # to [0446202a74e28172a83d06f81a7bbc619690972e] # # patch "lua/liolib.cc" # from [e4643807bc88e7b6b237072c7b7644d31234a390] # to [3f7ce51bbd6b0464d65a7f7d9fe709add45e672d] # # patch "lua/llex.cc" # from [e8c143403480735be3c567c557c10d71e247c886] # to [0a44c355365d095a58b3921ff2f0867e9335ac17] # # patch "lua/llex.h" # from [50ac0f149ecb9f76b81cad752fec87744a59e5e3] # to [7019003896b7e53facfd4e2841fdb0d94d174b5a] # # patch "lua/llimits.h" # from [7349e397e9ebf4dbd78da8d88ef34116ae3e4343] # to [6a320119a11880cd1a61f49032e0f8e1a41b6926] # # patch "lua/lmathlib.cc" # from [07ff0c1338fe2d3788690d0f923b24b58bab0427] # to [4d94c29efdad9ccaeaa6597a72b7c79c8c9c51ee] # # patch "lua/lmem.cc" # from [97495a9991ccebec5544c94774a704187057c78c] # to [1da4a6a52ebff6ab4cb4e8a1d576a000ffd5e364] # # patch "lua/lmem.h" # from [a1524f544ef5949f688e0f7de3da19f52dc639f1] # to [15879820dc05c1b8b87e91dbd0f71eed7799202d] # # patch "lua/loadlib.cc" # from [92e4846e97e9ca543f8be217e7d0a45369aca2bf] # to [cfc136c1d1c302416bbe3754bae5213a2a994909] # # patch "lua/lobject.cc" # from [e5c75b49051dc13bb7e11552af1ffc7f98c70003] # to [eb7326a72581c6ff789debbf94ed3177e4401035] # # patch "lua/lobject.h" # from [b62a4c9a28f16e29a9d8e1124d2c7e07046f3485] # to [10decb8d4c324ed17be2b2f0a55c380da6e67a09] # # patch "lua/lopcodes.cc" # from [cfd931771dd75803b1b55a720aec7dbb113b40cf] # to [c119b1ffad9e90b3e3433d6a7a62de6d90d60a9c] # # patch "lua/lopcodes.h" # from [0766802065f203e628f108a90604c18b80069771] # to [d72eebbdbda5c628d1ab938ec2730f46411ce742] # # patch "lua/loslib.cc" # from [83a5795fdf92e425015c0f512c4fe2bc3d90444f] # to [60db2f6e65a69d0c6b026782d7fb4314763c3918] # # patch "lua/lparser.cc" # from [a96da6d9bf09f815d38cd4ea3ef5af4c6f78f09e] # to [b4b0465c9841f7d9de7662dd61c7f6d8294c431c] # # patch "lua/lparser.h" # from [dbfc992dfa358f773d985f2be14461fb5a1c93b2] # to [dd22486eeb91add23df82575bb3a4a9d16688b10] # # patch "lua/lstate.cc" # from [41f395fc8b5c4df66a901f6bf72d5440dd3ccd2a] # to [0cf23f7767dec1bd1a4a5663e21e91dc11cdbb39] # # patch "lua/lstate.h" # from [7fa3a357b1cc452dadb9e825c81913a339236254] # to [806111a73fbb43e09387e7f2260d20445f276b42] # # patch "lua/lstring.cc" # from [003567f00fdd6793c8c22f35357846bae074dab5] # to [f4d571787f370ff878d0cbb3967311e5f63ca23c] # # patch "lua/lstring.h" # from [94e58423bdf5ef6cf59c8f8b52587dd4eff86182] # to [0cec6ff1f31150f6be1878c23c917a453b23f3aa] # # patch "lua/lstrlib.cc" # from [b22ca5764c31a456cd97b3e1dcccc6cefc0bb79c] # to [f19cd1d659bae4c8ae463fbec613d2f06ad62c0e] # # patch "lua/ltable.cc" # from [bfae2e9c7b800ba10fda43248b207d8cadbd7f88] # to [cfa92b57f87a312b66142b4b69f4262222cb505a] # # patch "lua/ltable.h" # from [5ca09ef9b80e82e8b7eaedf6291ea3fbe25d3e4e] # to [7f97dcd6a0b369fff276ba18c8e55b3fedf2f332] # # patch "lua/ltablib.cc" # from [4d6c47cffb400eab927fa30c95e044513a688995] # to [bb8a10dcc02a1ca74d217a2f7079d4128e78fab2] # # patch "lua/ltm.cc" # from [c09b24aac7b5e25672751f043810be53e4197325] # to [17d148df320ea7e4a969792c6d959186aa3aafd4] # # patch "lua/ltm.h" # from [0e454631381c80f2f51b12639bb75700b8779c35] # to [7dcdde07e2fe2e8bfa02f55a8fea21bc6ae7bf9d] # # patch "lua/lua.h" # from [fc4aa068ed36acb5cdeb31b525b7dc6684f2c1b5] # to [a9a293f0fad0e90cf96357b312c7c7c1398568d1] # # patch "lua/luaconf.h" # from [deeb01d96c697e8b212cd318fcb9ae2fccc7da6c] # to [29fd32b585d2f98536882e14f1d151c96c8929fb] # # patch "lua/lualib.h" # from [4bfe76a50bdd71f99c7ec2ad5c0ac4b90eda246e] # to [358f8ef4277ea276b5ba7e255b46de92ad5058f5] # # patch "lua/lundump.cc" # from [7eb2ba658ba9e2d9de7b38170f4b7ae396c9275c] # to [2b332689280a9d3f5657f42b4857ea0a98a8933b] # # patch "lua/lundump.h" # from [6796db3fb1e5ffe2f89c8e2eb3c314991fdbd04c] # to [f5d0b9fe363d0c0b74291e52fc2dfb74bddf650a] # # patch "lua/lvm.cc" # from [851190a851aaa71a727c8e37a3c83cfb62534dd3] # to [f6720aac900a81bb5c20f63a85eea51a968d8097] # # patch "lua/lvm.h" # from [bb7e3209527ab679daae29a8ac93a46e4199fe98] # to [c1fc49d14b67aaf4360368014fe00b7694e4f920] # # patch "lua/lzio.cc" # from [18ba0e4963600c65a4dd607d67e5264ff073ca10] # to [0b47df18f885d4b4c4b12cf883ec9ab4cc64ed0a] # # patch "lua/lzio.h" # from [6eaa4bc56423b2d88c04d2b042a65196f847f685] # to [054a67e2cf78d8c0769d8ff4b905901d33031949] # ============================================================ --- lua/lapi.cc b40fccca3348e17c067e242b561bac8f695e76ba +++ lua/lapi.cc 233c7eeec692e096b50a93cd9531a7788d3418fb @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.55 2006/06/07 12:37:17 roberto Exp $ +** $Id: lapi.c,v 2.55.1.4 2008/02/14 16:46:39 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -93,15 +93,14 @@ LUA_API int lua_checkstack (lua_State *L LUA_API int lua_checkstack (lua_State *L, int size) { - int res; + int res = 1; 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 */ - else { + else if (size > 0) { luaD_checkstack(L, size); if (L->ci->top < L->top + size) L->ci->top = L->top + size; - res = 1; } lua_unlock(L); return res; @@ -123,6 +122,11 @@ LUA_API void lua_xmove (lua_State *from, } +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { lua_CFunction old; lua_lock(L); @@ -749,7 +753,7 @@ LUA_API int lua_setfenv (lua_State *L, i res = 0; break; } - luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); L->top--; lua_unlock(L); return res; ============================================================ --- lua/lapi.h e2a03294339035e7747833d64ba72a23c7212935 +++ lua/lapi.h c9ef6db904b74061af447bffae9482e5040488c0 @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 2.2 2005/04/25 19:24:10 roberto Exp $ +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ ============================================================ --- lua/lauxlib.cc aec1f02474cca684decfbe8b3146f1c327448344 +++ lua/lauxlib.cc 8b9200394c552623f83dcd543e919223bec6033a @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.159 2006/03/21 19:31:09 roberto Exp $ +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -244,7 +244,7 @@ LUALIB_API void luaI_openlib (lua_State if (libname) { int size = libsize(l); /* check whether lib already exists */ - luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", size); + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); lua_getfield(L, -1, libname); /* get _LOADED[libname] */ if (!lua_istable(L, -1)) { /* not found? */ lua_pop(L, 1); /* remove previous result */ @@ -535,7 +535,7 @@ static const char *getF (lua_State *L, v return "\n"; } if (feof(lf->f)) return NULL; - *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f); + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); return (*size > 0) ? lf->buff : NULL; } @@ -570,9 +570,8 @@ LUALIB_API int luaL_loadfile (lua_State while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ if (c == '\n') c = getc(lf.f); } - if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */ - fclose(lf.f); - lf.f = fopen(filename, "rb"); /* reopen in binary mode */ + 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); /* skip eventual `#!...' */ while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; @@ -581,7 +580,7 @@ LUALIB_API int luaL_loadfile (lua_State ungetc(c, lf.f); status = lua_load(L, getF, &lf, lua_tostring(L, -1)); readstatus = ferror(lf.f); - if (lf.f != stdin) fclose(lf.f); /* close file (even in case of errors) */ + if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from `lua_load' */ return errfile(L, "read", fnameindex); ============================================================ --- lua/lauxlib.h d4240105ac4ed1d0d040a16cc4d3a7ee25c7b246 +++ lua/lauxlib.h 02a10281004072779e88a6689daceaf34e7cd572 @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp $ +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ ============================================================ --- lua/lbaselib.cc 2d74fd901a61936cc6c6dd6b27ce74e4cf6b27bf +++ lua/lbaselib.cc 1b18d1b5ff9aa5f619790ca2321b603b8c820fb0 @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $ +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -344,10 +344,12 @@ static int luaB_unpack (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); i = luaL_optint(L, 2, 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 */ - if (n <= 0) return 0; /* empty range */ - luaL_checkstack(L, n, "table too big to unpack"); - for (; i<=e; i++) /* push arg[i...e] */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ lua_rawgeti(L, 1, i); return n; } @@ -477,19 +479,56 @@ static const luaL_Reg base_funcs[] = { ** ======================================================= */ +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + static int auxresume (lua_State *L, lua_State *co, int narg) { - int status; + int status = costatus(L, co); if (!lua_checkstack(co, narg)) luaL_error(L, "too many arguments to resume"); - if (lua_status(co) == 0 && lua_gettop(co) == 0) { - lua_pushliteral(L, "cannot resume dead coroutine"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); return -1; /* error flag */ } lua_xmove(L, co, narg); + lua_setlevel(L, co); status = lua_resume(co, narg); if (status == 0 || status == LUA_YIELD) { int nres = lua_gettop(co); - if (!lua_checkstack(L, nres)) + if (!lua_checkstack(L, nres + 1)) luaL_error(L, "too many results to resume"); lua_xmove(co, L, nres); /* move yielded values */ return nres; @@ -556,39 +595,10 @@ static int luaB_yield (lua_State *L) { } -static int luaB_costatus (lua_State *L) { - lua_State *co = lua_tothread(L, 1); - luaL_argcheck(L, co, 1, "coroutine expected"); - if (L == co) lua_pushliteral(L, "running"); - else { - switch (lua_status(co)) { - case LUA_YIELD: - lua_pushliteral(L, "suspended"); - break; - case 0: { - lua_Debug ar; - if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ - lua_pushliteral(L, "normal"); /* it is running */ - else if (lua_gettop(co) == 0) - lua_pushliteral(L, "dead"); - else - lua_pushliteral(L, "suspended"); /* initial state */ - break; - } - default: /* some error occured */ - lua_pushliteral(L, "dead"); - break; - } - } - return 1; -} - - static int luaB_corunning (lua_State *L) { if (lua_pushthread(L)) - return 0; /* main thread is not a coroutine */ - else - return 1; + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; } ============================================================ --- lua/lcode.cc e6eacb14c3868e1c1ed01971a2c34f47c60c0f7e +++ lua/lcode.cc 19839aefded482af7963a4d2eac183b0691db520 @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ ============================================================ --- lua/lcode.h dcca16be29919622475922d21c9517365143172b +++ lua/lcode.h 062429f2031f802f7211d7fd3443e34c2aa93bce @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp $ +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ ============================================================ --- lua/ldblib.cc 3030235ffb2046498e521cc0650bb46b121d8176 +++ lua/ldblib.cc 38debe80a0006ef4efbe6db9cd4a7805991fe3f1 @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp $ +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -255,24 +255,25 @@ static int db_sethook (lua_State *L) { static int db_sethook (lua_State *L) { - int arg; + int arg, mask, count; + lua_Hook func; lua_State *L1 = getthread(L, &arg); if (lua_isnoneornil(L, arg+1)) { lua_settop(L, arg+1); - lua_sethook(L1, NULL, 0, 0); /* turn off hooks */ + func = NULL; mask = 0; count = 0; /* turn off hooks */ } else { const char *smask = luaL_checkstring(L, arg+2); - int count = luaL_optint(L, arg+3, 0); luaL_checktype(L, arg+1, LUA_TFUNCTION); - lua_sethook(L1, hookf, makemask(smask, count), count); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); } - gethooktable(L1); - lua_pushlightuserdata(L1, L1); + gethooktable(L); + lua_pushlightuserdata(L, L1); lua_pushvalue(L, arg+1); - lua_xmove(L, L1, 1); - lua_rawset(L1, -3); /* set new hook */ - lua_pop(L1, 1); /* remove hook table */ + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ return 0; } @@ -286,11 +287,10 @@ static int db_gethook (lua_State *L) { if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { - gethooktable(L1); - lua_pushlightuserdata(L1, L1); - lua_rawget(L1, -2); /* get hook */ - lua_remove(L1, -2); /* remove hook table */ - lua_xmove(L1, L, 1); + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushinteger(L, lua_gethookcount(L1)); ============================================================ --- lua/ldebug.cc 12397d0afadabc35c580b4031b9a1223d7efd02d +++ lua/ldebug.cc 39d5e3e301f18b29c641eb67280023063a99cdb8 @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $ +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -275,12 +275,12 @@ static int precheck (const Proto *pt) { static int precheck (const Proto *pt) { check(pt->maxstacksize <= MAXSTACK); - lua_assert(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); - lua_assert(!(pt->is_vararg & VARARG_NEEDSARG) || + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || (pt->is_vararg & VARARG_HASARG)); check(pt->sizeupvalues <= pt->nups); 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; } @@ -346,9 +346,18 @@ static Instruction symbexec (const Proto int dest = pc+1+b; check(0 <= dest && dest < pt->sizecode); if (dest > 0) { - /* cannot jump to a setlist count */ - Instruction d = pt->code[dest-1]; - check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)); + int j; + /* check that it does not jump to a setlist count; this + 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; @@ -363,7 +372,11 @@ static Instruction symbexec (const Proto } switch (op) { 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; } case OP_LOADNIL: { @@ -428,7 +441,10 @@ static Instruction symbexec (const Proto } case OP_SETLIST: { if (b > 0) checkreg(pt, a + b); - if (c == 0) pc++; + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } break; } case OP_CLOSURE: { ============================================================ --- lua/ldebug.h 989e9b1011b17b7e470c911f9828118f580edd75 +++ lua/ldebug.h c99005b7cf9ccc459c186e6301a71d115adfa459 @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 2.3 2005/04/25 19:24:10 roberto Exp $ +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ ============================================================ --- lua/ldo.cc dfa3815380568d4ebd38d95e292c41926cf8b77b +++ lua/ldo.cc 5545986bbacd2b59b4ffa691e72434fb42e8d8bc @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.38 2006/06/05 19:36:14 roberto Exp $ +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -83,7 +83,7 @@ static void resetstack (lua_State *L, in L->base = L->ci->base; luaF_close(L, L->base); /* close eventual pending closures */ luaD_seterrorobj(L, status, L->base); - L->nCcalls = 0; + L->nCcalls = L->baseCcalls; L->allowhook = 1; restore_stack_limit(L); L->errfunc = 0; @@ -332,7 +332,7 @@ static StkId callrethooks (lua_State *L, ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ luaD_callhook(L, LUA_HOOKRET, -1); if (f_isLua(L->ci)) { /* Lua function? */ - while (L->ci->tailcalls--) /* call hook for eventual tail calls */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ luaD_callhook(L, LUA_HOOKTAILRET, -1); } return restorestack(L, fr); @@ -417,22 +417,24 @@ LUA_API int lua_resume (lua_State *L, in LUA_API int lua_resume (lua_State *L, int nargs) { int status; lua_lock(L); - if (L->status != LUA_YIELD) { - if (L->status != 0) - return resume_error(L, "cannot resume dead coroutine"); - else if (L->ci != L->base_ci) + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) return resume_error(L, "cannot resume non-suspended coroutine"); - } + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); luai_userstateresume(L, nargs); - lua_assert(L->errfunc == 0 && L->nCcalls == 0); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; status = luaD_rawrunprotected(L, resume, L->top - nargs); if (status != 0) { /* error? */ L->status = cast_byte(status); /* mark thread as `dead' */ luaD_seterrorobj(L, status, L->top); L->ci->top = L->top; } - else + else { + lua_assert(L->nCcalls == L->baseCcalls); status = L->status; + } + --L->nCcalls; lua_unlock(L); return status; } @@ -441,7 +443,7 @@ LUA_API int lua_yield (lua_State *L, int LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); - if (L->nCcalls > 0) + if (L->nCcalls > L->baseCcalls) luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); L->base = L->top - nresults; /* protect stack slots below */ L->status = LUA_YIELD; ============================================================ --- lua/ldo.h fb197f91ae723ebf6078a818b360ac8e405cccf8 +++ lua/ldo.h a1ccddad924343d3b38951e9e4b96d735a6faa2d @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 2.7 2005/08/24 16:15:49 roberto Exp $ +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ ============================================================ --- lua/ldump.cc fe3a3e76f6656f5936928d4ca3fcb762fc253dcb +++ lua/ldump.cc 2593a17ee49d7809d7a1b94a9733cb02862b5c28 @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $ +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ ============================================================ --- lua/lfunc.cc 8bf49521d76d9fc9b948d818e027806d305976b5 +++ lua/lfunc.cc 8442f6114be3e777b601f11848154d5423fb9068 @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $ +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ ============================================================ --- lua/lfunc.h a785376a53128d2dd9fb73ca77d254b4fa1109a1 +++ lua/lfunc.h c4ee020120d392b5feb10977d760681c09933bd0 @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $ +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ ============================================================ --- lua/lgc.cc 31430b99360a8854902099b169766c458ac99f1d +++ lua/lgc.cc a5069b4901eac9eae03f4e5b57060471bef1508c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.38 2006/05/24 14:34:06 roberto Exp $ +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ ============================================================ --- lua/lgc.h 9d7cd2b8aa1796b8cac3670243a758ee02947d55 +++ lua/lgc.h e8c4c314dc26ef41b36c914ffad2a0d1c9c02780 @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 2.15 2005/08/24 16:15:49 roberto Exp $ +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ ============================================================ --- lua/linit.cc 0395394d3abe2bef704269e41f6b1d92b073dc5c +++ lua/linit.cc 0446202a74e28172a83d06f81a7bbc619690972e @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.14 2005/12/29 15:32:11 roberto Exp $ +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ ** Initialization of libraries for lua.c ** See Copyright Notice in lua.h */ ============================================================ --- lua/liolib.cc e4643807bc88e7b6b237072c7b7644d31234a390 +++ lua/liolib.cc 3f7ce51bbd6b0464d65a7f7d9fe709add45e672d @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.73 2006/05/08 20:14:16 roberto Exp $ +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -51,7 +51,7 @@ static void fileerror (lua_State *L, int } -#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) static int io_type (lua_State *L) { @@ -70,7 +70,7 @@ static FILE *tofile (lua_State *L) { static FILE *tofile (lua_State *L) { - FILE **f = topfile(L); + FILE **f = tofilep(L); if (*f == NULL) luaL_error(L, "attempt to use a closed file"); return *f; @@ -93,19 +93,31 @@ static FILE **newfile (lua_State *L) { /* -** this function has a separated environment, which defines the -** correct __close for 'popen' files +** function to (not) close the standard files stdin, stdout, and stderr */ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files +*/ static int io_pclose (lua_State *L) { - FILE **p = topfile(L); + FILE **p = tofilep(L); int ok = lua_pclose(L, *p); *p = NULL; return pushresult(L, ok, NULL); } +/* +** function to close regular files +*/ static int io_fclose (lua_State *L) { - FILE **p = topfile(L); + FILE **p = tofilep(L); int ok = (fclose(*p) == 0); *p = NULL; return pushresult(L, ok, NULL); @@ -128,18 +140,18 @@ static int io_gc (lua_State *L) { static int io_gc (lua_State *L) { - FILE *f = *topfile(L); - /* ignore closed files and standard files */ - if (f != NULL && f != stdin && f != stdout && f != stderr) + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) aux_close(L); return 0; } static int io_tostring (lua_State *L) { - FILE *f = *topfile(L); + FILE *f = *tofilep(L); if (f == NULL) - lua_pushstring(L, "file (closed)"); + lua_pushliteral(L, "file (closed)"); else lua_pushfstring(L, "file (%p)", f); return 1; @@ -155,6 +167,10 @@ static int io_open (lua_State *L) { } +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ static int io_popen (lua_State *L) { const char *filename = luaL_checkstring(L, 1); const char *mode = luaL_optstring(L, 2, "r"); @@ -280,7 +296,7 @@ static int read_line (lua_State *L, FILE char *p = luaL_prepbuffer(&b); if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ luaL_pushresult(&b); /* close buffer */ - return (lua_strlen(L, -1) > 0); /* check whether read something */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ } l = strlen(p); if (l == 0 || p[l-1] != '\n') @@ -308,7 +324,7 @@ static int read_chars (lua_State *L, FIL n -= nr; /* still have to read `n' chars */ } while (n > 0 && nr == rlen); /* until end of count or eof */ luaL_pushresult(&b); /* close buffer */ - return (n == 0 || lua_strlen(L, -1) > 0); + return (n == 0 || lua_objlen(L, -1) > 0); } @@ -502,31 +518,36 @@ static void createstdfile (lua_State *L, lua_pushvalue(L, -1); lua_rawseti(L, LUA_ENVIRONINDEX, k); } - lua_setfield(L, -2, fname); + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); } +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); +} + + LUALIB_API int luaopen_io (lua_State *L) { createmeta(L); /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ - lua_createtable(L, 2, 1); + newfenv(L, io_fclose); lua_replace(L, LUA_ENVIRONINDEX); /* open library */ luaL_register(L, LUA_IOLIBNAME, iolib); /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, 0, "stderr"); - /* create environment for 'popen' */ + lua_pop(L, 1); /* pop environment for default files */ lua_getfield(L, -1, "popen"); - lua_createtable(L, 0, 1); - lua_pushcfunction(L, io_pclose); - lua_setfield(L, -2, "__close"); - lua_setfenv(L, -2); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ lua_pop(L, 1); /* pop 'popen' */ - /* set default close function */ - lua_pushcfunction(L, io_fclose); - lua_setfield(L, LUA_ENVIRONINDEX, "__close"); return 1; } ============================================================ --- lua/llex.cc e8c143403480735be3c567c557c10d71e247c886 +++ lua/llex.cc 0a44c355365d095a58b3921ff2f0867e9335ac17 @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $ +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ ============================================================ --- lua/llex.h 50ac0f149ecb9f76b81cad752fec87744a59e5e3 +++ lua/llex.h 7019003896b7e53facfd4e2841fdb0d94d174b5a @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $ +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ ============================================================ --- lua/llimits.h 7349e397e9ebf4dbd78da8d88ef34116ae3e4343 +++ lua/llimits.h 6a320119a11880cd1a61f49032e0f8e1a41b6926 @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $ +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ ============================================================ --- lua/lmathlib.cc 07ff0c1338fe2d3788690d0f923b24b58bab0427 +++ lua/lmathlib.cc 4d94c29efdad9ccaeaa6597a72b7c79c8c9c51ee @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp $ +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ ** Standard mathematical library ** See Copyright Notice in lua.h */ ============================================================ --- lua/lmem.cc 97495a9991ccebec5544c94774a704187057c78c +++ lua/lmem.cc 1da4a6a52ebff6ab4cb4e8a1d576a000ffd5e364 @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.70 2005/12/26 13:35:47 roberto Exp $ +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ ============================================================ --- lua/lmem.h a1524f544ef5949f688e0f7de3da19f52dc639f1 +++ lua/lmem.h 15879820dc05c1b8b87e91dbd0f71eed7799202d @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.31 2005/04/25 19:24:10 roberto Exp $ +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ ============================================================ --- lua/loadlib.cc 92e4846e97e9ca543f8be217e7d0a45369aca2bf +++ lua/loadlib.cc cfc136c1d1c302416bbe3754bae5213a2a994909 @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $ +** $Id: loadlib.c,v 1.52.1.2 2007/12/28 14:58:43 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** ============================================================ --- lua/lobject.cc e5c75b49051dc13bb7e11552af1ffc7f98c70003 +++ lua/lobject.cc eb7326a72581c6ff789debbf94ed3177e4401035 @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.22 2006/02/10 17:43:52 roberto Exp $ +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ ============================================================ --- lua/lobject.h b62a4c9a28f16e29a9d8e1124d2c7e07046f3485 +++ lua/lobject.h 10decb8d4c324ed17be2b2f0a55c380da6e67a09 @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.20 2006/01/18 11:37:34 roberto Exp $ +** $Id: lobject.h,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ ============================================================ --- lua/lopcodes.cc cfd931771dd75803b1b55a720aec7dbb113b40cf +++ lua/lopcodes.cc c119b1ffad9e90b3e3433d6a7a62de6d90d60a9c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.37 2005/11/08 19:45:36 roberto Exp $ +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** See Copyright Notice in lua.h */ ============================================================ --- lua/lopcodes.h 0766802065f203e628f108a90604c18b80069771 +++ lua/lopcodes.h d72eebbdbda5c628d1ab938ec2730f46411ce742 @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.125 2006/03/14 19:04:44 roberto Exp $ +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ ============================================================ --- lua/loslib.cc 83a5795fdf92e425015c0f512c4fe2bc3d90444f +++ lua/loslib.cc 60db2f6e65a69d0c6b026782d7fb4314763c3918 @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $ +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -215,7 +215,6 @@ static int os_exit (lua_State *L) { static int os_exit (lua_State *L) { exit(luaL_optint(L, 1, EXIT_SUCCESS)); - return 0; /* to avoid warnings */ } static const luaL_Reg syslib[] = { ============================================================ --- lua/lparser.cc a96da6d9bf09f815d38cd4ea3ef5af4c6f78f09e +++ lua/lparser.cc b4b0465c9841f7d9de7662dd61c7f6d8294c431c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $ +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -939,7 +939,7 @@ static void assignment (LexState *ls, st if (nv.v.k == VLOCAL) check_conflict(ls, lh, &nv.v); luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, - "variable names"); + "variables in assignment"); assignment(ls, &nv, nvars+1); } else { /* assignment -> `=' explist1 */ ============================================================ --- lua/lparser.h dbfc992dfa358f773d985f2be14461fb5a1c93b2 +++ lua/lparser.h dd22486eeb91add23df82575bb3a4a9d16688b10 @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $ +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ ============================================================ --- lua/lstate.cc 41f395fc8b5c4df66a901f6bf72d5440dd3ccd2a +++ lua/lstate.cc 0cf23f7767dec1bd1a4a5663e21e91dc11cdbb39 @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $ +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -93,7 +93,7 @@ static void preinit_state (lua_State *L, resethookcount(L); L->openupval = NULL; L->size_ci = 0; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; L->status = 0; L->base_ci = L->ci = NULL; L->savedpc = NULL; @@ -205,7 +205,7 @@ LUA_API void lua_close (lua_State *L) { do { /* repeat until no more errors */ L->ci = L->base_ci; L->base = L->top = L->ci->base; - L->nCcalls = 0; + L->nCcalls = L->baseCcalls = 0; } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); lua_assert(G(L)->tmudata == NULL); luai_userstateclose(L); ============================================================ --- lua/lstate.h 7fa3a357b1cc452dadb9e825c81913a339236254 +++ lua/lstate.h 806111a73fbb43e09387e7f2260d20445f276b42 @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $ +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -112,6 +112,7 @@ struct lua_State { int stacksize; int size_ci; /* size of array `base_ci' */ unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ lu_byte hookmask; lu_byte allowhook; int basehookcount; ============================================================ --- lua/lstring.cc 003567f00fdd6793c8c22f35357846bae074dab5 +++ lua/lstring.cc f4d571787f370ff878d0cbb3967311e5f63ca23c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $ +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ ============================================================ --- lua/lstring.h 94e58423bdf5ef6cf59c8f8b52587dd4eff86182 +++ lua/lstring.h 0cec6ff1f31150f6be1878c23c917a453b23f3aa @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $ +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ ============================================================ --- lua/lstrlib.cc b22ca5764c31a456cd97b3e1dcccc6cefc0bb79c +++ lua/lstrlib.cc f19cd1d659bae4c8ae463fbec613d2f06ad62c0e @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $ +** $Id: lstrlib.c,v 1.132.1.3 2007/12/28 15:32:23 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -629,10 +629,6 @@ static void add_value (MatchState *ms, l lua_gettable(L, 3); break; } - default: { - luaL_argerror(L, 3, "string/function/table expected"); - return; - } } if (!lua_toboolean(L, -1)) { /* nil or false? */ lua_pop(L, 1); @@ -648,11 +644,15 @@ static int str_gsub (lua_State *L) { size_t srcl; const char *src = luaL_checklstring(L, 1, &srcl); const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); int max_s = luaL_optint(L, 4, srcl+1); int anchor = (*p == '^') ? (p++, 1) : 0; int n = 0; MatchState ms; luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); luaL_buffinit(L, &b); ms.L = L; ms.src_init = src; ============================================================ --- lua/ltable.cc bfae2e9c7b800ba10fda43248b207d8cadbd7f88 +++ lua/ltable.cc cfa92b57f87a312b66142b4b69f4262222cb505a @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp $ +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ ============================================================ --- lua/ltable.h 5ca09ef9b80e82e8b7eaedf6291ea3fbe25d3e4e +++ lua/ltable.h 7f97dcd6a0b369fff276ba18c8e55b3fedf2f332 @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 2.10 2006/01/10 13:13:06 roberto Exp $ +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ ============================================================ --- lua/ltablib.cc 4d6c47cffb400eab927fa30c95e044513a688995 +++ lua/ltablib.cc bb8a10dcc02a1ca74d217a2f7079d4128e78fab2 @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.38 2005/10/23 17:38:15 roberto Exp $ +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -118,7 +118,8 @@ static int tremove (lua_State *L) { static int tremove (lua_State *L) { int e = aux_getn(L, 1); int pos = luaL_optint(L, 2, e); - if (e == 0) return 0; /* table is `empty' */ + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ luaL_setn(L, 1, e - 1); /* t.n = n-1 */ lua_rawgeti(L, 1, pos); /* result = t[pos] */ for ( ;pos #include -/* Monotone local: Needs to see the application config.h. */ -#include "config.h" /* ** ================================================================== @@ -31,14 +29,9 @@ #endif -/* Monotone local: We can assume POSIX if not _WIN32. */ -#if !defined(LUA_ANSI) -#if defined(_WIN32) +#if !defined(LUA_ANSI) && defined(_WIN32) #define LUA_WIN -#else -#define LUA_USE_POSIX #endif -#endif #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX @@ -447,9 +440,10 @@ @* can use. ** 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 to consume unlimited stack space. +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) */ -#define LUAI_MAXCSTACK 2048 +#define LUAI_MAXCSTACK 8000 @@ -559,26 +553,30 @@ ** in C is extremely slow, so any alternative is worth trying. */ -/* Monotone local: lrint() is what we really want, but it's C99, so we - can't assume it. Also, remove horrible union hack that cannot be - relied upon. Note that if LUA_NUMBER_DOUBLE is not defined, no - special handling is necessary. */ +/* On a Pentium, resort to a trick */ +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ + (defined(__i386) || defined (_M_IX86) || defined(__i386__)) -#if defined(LUA_NUMBER_DOUBLE) && defined(HAVE_LRINT) -#define lua_number2int(i,d) ((i) = lrint(d)) -#define lua_number2integer(i,n) ((i) = lrint(n)) +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) -/* On a Microsoft compiler on x86 and not SSE2, use assembler */ -#elif defined(LUA_NUMBER_DOUBLE) && defined(_MSC_VER) \ - && (defined(__i386) || defined(__i386__) || defined(_M_IX86)) \ - && !defined(__SSE2__) +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) -#define lua_number2int(i,d) __asm fld d __asm fistp i +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + +union luai_Cast { double l_d; long l_l; }; +#define lua_number2int(i,d) \ + { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } #define lua_number2integer(i,n) lua_number2int(i, n) +#endif + + /* this option always works, but may be slow */ #else - #define lua_number2int(i,d) ((i)=(int)(d)) #define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) @@ -669,7 +667,7 @@ */ #if defined(LUA_USE_POPEN) -#define lua_popen(L,c,m) ((void)L, popen(c,m)) +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #elif defined(LUA_WIN) @@ -759,10 +757,6 @@ ** without modifying the main part of the file. */ -/* Monotone local: make absolutely sure loadlib is a stub. */ -#undef LUA_DL_DLOPEN -#undef LUA_DL_DLL -#undef LUA_DL_DYLD #endif ============================================================ --- lua/lualib.h 4bfe76a50bdd71f99c7ec2ad5c0ac4b90eda246e +++ lua/lualib.h 358f8ef4277ea276b5ba7e255b46de92ad5058f5 @@ -1,5 +1,5 @@ /* -** $Id: lualib.h,v 1.36 2005/12/27 17:12:00 roberto Exp $ +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua standard libraries ** See Copyright Notice in lua.h */ ============================================================ --- lua/lundump.cc 7eb2ba658ba9e2d9de7b38170f4b7ae396c9275c +++ lua/lundump.cc 2b332689280a9d3f5657f42b4857ea0a98a8933b @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 1.60 2006/02/16 15:53:49 lhf Exp $ +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -29,6 +29,7 @@ typedef struct { #ifdef LUAC_TRUST_BINARIES #define IF(c,s) +#define error(S,s) #else #define IF(c,s) if (c) error(S,s) @@ -113,7 +114,7 @@ static void LoadConstants(LoadState* S, setnilvalue(o); break; case LUA_TBOOLEAN: - setbvalue(o,LoadChar(S)); + setbvalue(o,LoadChar(S)!=0); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); @@ -122,7 +123,7 @@ static void LoadConstants(LoadState* S, setsvalue2n(S->L,o,LoadString(S)); break; default: - IF (1, "bad constant"); + error(S,"bad constant"); break; } } @@ -159,7 +160,9 @@ static Proto* LoadFunction(LoadState* S, 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); f->source=LoadString(S); if (f->source==NULL) f->source=p; f->linedefined=LoadInt(S); @@ -173,6 +176,7 @@ static Proto* LoadFunction(LoadState* S, LoadDebug(S,f); IF (!luaG_checkcode(f), "bad code"); S->L->top--; + S->L->nCcalls--; return f; } ============================================================ --- lua/lundump.h 6796db3fb1e5ffe2f89c8e2eb3c314991fdbd04c +++ lua/lundump.h f5d0b9fe363d0c0b74291e52fc2dfb74bddf650a @@ -1,5 +1,5 @@ /* -** $Id: lundump.h,v 1.40 2005/11/11 14:03:13 lhf Exp $ +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ ** load precompiled Lua chunks ** See Copyright Notice in lua.h */ ============================================================ --- lua/lvm.cc 851190a851aaa71a727c8e37a3c83cfb62534dd3 +++ lua/lvm.cc f6720aac900a81bb5c20f63a85eea51a968d8097 @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $ +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ ============================================================ --- lua/lvm.h bb7e3209527ab679daae29a8ac93a46e4199fe98 +++ lua/lvm.h c1fc49d14b67aaf4360368014fe00b7694e4f920 @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $ +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ ============================================================ --- lua/lzio.cc 18ba0e4963600c65a4dd607d67e5264ff073ca10 +++ lua/lzio.cc 0b47df18f885d4b4c4b12cf883ec9ab4cc64ed0a @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $ +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ ** a generic input stream interface ** See Copyright Notice in lua.h */ ============================================================ --- lua/lzio.h 6eaa4bc56423b2d88c04d2b042a65196f847f685 +++ lua/lzio.h 054a67e2cf78d8c0769d8ff4b905901d33031949 @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $ +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ ** Buffered streams ** See Copyright Notice in lua.h */