summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2006-06-19 12:00:00 +0000
committerrepogen <>2006-06-19 12:00:00 +0000
commit0de9166148af8217fd15c8540755753c0256581b (patch)
tree0d5d72e0a7b6b2c91d43dec1a49e8f76e417e6c7
parente7731a8fb8a317aa5c444ef073bfad82fa5baa54 (diff)
downloadlua-github-5.0.x.tar.gz
Lua 5.0.35.0.35.0.x
-rw-r--r--COPYRIGHT2
-rw-r--r--DIFFS480
-rw-r--r--MANIFEST260
-rw-r--r--include/lua.h8
-rw-r--r--src/lapi.c6
-rw-r--r--src/lcode.c52
-rw-r--r--src/lfunc.c10
-rw-r--r--src/lfunc.h9
-rw-r--r--src/lgc.c23
-rw-r--r--src/lib/lbaselib.c4
-rw-r--r--src/lib/liolib.c66
-rw-r--r--src/lvm.c14
12 files changed, 514 insertions, 420 deletions
diff --git a/COPYRIGHT b/COPYRIGHT
index 16321abf..2cd57d3b 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -9,7 +9,7 @@ For details and rationale, see http://www.lua.org/license.html .
===============================================================================
-Copyright (C) 2003-2004 Tecgraf, PUC-Rio.
+Copyright (C) 2003-2006 Tecgraf, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/DIFFS b/DIFFS
index f7d5ba27..c236ff8b 100644
--- a/DIFFS
+++ b/DIFFS
@@ -1,224 +1,294 @@
-diff -r lua-5.0/COPYRIGHT lua-5.0.2/COPYRIGHT
+diff -r lua-5.0.2/COPYRIGHT lua-5.0.3/COPYRIGHT
12c12
-< Copyright (C) 2003 Tecgraf, PUC-Rio.
+< Copyright (C) 2003-2004 Tecgraf, PUC-Rio.
---
-> Copyright (C) 2003-2004 Tecgraf, PUC-Rio.
-diff -r lua-5.0/Makefile lua-5.0.2/Makefile
-98a99,101
-> newer:
-> @find . -newer MANIFEST -type f
->
-diff -r lua-5.0/doc/readme.html lua-5.0.2/doc/readme.html
-16c16
-< <LI><A HREF="manual.html">Reference manual</A>
----
-> <LI><A HREF="contents.html">Reference manual</A>
-31c31
-< Tue Apr 1 14:35:18 EST 2003
----
-> Thu Mar 11 23:08:56 BRT 2004
-diff -r lua-5.0/include/lua.h lua-5.0.2/include/lua.h
+> Copyright (C) 2003-2006 Tecgraf, PUC-Rio.
+diff -r lua-5.0.2/include/lua.h lua-5.0.3/include/lua.h
2c2
-< ** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $
+< ** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
---
-> ** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
+> ** $Id: lua.h,v 1.175c 2003/03/18 12:31:39 roberto Exp $
17,18c17,18
-< #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_VERSION "Lua 5.0.2"
-> #define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
+> #define LUA_VERSION "Lua 5.0.3"
+> #define LUA_COPYRIGHT "Copyright (C) 1994-2006 Tecgraf, PUC-Rio"
368c368
-< * Copyright (C) 1994-2003 Tecgraf, PUC-Rio. All rights reserved.
+< * Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved.
+---
+> * Copyright (C) 1994-2006 Tecgraf, PUC-Rio. All rights reserved.
+diff -r lua-5.0.2/src/lapi.c lua-5.0.3/src/lapi.c
+2c2
+< ** $Id: lapi.c,v 1.235 2003/04/07 14:36:08 roberto Exp $
+---
+> ** $Id: lapi.c,v 1.235a 2003/04/07 14:36:08 roberto Exp $
+882c882
+< if (n > f->c.nupvalues) return NULL;
---
-> * Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved.
-diff -r lua-5.0/src/ldo.c lua-5.0.2/src/ldo.c
+> if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
+888c888
+< if (n > p->sizeupvalues) return NULL;
+---
+> if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
+diff -r lua-5.0.2/src/lcode.c lua-5.0.3/src/lcode.c
2c2
-< ** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp $
----
-> ** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
-325,326c325
-< if (nargs >= L->top - L->base)
-< luaG_runerror(L, "cannot resume dead coroutine");
----
-> lua_assert(nargs < L->top - L->base);
-329c328,329
-< else if (ci->state & CI_YIELD) { /* inside a yield? */
----
-> else { /* inside a yield */
-> lua_assert(ci->state & CI_YIELD);
-344,345d343
-< else
-< luaG_runerror(L, "cannot resume non-suspended coroutine");
-351a350,358
-> 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;
+< ** $Id: lcode.c,v 1.117 2003/04/03 13:35:34 roberto Exp $
+---
+> ** $Id: lcode.c,v 1.117a 2003/04/03 13:35:34 roberto Exp $
+105c105,108
+< if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1;
+---
+> if (GET_OPCODE(i) != OP_TEST ||
+> GETARG_A(i) != NO_REG ||
+> GETARG_C(i) != cond)
+> return 1;
+117,118c120,130
+< static void luaK_patchlistaux (FuncState *fs, int list,
+< int ttarget, int treg, int ftarget, int freg, int dtarget) {
+---
+> static void removevalues (FuncState *fs, int list) {
+> for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
+> Instruction *i = getjumpcontrol(fs, list);
+> if (GET_OPCODE(*i) == OP_TEST)
+> patchtestreg(i, NO_REG);
+> }
> }
>
>
-355a363,368
-> 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");
-diff -r lua-5.0/src/lgc.c lua-5.0.2/src/lgc.c
-2c2
-< ** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp $
----
-> ** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
-113c113,114
-< void luaC_separateudata (lua_State *L) {
----
-> size_t luaC_separateudata (lua_State *L) {
-> size_t deadmem = 0;
-127a129
-> deadmem += sizeudata(gcotou(curr)->uv.len);
-136a139
-> return deadmem;
-247c250
-< if (!(ci->state & CI_C) && lim < ci->top)
----
-> if (lim < ci->top)
-390c393
-< static void checkSizes (lua_State *L) {
----
-> static void checkSizes (lua_State *L, size_t deadmem) {
-400c403
-< G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
----
-> G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
-454c457,458
-< static void mark (lua_State *L) {
----
-> static size_t mark (lua_State *L) {
-> size_t deadmem;
-467c471
-< luaC_separateudata(L); /* separate userdata to be preserved */
----
-> deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
-475a480
-> return deadmem;
-480c485
-< mark(L);
----
-> size_t deadmem = mark(L);
-482c487
-< checkSizes(L);
----
-> checkSizes(L, deadmem);
-diff -r lua-5.0/src/lgc.h lua-5.0.2/src/lgc.h
+> static void luaK_patchlistaux (FuncState *fs, int list, int vtarget, int reg,
+> int dtarget) {
+122,136c134,136
+< if (GET_OPCODE(*i) != OP_TEST) {
+< lua_assert(dtarget != NO_JUMP);
+< luaK_fixjump(fs, list, dtarget); /* jump to default target */
+< }
+< else {
+< if (GETARG_C(*i)) {
+< lua_assert(ttarget != NO_JUMP);
+< patchtestreg(i, treg);
+< luaK_fixjump(fs, list, ttarget);
+< }
+< else {
+< lua_assert(ftarget != NO_JUMP);
+< patchtestreg(i, freg);
+< luaK_fixjump(fs, list, ftarget);
+< }
+---
+> if (GET_OPCODE(*i) == OP_TEST && GETARG_A(*i) == NO_REG) {
+> patchtestreg(i, reg);
+> luaK_fixjump(fs, list, vtarget);
+137a138,139
+> else
+> luaK_fixjump(fs, list, dtarget); /* jump to default target */
+144c146
+< luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
+---
+> luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
+154c156
+< luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
+---
+> luaK_patchlistaux(fs, list, target, NO_REG, target);
+357,358c359,360
+< luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
+< luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
+---
+> luaK_patchlistaux(fs, e->f, final, reg, p_f);
+> luaK_patchlistaux(fs, e->t, final, reg, p_t);
+476c478
+< return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
+---
+> return luaK_condjump(fs, OP_TEST, GETARG_B(ie), GETARG_B(ie), !cond);
+566a569,570
+> removevalues(fs, e->f);
+> removevalues(fs, e->t);
+diff -r lua-5.0.2/src/lfunc.c lua-5.0.3/src/lfunc.c
2c2
-< ** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $
----
-> ** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
-18c18
-< void luaC_separateudata (lua_State *L);
----
-> size_t luaC_separateudata (lua_State *L);
-diff -r lua-5.0/src/lib/lbaselib.c lua-5.0.2/src/lib/lbaselib.c
+< ** $Id: lfunc.c,v 1.67 2003/03/18 12:50:04 roberto Exp $
+---
+> ** $Id: lfunc.c,v 1.67a 2003/03/18 12:50:04 roberto Exp $
+19,26d18
+<
+<
+< #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
+< cast(int, sizeof(TObject)*((n)-1)))
+<
+< #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
+< cast(int, sizeof(TObject *)*((n)-1)))
+<
+diff -r lua-5.0.2/src/lfunc.h lua-5.0.3/src/lfunc.h
2c2
-< ** $Id: lbaselib.c,v 1.130 2003/04/03 13:35:34 roberto Exp $
+< ** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp $
---
-> ** $Id: lbaselib.c,v 1.130b 2003/04/03 13:35:34 roberto Exp $
-276a277
-> int n = lua_gettop(L);
-280c281
-< return lua_gettop(L) - 1;
----
-> return lua_gettop(L) - n;
-327c328
-< char buff[64];
----
-> char buff[128];
-diff -r lua-5.0/src/lib/liolib.c lua-5.0.2/src/lib/liolib.c
-2c2
-< ** $Id: liolib.c,v 2.39 2003/03/19 21:16:12 roberto Exp $
----
-> ** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
-161c161
-< if (lua_isnone(L, 1)) {
----
-> if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
-178c178
-< char buff[32];
----
-> char buff[128];
-diff -r lua-5.0/src/lparser.c lua-5.0.2/src/lparser.c
+> ** $Id: lfunc.h,v 1.21a 2003/03/18 12:50:04 roberto Exp $
+11a12,18
+>
+>
+> #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
+> cast(int, sizeof(TObject)*((n)-1)))
+>
+> #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
+> cast(int, sizeof(TObject *)*((n)-1)))
+diff -r lua-5.0.2/src/lgc.c lua-5.0.3/src/lgc.c
2c2
-< ** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp $
----
-> ** $Id: lparser.c,v 1.208a 2003/04/03 13:35:34 roberto Exp $
-1143a1144
-> FuncState *fs = ls->fs;
-1145c1146,1147
-< init_exp(&v, VLOCAL, ls->fs->freereg++);
----
-> init_exp(&v, VLOCAL, fs->freereg);
-> luaK_reserveregs(fs, 1);
-1148c1150,1152
-< 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;
-diff -r lua-5.0/src/luac/Makefile lua-5.0.2/src/luac/Makefile
-16c16
-< $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
----
-> $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
-diff -r lua-5.0/src/luac/luac.c lua-5.0.2/src/luac/luac.c
+< ** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
+---
+> ** $Id: lgc.c,v 1.171b 2003/04/03 13:35:34 roberto Exp $
+221,224c221,222
+< if (!u->marked) {
+< markobject(st, &u->value);
+< u->marked = 1;
+< }
+---
+> markobject(st, u->v);
+> u->marked = 1;
+261c259,260
+< static void propagatemarks (GCState *st) {
+---
+> static lu_mem propagatemarks (GCState *st) {
+> lu_mem mf = 0;
+267a267,268
+> mf += sizeof(Table) + sizeof(TObject) * h->sizearray +
+> sizeof(Node) * sizenode(h);
+273a275,276
+> mf += (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
+> sizeLclosure(cl->l.nupvalues);
+279a283,284
+> mf += sizeof(lua_State) + sizeof(TObject) * th->stacksize +
+> sizeof(CallInfo) * th->size_ci;
+285a291
+> /* do not need 'mf' for this case (cannot happen inside a udata) */
+290a297
+> return mf;
+371c378
+< if (curr->gch.marked > limit) {
+---
+> if ((curr->gch.marked & ~(KEYWEAK | VALUEWEAK)) > limit) {
+473c480
+< propagatemarks(&st); /* remark, to propagate `preserveness' */
+---
+> deadmem += propagatemarks(&st); /* remark, to propagate `preserveness' */
+diff -r lua-5.0.2/src/lib/lbaselib.c lua-5.0.3/src/lib/lbaselib.c
2c2
-< ** $Id: luac.c,v 1.44 2003/04/07 20:34:20 lhf Exp $
----
-> ** $Id: luac.c,v 1.44a 2003/04/07 20:34:20 lhf Exp $
-184a185
-> lua_lock(L);
-185a187
-> lua_unlock(L);
-diff -r lua-5.0/src/lvm.c lua-5.0.2/src/lvm.c
+< ** $Id: lbaselib.c,v 1.130b 2003/04/03 13:35:34 roberto Exp $
+---
+> ** $Id: lbaselib.c,v 1.130c 2003/04/03 13:35:34 roberto Exp $
+175a176
+> lua_settop(L, 2);
+183a185
+> lua_settop(L, 3);
+diff -r lua-5.0.2/src/lib/liolib.c lua-5.0.3/src/lib/liolib.c
2c2
-< ** $Id: lvm.c,v 1.284 2003/04/03 13:35:34 roberto Exp $
----
-> ** $Id: lvm.c,v 1.284b 2003/04/03 13:35:34 roberto Exp $
-69c69
-< if (mask > LUA_MASKLINE) { /* instruction-hook set? */
----
-> if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
-402,403c402,403
-< L->ci->u.l.pc = &pc;
-< if (L->hookmask & LUA_MASKCALL)
----
-> if (L->hookmask & LUA_MASKCALL) {
-> L->ci->u.l.pc = &pc;
-404a405
-> }
-405a407
-> L->ci->u.l.pc = &pc;
-676,678c678
-< 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));
-779a780
+< ** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
+---
+> ** $Id: liolib.c,v 2.39b 2003/03/19 21:16:12 roberto Exp $
+22a23,28
+> typedef struct FileHandle {
+> FILE *f;
+> int ispipe;
+> } FileHandle;
+>
>
-diff -r lua-5.0/test/luac.lua lua-5.0.2/test/luac.lua
-4,6c4,6
-< assert(arg[1]~=nil,"usage: lua luac.lua file.lua")
-< f=assert(io.open("luac.out","w"))
-< f:write(string.dump(loadfile(arg[1])))
----
-> assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
-> f=assert(io.open("luac.out","wb"))
-> f:write(string.dump(assert(loadfile(arg[1]))))
-diff -r lua-5.0/test/table.lua lua-5.0.2/test/table.lua
-8c8
-< local _,_,a,b=string.find(l,'"?(%w+)"?%s*(.*)$')
----
-> local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$')
+89,92c95,98
+< static FILE **topfile (lua_State *L, int findex) {
+< FILE **f = (FILE **)luaL_checkudata(L, findex, FILEHANDLE);
+< if (f == NULL) luaL_argerror(L, findex, "bad file");
+< return f;
+---
+> static FileHandle *topfile (lua_State *L, int findex) {
+> FileHandle *fh = (FileHandle *)luaL_checkudata(L, findex, FILEHANDLE);
+> if (fh == NULL) luaL_argerror(L, findex, "bad file");
+> return fh;
+97,99c103,105
+< FILE **f = (FILE **)luaL_checkudata(L, 1, FILEHANDLE);
+< if (f == NULL) lua_pushnil(L);
+< else if (*f == NULL)
+---
+> FileHandle *fh = (FileHandle *)luaL_checkudata(L, 1, FILEHANDLE);
+> if (fh == NULL) lua_pushnil(L);
+> else if (fh->f == NULL)
+107,109c113,117
+< static FILE *tofile (lua_State *L, int findex) {
+< FILE **f = topfile(L, findex);
+< if (*f == NULL)
+---
+> #define tofile(L,i) (tofileh(L,i)->f)
+>
+> static FileHandle *tofileh (lua_State *L, int findex) {
+> FileHandle *fh = topfile(L, findex);
+> if (fh->f == NULL)
+111c119
+< return *f;
+---
+> return fh;
+115a124,125
+> #define newfile(L) (&(newfileh(L)->f))
+>
+121,123c131,134
+< static FILE **newfile (lua_State *L) {
+< FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
+< *pf = NULL; /* file handle is currently `closed' */
+---
+> static FileHandle *newfileh (lua_State *L) {
+> FileHandle *fh = (FileHandle *)lua_newuserdata(L, sizeof(FileHandle));
+> fh->f = NULL; /* file handle is currently `closed' */
+> fh->ispipe = 0;
+126c137
+< return pf;
+---
+> return fh;
+148c159,160
+< FILE *f = tofile(L, 1);
+---
+> FileHandle *fh = tofileh(L, 1);
+> FILE *f = fh->f;
+152,154c164,165
+< int ok = (pclose(f) != -1) || (fclose(f) == 0);
+< if (ok)
+< *(FILE **)lua_touserdata(L, 1) = NULL; /* mark file as closed */
+---
+> int ok = fh->ispipe ? (pclose(f) != -1) : (fclose(f) == 0);
+> fh->f = NULL; /* mark file as closed */
+170,171c181,182
+< FILE **f = topfile(L, 1);
+< if (*f != NULL) /* ignore closed files */
+---
+> FileHandle *fh = topfile(L, 1);
+> if (fh->f != NULL) /* ignore closed files */
+179,180c190,191
+< FILE **f = topfile(L, 1);
+< if (*f == NULL)
+---
+> FileHandle *fh = topfile(L, 1);
+> if (fh->f == NULL)
+205,207c216,219
+< FILE **pf = newfile(L);
+< *pf = popen(filename, mode);
+< return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
+---
+> FileHandle *fh = newfileh(L);
+> fh->f = popen(filename, mode);
+> fh->ispipe = 1;
+> return (fh->f == NULL) ? pushresult(L, 0, filename) : 1;
+diff -r lua-5.0.2/src/lvm.c lua-5.0.3/src/lvm.c
+2c2
+< ** $Id: lvm.c,v 1.284b 2003/04/03 13:35:34 roberto Exp $
+---
+> ** $Id: lvm.c,v 1.284c 2003/04/03 13:35:34 roberto Exp $
+324,325c324
+< lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
+< cast(lu_mem, tsvalue(top-2)->tsv.len);
+---
+> size_t tl = tsvalue(top-1)->tsv.len;
+328,330c327,331
+< while (n < total && tostring(L, top-n-1)) { /* collect total length */
+< tl += tsvalue(top-n-1)->tsv.len;
+< n++;
+---
+> /* collect total length */
+> for (n = 1; n < total && tostring(L, top-n-1); n++) {
+> size_t l = tsvalue(top-n-1)->tsv.len;
+> if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
+> tl += l;
+332d332
+< if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
diff --git a/MANIFEST b/MANIFEST
index 0c7b8dce..9692b6aa 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,131 +1,131 @@
-MANIFEST contents of Lua 5.0.2 distribution on Wed Mar 17 17:59:01 BRT 2004
-lua-5.0.2
-lua-5.0.2/COPYRIGHT
-lua-5.0.2/DIFFS
-lua-5.0.2/HISTORY
-lua-5.0.2/INSTALL
-lua-5.0.2/MANIFEST
-lua-5.0.2/Makefile
-lua-5.0.2/README
-lua-5.0.2/UPDATE
-lua-5.0.2/bin
-lua-5.0.2/build
-lua-5.0.2/config
-lua-5.0.2/configure
-lua-5.0.2/doc
-lua-5.0.2/doc/contents.html
-lua-5.0.2/doc/logo.gif
-lua-5.0.2/doc/lua.1
-lua-5.0.2/doc/lua.html
-lua-5.0.2/doc/luac.1
-lua-5.0.2/doc/luac.html
-lua-5.0.2/doc/manual.html
-lua-5.0.2/doc/readme.html
-lua-5.0.2/etc
-lua-5.0.2/etc/Makefile
-lua-5.0.2/etc/README
-lua-5.0.2/etc/bin2c.c
-lua-5.0.2/etc/compat.lua
-lua-5.0.2/etc/doall.lua
-lua-5.0.2/etc/lua.ico
-lua-5.0.2/etc/lua.magic
-lua-5.0.2/etc/lua.xpm
-lua-5.0.2/etc/luser_number.h
-lua-5.0.2/etc/luser_tests.h
-lua-5.0.2/etc/min.c
-lua-5.0.2/etc/noparser.c
-lua-5.0.2/etc/saconfig.c
-lua-5.0.2/etc/trace.c
-lua-5.0.2/include
-lua-5.0.2/include/Makefile
-lua-5.0.2/include/lauxlib.h
-lua-5.0.2/include/lua.h
-lua-5.0.2/include/lualib.h
-lua-5.0.2/lib
-lua-5.0.2/src
-lua-5.0.2/src/Makefile
-lua-5.0.2/src/README
-lua-5.0.2/src/lapi.c
-lua-5.0.2/src/lapi.h
-lua-5.0.2/src/lcode.c
-lua-5.0.2/src/lcode.h
-lua-5.0.2/src/ldebug.c
-lua-5.0.2/src/ldebug.h
-lua-5.0.2/src/ldo.c
-lua-5.0.2/src/ldo.h
-lua-5.0.2/src/ldump.c
-lua-5.0.2/src/lfunc.c
-lua-5.0.2/src/lfunc.h
-lua-5.0.2/src/lgc.c
-lua-5.0.2/src/lgc.h
-lua-5.0.2/src/lib
-lua-5.0.2/src/lib/Makefile
-lua-5.0.2/src/lib/README
-lua-5.0.2/src/lib/lauxlib.c
-lua-5.0.2/src/lib/lbaselib.c
-lua-5.0.2/src/lib/ldblib.c
-lua-5.0.2/src/lib/liolib.c
-lua-5.0.2/src/lib/lmathlib.c
-lua-5.0.2/src/lib/loadlib.c
-lua-5.0.2/src/lib/lstrlib.c
-lua-5.0.2/src/lib/ltablib.c
-lua-5.0.2/src/llex.c
-lua-5.0.2/src/llex.h
-lua-5.0.2/src/llimits.h
-lua-5.0.2/src/lmem.c
-lua-5.0.2/src/lmem.h
-lua-5.0.2/src/lobject.c
-lua-5.0.2/src/lobject.h
-lua-5.0.2/src/lopcodes.c
-lua-5.0.2/src/lopcodes.h
-lua-5.0.2/src/lparser.c
-lua-5.0.2/src/lparser.h
-lua-5.0.2/src/lstate.c
-lua-5.0.2/src/lstate.h
-lua-5.0.2/src/lstring.c
-lua-5.0.2/src/lstring.h
-lua-5.0.2/src/ltable.c
-lua-5.0.2/src/ltable.h
-lua-5.0.2/src/ltests.c
-lua-5.0.2/src/ltm.c
-lua-5.0.2/src/ltm.h
-lua-5.0.2/src/lua
-lua-5.0.2/src/lua/Makefile
-lua-5.0.2/src/lua/README
-lua-5.0.2/src/lua/lua.c
-lua-5.0.2/src/luac
-lua-5.0.2/src/luac/Makefile
-lua-5.0.2/src/luac/README
-lua-5.0.2/src/luac/luac.c
-lua-5.0.2/src/luac/print.c
-lua-5.0.2/src/lundump.c
-lua-5.0.2/src/lundump.h
-lua-5.0.2/src/lvm.c
-lua-5.0.2/src/lvm.h
-lua-5.0.2/src/lzio.c
-lua-5.0.2/src/lzio.h
-lua-5.0.2/test
-lua-5.0.2/test/README
-lua-5.0.2/test/bisect.lua
-lua-5.0.2/test/cf.lua
-lua-5.0.2/test/echo.lua
-lua-5.0.2/test/env.lua
-lua-5.0.2/test/factorial.lua
-lua-5.0.2/test/fib.lua
-lua-5.0.2/test/fibfor.lua
-lua-5.0.2/test/globals.lua
-lua-5.0.2/test/hello.lua
-lua-5.0.2/test/life.lua
-lua-5.0.2/test/lua
-lua-5.0.2/test/luac
-lua-5.0.2/test/luac.lua
-lua-5.0.2/test/printf.lua
-lua-5.0.2/test/readonly.lua
-lua-5.0.2/test/sieve.lua
-lua-5.0.2/test/sort.lua
-lua-5.0.2/test/table.lua
-lua-5.0.2/test/trace-calls.lua
-lua-5.0.2/test/trace-globals.lua
-lua-5.0.2/test/undefined.lua
-lua-5.0.2/test/xd.lua
+MANIFEST contents of Lua 5.0.3 distribution on Mon Jun 19 11:04:48 BRT 2006
+lua-5.0.3
+lua-5.0.3/COPYRIGHT
+lua-5.0.3/DIFFS
+lua-5.0.3/HISTORY
+lua-5.0.3/INSTALL
+lua-5.0.3/MANIFEST
+lua-5.0.3/Makefile
+lua-5.0.3/README
+lua-5.0.3/UPDATE
+lua-5.0.3/bin
+lua-5.0.3/build
+lua-5.0.3/config
+lua-5.0.3/configure
+lua-5.0.3/doc
+lua-5.0.3/doc/contents.html
+lua-5.0.3/doc/logo.gif
+lua-5.0.3/doc/lua.1
+lua-5.0.3/doc/lua.html
+lua-5.0.3/doc/luac.1
+lua-5.0.3/doc/luac.html
+lua-5.0.3/doc/manual.html
+lua-5.0.3/doc/readme.html
+lua-5.0.3/etc
+lua-5.0.3/etc/Makefile
+lua-5.0.3/etc/README
+lua-5.0.3/etc/bin2c.c
+lua-5.0.3/etc/compat.lua
+lua-5.0.3/etc/doall.lua
+lua-5.0.3/etc/lua.ico
+lua-5.0.3/etc/lua.magic
+lua-5.0.3/etc/lua.xpm
+lua-5.0.3/etc/luser_number.h
+lua-5.0.3/etc/luser_tests.h
+lua-5.0.3/etc/min.c
+lua-5.0.3/etc/noparser.c
+lua-5.0.3/etc/saconfig.c
+lua-5.0.3/etc/trace.c
+lua-5.0.3/include
+lua-5.0.3/include/Makefile
+lua-5.0.3/include/lauxlib.h
+lua-5.0.3/include/lua.h
+lua-5.0.3/include/lualib.h
+lua-5.0.3/lib
+lua-5.0.3/src
+lua-5.0.3/src/Makefile
+lua-5.0.3/src/README
+lua-5.0.3/src/lapi.c
+lua-5.0.3/src/lapi.h
+lua-5.0.3/src/lcode.c
+lua-5.0.3/src/lcode.h
+lua-5.0.3/src/ldebug.c
+lua-5.0.3/src/ldebug.h
+lua-5.0.3/src/ldo.c
+lua-5.0.3/src/ldo.h
+lua-5.0.3/src/ldump.c
+lua-5.0.3/src/lfunc.c
+lua-5.0.3/src/lfunc.h
+lua-5.0.3/src/lgc.c
+lua-5.0.3/src/lgc.h
+lua-5.0.3/src/lib
+lua-5.0.3/src/lib/Makefile
+lua-5.0.3/src/lib/README
+lua-5.0.3/src/lib/lauxlib.c
+lua-5.0.3/src/lib/lbaselib.c
+lua-5.0.3/src/lib/ldblib.c
+lua-5.0.3/src/lib/liolib.c
+lua-5.0.3/src/lib/lmathlib.c
+lua-5.0.3/src/lib/loadlib.c
+lua-5.0.3/src/lib/lstrlib.c
+lua-5.0.3/src/lib/ltablib.c
+lua-5.0.3/src/llex.c
+lua-5.0.3/src/llex.h
+lua-5.0.3/src/llimits.h
+lua-5.0.3/src/lmem.c
+lua-5.0.3/src/lmem.h
+lua-5.0.3/src/lobject.c
+lua-5.0.3/src/lobject.h
+lua-5.0.3/src/lopcodes.c
+lua-5.0.3/src/lopcodes.h
+lua-5.0.3/src/lparser.c
+lua-5.0.3/src/lparser.h
+lua-5.0.3/src/lstate.c
+lua-5.0.3/src/lstate.h
+lua-5.0.3/src/lstring.c
+lua-5.0.3/src/lstring.h
+lua-5.0.3/src/ltable.c
+lua-5.0.3/src/ltable.h
+lua-5.0.3/src/ltests.c
+lua-5.0.3/src/ltm.c
+lua-5.0.3/src/ltm.h
+lua-5.0.3/src/lua
+lua-5.0.3/src/lua/Makefile
+lua-5.0.3/src/lua/README
+lua-5.0.3/src/lua/lua.c
+lua-5.0.3/src/luac
+lua-5.0.3/src/luac/Makefile
+lua-5.0.3/src/luac/README
+lua-5.0.3/src/luac/luac.c
+lua-5.0.3/src/luac/print.c
+lua-5.0.3/src/lundump.c
+lua-5.0.3/src/lundump.h
+lua-5.0.3/src/lvm.c
+lua-5.0.3/src/lvm.h
+lua-5.0.3/src/lzio.c
+lua-5.0.3/src/lzio.h
+lua-5.0.3/test
+lua-5.0.3/test/README
+lua-5.0.3/test/bisect.lua
+lua-5.0.3/test/cf.lua
+lua-5.0.3/test/echo.lua
+lua-5.0.3/test/env.lua
+lua-5.0.3/test/factorial.lua
+lua-5.0.3/test/fib.lua
+lua-5.0.3/test/fibfor.lua
+lua-5.0.3/test/globals.lua
+lua-5.0.3/test/hello.lua
+lua-5.0.3/test/life.lua
+lua-5.0.3/test/lua
+lua-5.0.3/test/luac
+lua-5.0.3/test/luac.lua
+lua-5.0.3/test/printf.lua
+lua-5.0.3/test/readonly.lua
+lua-5.0.3/test/sieve.lua
+lua-5.0.3/test/sort.lua
+lua-5.0.3/test/table.lua
+lua-5.0.3/test/trace-calls.lua
+lua-5.0.3/test/trace-globals.lua
+lua-5.0.3/test/undefined.lua
+lua-5.0.3/test/xd.lua
END OF MANIFEST
diff --git a/include/lua.h b/include/lua.h
index 88b0191e..bd4acc9a 100644
--- a/include/lua.h
+++ b/include/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
+** $Id: lua.h,v 1.175c 2003/03/18 12:31:39 roberto Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -14,8 +14,8 @@
#include <stddef.h>
-#define LUA_VERSION "Lua 5.0.2"
-#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
+#define LUA_VERSION "Lua 5.0.3"
+#define LUA_COPYRIGHT "Copyright (C) 1994-2006 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -365,7 +365,7 @@ struct lua_Debug {
/******************************************************************************
-* Copyright (C) 1994-2004 Tecgraf, PUC-Rio. All rights reserved.
+* Copyright (C) 1994-2006 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
diff --git a/src/lapi.c b/src/lapi.c
index d5dd9ca4..2ed4c634 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.235 2003/04/07 14:36:08 roberto Exp $
+** $Id: lapi.c,v 1.235a 2003/04/07 14:36:08 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -879,13 +879,13 @@ static const char *aux_upvalue (lua_State *L, int funcindex, int n,
if (!ttisfunction(fi)) return NULL;
f = clvalue(fi);
if (f->c.isC) {
- if (n > f->c.nupvalues) return NULL;
+ if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
*val = &f->c.upvalue[n-1];
return "";
}
else {
Proto *p = f->l.p;
- if (n > p->sizeupvalues) return NULL;
+ if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
*val = f->l.upvals[n-1]->v;
return getstr(p->upvalues[n-1]);
}
diff --git a/src/lcode.c b/src/lcode.c
index d626ecd6..3925c976 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 1.117 2003/04/03 13:35:34 roberto Exp $
+** $Id: lcode.c,v 1.117a 2003/04/03 13:35:34 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -102,7 +102,10 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) {
static int need_value (FuncState *fs, int list, int cond) {
for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
Instruction i = *getjumpcontrol(fs, list);
- if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1;
+ if (GET_OPCODE(i) != OP_TEST ||
+ GETARG_A(i) != NO_REG ||
+ GETARG_C(i) != cond)
+ return 1;
}
return 0; /* not found */
}
@@ -114,34 +117,33 @@ static void patchtestreg (Instruction *i, int reg) {
}
-static void luaK_patchlistaux (FuncState *fs, int list,
- int ttarget, int treg, int ftarget, int freg, int dtarget) {
+static void removevalues (FuncState *fs, int list) {
+ for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
+ Instruction *i = getjumpcontrol(fs, list);
+ if (GET_OPCODE(*i) == OP_TEST)
+ patchtestreg(i, NO_REG);
+ }
+}
+
+
+static void luaK_patchlistaux (FuncState *fs, int list, int vtarget, int reg,
+ int dtarget) {
while (list != NO_JUMP) {
int next = luaK_getjump(fs, list);
Instruction *i = getjumpcontrol(fs, list);
- if (GET_OPCODE(*i) != OP_TEST) {
- lua_assert(dtarget != NO_JUMP);
- luaK_fixjump(fs, list, dtarget); /* jump to default target */
- }
- else {
- if (GETARG_C(*i)) {
- lua_assert(ttarget != NO_JUMP);
- patchtestreg(i, treg);
- luaK_fixjump(fs, list, ttarget);
- }
- else {
- lua_assert(ftarget != NO_JUMP);
- patchtestreg(i, freg);
- luaK_fixjump(fs, list, ftarget);
- }
+ if (GET_OPCODE(*i) == OP_TEST && GETARG_A(*i) == NO_REG) {
+ patchtestreg(i, reg);
+ luaK_fixjump(fs, list, vtarget);
}
+ else
+ luaK_fixjump(fs, list, dtarget); /* jump to default target */
list = next;
}
}
static void luaK_dischargejpc (FuncState *fs) {
- luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
+ luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
fs->jpc = NO_JUMP;
}
@@ -151,7 +153,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) {
luaK_patchtohere(fs, list);
else {
lua_assert(target < fs->pc);
- luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
+ luaK_patchlistaux(fs, list, target, NO_REG, target);
}
}
@@ -354,8 +356,8 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
luaK_patchtohere(fs, fj);
}
final = luaK_getlabel(fs);
- luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
- luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
+ luaK_patchlistaux(fs, e->f, final, reg, p_f);
+ luaK_patchlistaux(fs, e->t, final, reg, p_t);
}
e->f = e->t = NO_JUMP;
e->info = reg;
@@ -473,7 +475,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) {
Instruction ie = getcode(fs, e);
if (GET_OPCODE(ie) == OP_NOT) {
fs->pc--; /* remove previous OP_NOT */
- return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
+ return luaK_condjump(fs, OP_TEST, GETARG_B(ie), GETARG_B(ie), !cond);
}
/* else go through */
}
@@ -564,6 +566,8 @@ static void codenot (FuncState *fs, expdesc *e) {
}
/* interchange true and false lists */
{ int temp = e->f; e->f = e->t; e->t = temp; }
+ removevalues(fs, e->f);
+ removevalues(fs, e->t);
}
diff --git a/src/lfunc.c b/src/lfunc.c
index 31044fa5..97c5d9bb 100644
--- a/src/lfunc.c
+++ b/src/lfunc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lfunc.c,v 1.67 2003/03/18 12:50:04 roberto Exp $
+** $Id: lfunc.c,v 1.67a 2003/03/18 12:50:04 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -18,14 +18,6 @@
#include "lstate.h"
-#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
- cast(int, sizeof(TObject)*((n)-1)))
-
-#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
- cast(int, sizeof(TObject *)*((n)-1)))
-
-
-
Closure *luaF_newCclosure (lua_State *L, int nelems) {
Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
luaC_link(L, valtogco(c), LUA_TFUNCTION);
diff --git a/src/lfunc.h b/src/lfunc.h
index 5d532507..dc61e2ed 100644
--- a/src/lfunc.h
+++ b/src/lfunc.h
@@ -1,5 +1,5 @@
/*
-** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp $
+** $Id: lfunc.h,v 1.21a 2003/03/18 12:50:04 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -11,6 +11,13 @@
#include "lobject.h"
+#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
+ cast(int, sizeof(TObject)*((n)-1)))
+
+#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
+ cast(int, sizeof(TObject *)*((n)-1)))
+
+
Proto *luaF_newproto (lua_State *L);
Closure *luaF_newCclosure (lua_State *L, int nelems);
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e);
diff --git a/src/lgc.c b/src/lgc.c
index 5e036d38..b44f2017 100644
--- a/src/lgc.c
+++ b/src/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
+** $Id: lgc.c,v 1.171b 2003/04/03 13:35:34 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -218,10 +218,8 @@ static void traverseclosure (GCState *st, Closure *cl) {
markvalue(st, cl->l.p);
for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */
UpVal *u = cl->l.upvals[i];
- if (!u->marked) {
- markobject(st, &u->value);
- u->marked = 1;
- }
+ markobject(st, u->v);
+ u->marked = 1;
}
}
}
@@ -258,36 +256,45 @@ static void traversestack (GCState *st, lua_State *L1) {
}
-static void propagatemarks (GCState *st) {
+static lu_mem propagatemarks (GCState *st) {
+ lu_mem mf = 0;
while (st->tmark) { /* traverse marked objects */
switch (st->tmark->gch.tt) {
case LUA_TTABLE: {
Table *h = gcotoh(st->tmark);
st->tmark = h->gclist;
traversetable(st, h);
+ mf += sizeof(Table) + sizeof(TObject) * h->sizearray +
+ sizeof(Node) * sizenode(h);
break;
}
case LUA_TFUNCTION: {
Closure *cl = gcotocl(st->tmark);
st->tmark = cl->c.gclist;
traverseclosure(st, cl);
+ mf += (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
+ sizeLclosure(cl->l.nupvalues);
break;
}
case LUA_TTHREAD: {
lua_State *th = gcototh(st->tmark);
st->tmark = th->gclist;
traversestack(st, th);
+ mf += sizeof(lua_State) + sizeof(TObject) * th->stacksize +
+ sizeof(CallInfo) * th->size_ci;
break;
}
case LUA_TPROTO: {
Proto *p = gcotop(st->tmark);
st->tmark = p->gclist;
traverseproto(st, p);
+ /* do not need 'mf' for this case (cannot happen inside a udata) */
break;
}
default: lua_assert(0);
}
}
+ return mf;
}
@@ -368,7 +375,7 @@ static int sweeplist (lua_State *L, GCObject **p, int limit) {
GCObject *curr;
int count = 0; /* number of collected items */
while ((curr = *p) != NULL) {
- if (curr->gch.marked > limit) {
+ if ((curr->gch.marked & ~(KEYWEAK | VALUEWEAK)) > limit) {
unmark(curr);
p = &curr->gch.next;
}
@@ -470,7 +477,7 @@ static size_t mark (lua_State *L) {
st.wv = NULL;
deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
marktmu(&st); /* mark `preserved' userdata */
- propagatemarks(&st); /* remark, to propagate `preserveness' */
+ deadmem += propagatemarks(&st); /* remark, to propagate `preserveness' */
cleartablekeys(wkv);
/* `propagatemarks' may resuscitate some weak tables; clear them too */
cleartablekeys(st.wk);
diff --git a/src/lib/lbaselib.c b/src/lib/lbaselib.c
index b6a4baed..fb26a54a 100644
--- a/src/lib/lbaselib.c
+++ b/src/lib/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.130b 2003/04/03 13:35:34 roberto Exp $
+** $Id: lbaselib.c,v 1.130c 2003/04/03 13:35:34 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -173,6 +173,7 @@ static int luaB_rawequal (lua_State *L) {
static int luaB_rawget (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checkany(L, 2);
+ lua_settop(L, 2);
lua_rawget(L, 1);
return 1;
}
@@ -181,6 +182,7 @@ static int luaB_rawset (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checkany(L, 2);
luaL_checkany(L, 3);
+ lua_settop(L, 3);
lua_rawset(L, 1);
return 1;
}
diff --git a/src/lib/liolib.c b/src/lib/liolib.c
index 96b38831..bcadcdfd 100644
--- a/src/lib/liolib.c
+++ b/src/lib/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
+** $Id: liolib.c,v 2.39b 2003/03/19 21:16:12 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -20,6 +20,12 @@
#include "lualib.h"
+typedef struct FileHandle {
+ FILE *f;
+ int ispipe;
+} FileHandle;
+
+
/*
** by default, gcc does not get `tmpname'
@@ -86,17 +92,17 @@ static int pushresult (lua_State *L, int i, const char *filename) {
}
-static FILE **topfile (lua_State *L, int findex) {
- FILE **f = (FILE **)luaL_checkudata(L, findex, FILEHANDLE);
- if (f == NULL) luaL_argerror(L, findex, "bad file");
- return f;
+static FileHandle *topfile (lua_State *L, int findex) {
+ FileHandle *fh = (FileHandle *)luaL_checkudata(L, findex, FILEHANDLE);
+ if (fh == NULL) luaL_argerror(L, findex, "bad file");
+ return fh;
}
static int io_type (lua_State *L) {
- FILE **f = (FILE **)luaL_checkudata(L, 1, FILEHANDLE);
- if (f == NULL) lua_pushnil(L);
- else if (*f == NULL)
+ FileHandle *fh = (FileHandle *)luaL_checkudata(L, 1, FILEHANDLE);
+ if (fh == NULL) lua_pushnil(L);
+ else if (fh->f == NULL)
lua_pushliteral(L, "closed file");
else
lua_pushliteral(L, "file");
@@ -104,26 +110,31 @@ static int io_type (lua_State *L) {
}
-static FILE *tofile (lua_State *L, int findex) {
- FILE **f = topfile(L, findex);
- if (*f == NULL)
+#define tofile(L,i) (tofileh(L,i)->f)
+
+static FileHandle *tofileh (lua_State *L, int findex) {
+ FileHandle *fh = topfile(L, findex);
+ if (fh->f == NULL)
luaL_error(L, "attempt to use a closed file");
- return *f;
+ return fh;
}
+#define newfile(L) (&(newfileh(L)->f))
+
/*
** When creating file handles, always creates a `closed' file handle
** before opening the actual file; so, if there is a memory error, the
** file is not left opened.
*/
-static FILE **newfile (lua_State *L) {
- FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
- *pf = NULL; /* file handle is currently `closed' */
+static FileHandle *newfileh (lua_State *L) {
+ FileHandle *fh = (FileHandle *)lua_newuserdata(L, sizeof(FileHandle));
+ fh->f = NULL; /* file handle is currently `closed' */
+ fh->ispipe = 0;
luaL_getmetatable(L, FILEHANDLE);
lua_setmetatable(L, -2);
- return pf;
+ return fh;
}
@@ -145,13 +156,13 @@ static void registerfile (lua_State *L, FILE *f, const char *name,
static int aux_close (lua_State *L) {
- FILE *f = tofile(L, 1);
+ FileHandle *fh = tofileh(L, 1);
+ FILE *f = fh->f;
if (f == stdin || f == stdout || f == stderr)
return 0; /* file cannot be closed */
else {
- int ok = (pclose(f) != -1) || (fclose(f) == 0);
- if (ok)
- *(FILE **)lua_touserdata(L, 1) = NULL; /* mark file as closed */
+ int ok = fh->ispipe ? (pclose(f) != -1) : (fclose(f) == 0);
+ fh->f = NULL; /* mark file as closed */
return ok;
}
}
@@ -167,8 +178,8 @@ static int io_close (lua_State *L) {
static int io_gc (lua_State *L) {
- FILE **f = topfile(L, 1);
- if (*f != NULL) /* ignore closed files */
+ FileHandle *fh = topfile(L, 1);
+ if (fh->f != NULL) /* ignore closed files */
aux_close(L);
return 0;
}
@@ -176,8 +187,8 @@ static int io_gc (lua_State *L) {
static int io_tostring (lua_State *L) {
char buff[128];
- FILE **f = topfile(L, 1);
- if (*f == NULL)
+ FileHandle *fh = topfile(L, 1);
+ if (fh->f == NULL)
strcpy(buff, "closed");
else
sprintf(buff, "%p", lua_touserdata(L, 1));
@@ -202,9 +213,10 @@ static int io_popen (lua_State *L) {
#else
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
- FILE **pf = newfile(L);
- *pf = popen(filename, mode);
- return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
+ FileHandle *fh = newfileh(L);
+ fh->f = popen(filename, mode);
+ fh->ispipe = 1;
+ return (fh->f == NULL) ? pushresult(L, 0, filename) : 1;
#endif
}
diff --git a/src/lvm.c b/src/lvm.c
index 94e2802d..95132931 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.284b 2003/04/03 13:35:34 roberto Exp $
+** $Id: lvm.c,v 1.284c 2003/04/03 13:35:34 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -321,15 +321,15 @@ void luaV_concat (lua_State *L, int total, int last) {
luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */
- lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
- cast(lu_mem, tsvalue(top-2)->tsv.len);
+ size_t tl = tsvalue(top-1)->tsv.len;
char *buffer;
int i;
- while (n < total && tostring(L, top-n-1)) { /* collect total length */
- tl += tsvalue(top-n-1)->tsv.len;
- n++;
+ /* collect total length */
+ for (n = 1; n < total && tostring(L, top-n-1); n++) {
+ size_t l = tsvalue(top-n-1)->tsv.len;
+ if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
+ tl += l;
}
- if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
buffer = luaZ_openspace(L, &G(L)->buff, tl);
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */