# # patch "ChangeLog" # from [369e3b3a2565f2338c5b1cba2dca8bde16b221ab] # to [88b7d03f7822bf0467b170a2abd9383a95a29b96] # # patch "lua/lbaselib.c" # from [3df217b8f16babf4d43d4dd45d9c431ba79249e4] # to [0e04c41d7a456b729da336789edd968b10c6d819] # # patch "lua/ldo.c" # from [4c1e026a1aab65b17752755ead03fec4bda934bd] # to [dc192d3aa74ac943e3f5a09120242d6a15b433dc] # # patch "lua/lgc.c" # from [78aee88428335dfef4855b330ce72ad798041f4b] # to [6c2146a08f71323a53b7fe9bf89e9f1f06aeab4a] # # patch "lua/lgc.h" # from [6a6e8b6c186afde99dbd25d0054a1fa0b178c1f0] # to [9d3863eda15a5996349f8ce35b6eb20e658280ed] # # patch "lua/liolib.c" # from [bc4f9f194b3dc8262a6180fce3eb2fd578746c67] # to [fadcadbbae8e9b4903265ea360165aa87f3a6240] # # patch "lua/lparser.c" # from [34b6d02dced909da0636da48dcf99c6d5a4f82f5] # to [b5a53a8d48ff9964edd201d4b69074b611b1f797] # # patch "lua/lua.h" # from [6eb513affce73a59f5a2d8699d45de7f220f7463] # to [7fd2285047bb19fae5c3bb30cf22ad385731f97b] # # patch "lua/lualib.h" # from [bd0362b9268ce6f34a909b89e24fa21f3c701dab] # to [aaa3ea1d5174aafee68e32ae989fc04aad739c29] # # patch "lua/lvm.c" # from [9ca5c5431d4999debed34515ae775093b2f3a6f7] # to [935d94cfbb01d58a9137de1358565531aeedfd9a] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,7 @@ +2005-07-17 Matthew Gregan + + * lua/*: Import Lua 5.0.2 from upstream. + 2005-07-16 Nathaniel Smith * NEWS: Update for 0.21. --- lua/lbaselib.c +++ lua/lbaselib.c @@ -274,10 +274,11 @@ static int luaB_dofile (lua_State *L) { const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); int status = luaL_loadfile(L, fname); if (status != 0) lua_error(L); lua_call(L, 0, LUA_MULTRET); - return lua_gettop(L) - 1; + return lua_gettop(L) - n; } @@ -324,7 +325,7 @@ static int luaB_tostring (lua_State *L) { - char buff[64]; + char buff[128]; luaL_checkany(L, 1); if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ return 1; /* use its value */ --- lua/ldo.c +++ lua/ldo.c @@ -322,11 +322,11 @@ int nargs = *cast(int *, ud); CallInfo *ci = L->ci; if (ci == L->base_ci) { /* no activation record? */ - if (nargs >= L->top - L->base) - luaG_runerror(L, "cannot resume dead coroutine"); + lua_assert(nargs < L->top - L->base); luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */ } - else if (ci->state & CI_YIELD) { /* inside a yield? */ + else { /* inside a yield */ + lua_assert(ci->state & CI_YIELD); if (ci->state & CI_C) { /* `common' yield? */ /* finish interrupted execution of `OP_CALL' */ int nresults; @@ -341,18 +341,31 @@ ci->state &= ~CI_YIELD; } } - else - luaG_runerror(L, "cannot resume non-suspended coroutine"); firstResult = luaV_execute(L); if (firstResult != NULL) /* return? */ luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */ } +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + LUA_API int lua_resume (lua_State *L, int nargs) { int status; lu_byte old_allowhooks; lua_lock(L); + if (L->ci == L->base_ci) { + if (nargs >= L->top - L->base) + return resume_error(L, "cannot resume dead coroutine"); + } + else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */ + return resume_error(L, "cannot resume non-suspended coroutine"); old_allowhooks = L->allowhook; lua_assert(L->errfunc == 0 && L->nCcalls == 0); status = luaD_rawrunprotected(L, resume, &nargs); --- lua/lgc.c +++ lua/lgc.c @@ -110,7 +110,8 @@ /* move `dead' udata that need finalization to list `tmudata' */ -void luaC_separateudata (lua_State *L) { +size_t luaC_separateudata (lua_State *L) { + size_t deadmem = 0; GCObject **p = &G(L)->rootudata; GCObject *curr; GCObject *collected = NULL; /* to collect udata with gc event */ @@ -125,6 +126,7 @@ p = &curr->gch.next; } else { /* must call its gc method */ + deadmem += sizeudata(gcotou(curr)->uv.len); *p = curr->gch.next; curr->gch.next = NULL; /* link `curr' at the end of `collected' list */ *lastcollected = curr; @@ -134,6 +136,7 @@ /* insert collected udata with gc event into `tmudata' list */ *lastcollected = G(L)->tmudata; G(L)->tmudata = collected; + return deadmem; } @@ -244,7 +247,7 @@ for (ci = L1->base_ci; ci <= L1->ci; ci++) { lua_assert(ci->top <= L1->stack_last); lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC)); - if (!(ci->state & CI_C) && lim < ci->top) + if (lim < ci->top) lim = ci->top; } for (o = L1->stack; o < L1->top; o++) @@ -387,7 +390,7 @@ } -static void checkSizes (lua_State *L) { +static void checkSizes (lua_State *L, size_t deadmem) { /* check size of string hash */ if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) && G(L)->strt.size > MINSTRTABSIZE*2) @@ -397,7 +400,7 @@ size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2; luaZ_resizebuffer(L, &G(L)->buff, newsize); } - G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */ + G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */ } @@ -451,7 +454,8 @@ } -static void mark (lua_State *L) { +static size_t mark (lua_State *L) { + size_t deadmem; GCState st; GCObject *wkv; st.g = G(L); @@ -464,7 +468,7 @@ wkv = st.wkv; /* keys must be cleared after preserving udata */ st.wkv = NULL; st.wv = NULL; - luaC_separateudata(L); /* separate userdata to be preserved */ + deadmem = luaC_separateudata(L); /* separate userdata to be preserved */ marktmu(&st); /* mark `preserved' userdata */ propagatemarks(&st); /* remark, to propagate `preserveness' */ cleartablekeys(wkv); @@ -473,13 +477,14 @@ cleartablevalues(st.wv); cleartablekeys(st.wkv); cleartablevalues(st.wkv); + return deadmem; } void luaC_collectgarbage (lua_State *L) { - mark(L); + size_t deadmem = mark(L); luaC_sweep(L, 0); - checkSizes(L); + checkSizes(L, deadmem); luaC_callGCTM(L); } --- lua/lgc.h +++ lua/lgc.h @@ -15,7 +15,7 @@ if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); } -void luaC_separateudata (lua_State *L); +size_t luaC_separateudata (lua_State *L); void luaC_callGCTM (lua_State *L); void luaC_sweep (lua_State *L, int all); void luaC_collectgarbage (lua_State *L); --- lua/liolib.c +++ lua/liolib.c @@ -158,7 +158,7 @@ static int io_close (lua_State *L) { - if (lua_isnone(L, 1)) { + if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) { lua_pushstring(L, IO_OUTPUT); lua_rawget(L, lua_upvalueindex(1)); } @@ -175,7 +175,7 @@ static int io_tostring (lua_State *L) { - char buff[32]; + char buff[128]; FILE **f = topfile(L, 1); if (*f == NULL) strcpy(buff, "closed"); --- lua/lparser.c +++ lua/lparser.c @@ -1141,11 +1141,15 @@ static void localfunc (LexState *ls) { expdesc v, b; + FuncState *fs = ls->fs; new_localvar(ls, str_checkname(ls), 0); - init_exp(&v, VLOCAL, ls->fs->freereg++); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); adjustlocalvars(ls, 1); body(ls, &b, 0, ls->linenumber); - luaK_storevar(ls->fs, &v, &b); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; } --- lua/lua.h +++ lua/lua.h @@ -18,8 +18,8 @@ #include -#define LUA_VERSION "Lua 5.0" -#define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio" +#define LUA_VERSION "Lua 5.0.2" +#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -369,7 +369,7 @@ /****************************************************************************** -* Copyright (C) 1994-2003 Tecgraf, PUC-Rio. All rights reserved. +* Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the --- lua/lualib.h +++ lua/lualib.h @@ -38,7 +38,6 @@ LUALIB_API int luaopen_loadlib (lua_State *L); -LUALIB_API int luaopen_posix (lua_State *L); /* to help testing the libraries */ #ifndef lua_assert --- lua/lvm.c +++ lua/lvm.c @@ -66,7 +66,7 @@ static void traceexec (lua_State *L) { lu_byte mask = L->hookmask; - if (mask > LUA_MASKLINE) { /* instruction-hook set? */ + if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */ if (L->hookcount == 0) { resethookcount(L); luaD_callhook(L, LUA_HOOKCOUNT, -1); @@ -399,10 +399,12 @@ TObject *k; const Instruction *pc; callentry: /* entry point when calling new functions */ - L->ci->u.l.pc = &pc; - if (L->hookmask & LUA_MASKCALL) + if (L->hookmask & LUA_MASKCALL) { + L->ci->u.l.pc = &pc; luaD_callhook(L, LUA_HOOKCALL, -1); + } retentry: /* entry point when returning to old functions */ + L->ci->u.l.pc = &pc; lua_assert(L->ci->state == CI_SAVEDPC || L->ci->state == (CI_SAVEDPC | CI_CALLING)); L->ci->state = CI_HASFRAME; /* activate frame */ @@ -673,9 +675,7 @@ } else { /* yes: continue its execution */ int nresults; - lua_assert(ci->u.l.pc == &pc && - ttisfunction(ci->base - 1) && - (ci->state & CI_SAVEDPC)); + lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC)); lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL); nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1; luaD_poscall(L, nresults, ra); @@ -778,3 +778,4 @@ } } +