From bd619b931173fc35f38dfbb07746bcdc5ef11808 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 31 May 2010 13:08:55 -0300 Subject: new macro MAXUPVAL (maximum number of upvalues per closure) --- lapi.c | 6 +++--- llimits.h | 7 ++++++- lparser.c | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lapi.c b/lapi.c index 274802ef..95be89d5 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.128 2010/05/12 14:09:20 roberto Exp roberto $ +** $Id: lapi.c,v 2.129 2010/05/14 13:15:26 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -55,7 +55,7 @@ static TValue *index2addr (lua_State *L, int idx) { return &G(L)->l_registry; else { /* upvalues */ idx = LUA_REGISTRYINDEX - idx; - api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large"); + api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); if (ttislcf(ci->func)) /* light C function? */ return cast(TValue *, luaO_nilobject); /* it has no upvalues */ else { @@ -507,7 +507,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { else { Closure *cl; api_checknelems(L, n); - api_check(L, n <= UCHAR_MAX, "upvalue index too large"); + api_check(L, n <= MAXUPVAL, "upvalue index too large"); luaC_checkGC(L); cl = luaF_newCclosure(L, n); cl->c.f = fn; diff --git a/llimits.h b/llimits.h index 92300896..b7c7bc50 100644 --- a/llimits.h +++ b/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.80 2010/05/07 18:44:12 roberto Exp roberto $ +** $Id: llimits.h,v 1.81 2010/05/24 19:29:46 roberto Exp roberto $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ @@ -97,6 +97,11 @@ typedef LUAI_UACNUMBER l_uacNumber; #define LUAI_MAXCCALLS 200 #endif +/* +** maximum number of upvalues in a closure (both C and Lua). (Value +** must fit in an unsigned char.) +*/ +#define MAXUPVAL UCHAR_MAX /* diff --git a/lparser.c b/lparser.c index 58c8fb97..a45b53ce 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.85 2010/05/14 15:03:43 roberto Exp roberto $ +** $Id: lparser.c,v 2.86 2010/05/15 13:32:02 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -221,9 +221,9 @@ static int searchupvalue (FuncState *fs, TString *name) { static int newupvalue (FuncState *fs, TString *name, expdesc *v) { Proto *f = fs->f; int oldsize = f->sizeupvalues; - checklimit(fs, fs->nups + 1, UCHAR_MAX, "upvalues"); + checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, - Upvaldesc, UCHAR_MAX, "upvalues"); + Upvaldesc, MAXUPVAL, "upvalues"); while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; f->upvalues[fs->nups].instack = (v->k == VLOCAL); f->upvalues[fs->nups].idx = cast_byte(v->u.s.info); -- cgit v1.2.3-55-g6feb