diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-31 13:08:55 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-31 13:08:55 -0300 |
| commit | bd619b931173fc35f38dfbb07746bcdc5ef11808 (patch) | |
| tree | 2fdcf32609e853c0490af52a9590a40982749a8e | |
| parent | aca84ee1a04987f7cfe8c4e4126c953351d1216f (diff) | |
| download | lua-bd619b931173fc35f38dfbb07746bcdc5ef11808.tar.gz lua-bd619b931173fc35f38dfbb07746bcdc5ef11808.tar.bz2 lua-bd619b931173fc35f38dfbb07746bcdc5ef11808.zip | |
new macro MAXUPVAL (maximum number of upvalues per closure)
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | llimits.h | 7 | ||||
| -rw-r--r-- | lparser.c | 6 |
3 files changed, 12 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.128 2010/05/12 14:09:20 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.129 2010/05/14 13:15:26 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -55,7 +55,7 @@ static TValue *index2addr (lua_State *L, int idx) { | |||
| 55 | return &G(L)->l_registry; | 55 | return &G(L)->l_registry; |
| 56 | else { /* upvalues */ | 56 | else { /* upvalues */ |
| 57 | idx = LUA_REGISTRYINDEX - idx; | 57 | idx = LUA_REGISTRYINDEX - idx; |
| 58 | api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large"); | 58 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
| 59 | if (ttislcf(ci->func)) /* light C function? */ | 59 | if (ttislcf(ci->func)) /* light C function? */ |
| 60 | return cast(TValue *, luaO_nilobject); /* it has no upvalues */ | 60 | return cast(TValue *, luaO_nilobject); /* it has no upvalues */ |
| 61 | else { | 61 | else { |
| @@ -507,7 +507,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
| 507 | else { | 507 | else { |
| 508 | Closure *cl; | 508 | Closure *cl; |
| 509 | api_checknelems(L, n); | 509 | api_checknelems(L, n); |
| 510 | api_check(L, n <= UCHAR_MAX, "upvalue index too large"); | 510 | api_check(L, n <= MAXUPVAL, "upvalue index too large"); |
| 511 | luaC_checkGC(L); | 511 | luaC_checkGC(L); |
| 512 | cl = luaF_newCclosure(L, n); | 512 | cl = luaF_newCclosure(L, n); |
| 513 | cl->c.f = fn; | 513 | cl->c.f = fn; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.80 2010/05/07 18:44:12 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.81 2010/05/24 19:29:46 roberto Exp roberto $ |
| 3 | ** Limits, basic types, and some other `installation-dependent' definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -97,6 +97,11 @@ typedef LUAI_UACNUMBER l_uacNumber; | |||
| 97 | #define LUAI_MAXCCALLS 200 | 97 | #define LUAI_MAXCCALLS 200 |
| 98 | #endif | 98 | #endif |
| 99 | 99 | ||
| 100 | /* | ||
| 101 | ** maximum number of upvalues in a closure (both C and Lua). (Value | ||
| 102 | ** must fit in an unsigned char.) | ||
| 103 | */ | ||
| 104 | #define MAXUPVAL UCHAR_MAX | ||
| 100 | 105 | ||
| 101 | 106 | ||
| 102 | /* | 107 | /* |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.85 2010/05/14 15:03:43 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.86 2010/05/15 13:32:02 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -221,9 +221,9 @@ static int searchupvalue (FuncState *fs, TString *name) { | |||
| 221 | static int newupvalue (FuncState *fs, TString *name, expdesc *v) { | 221 | static int newupvalue (FuncState *fs, TString *name, expdesc *v) { |
| 222 | Proto *f = fs->f; | 222 | Proto *f = fs->f; |
| 223 | int oldsize = f->sizeupvalues; | 223 | int oldsize = f->sizeupvalues; |
| 224 | checklimit(fs, fs->nups + 1, UCHAR_MAX, "upvalues"); | 224 | checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); |
| 225 | luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, | 225 | luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, |
| 226 | Upvaldesc, UCHAR_MAX, "upvalues"); | 226 | Upvaldesc, MAXUPVAL, "upvalues"); |
| 227 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; | 227 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; |
| 228 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); | 228 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); |
| 229 | f->upvalues[fs->nups].idx = cast_byte(v->u.s.info); | 229 | f->upvalues[fs->nups].idx = cast_byte(v->u.s.info); |
