diff options
| -rw-r--r-- | lapi.c | 3 | ||||
| -rw-r--r-- | ldo.c | 32 | ||||
| -rw-r--r-- | ldo.h | 12 | ||||
| -rw-r--r-- | lgc.h | 6 | ||||
| -rw-r--r-- | llimits.h | 11 | ||||
| -rw-r--r-- | lvm.c | 16 |
6 files changed, 42 insertions, 38 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.45 2005/07/06 18:07:30 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.46 2005/07/31 17:12:32 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 | */ |
| @@ -344,6 +344,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
| 344 | return NULL; | 344 | return NULL; |
| 345 | } | 345 | } |
| 346 | luaC_checkGC(L); | 346 | luaC_checkGC(L); |
| 347 | o = index2adr(L, idx); /* previous call may reallocate the stack */ | ||
| 347 | lua_unlock(L); | 348 | lua_unlock(L); |
| 348 | } | 349 | } |
| 349 | if (len != NULL) *len = tsvalue(o)->len; | 350 | if (len != NULL) *len = tsvalue(o)->len; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.30 2005/08/22 18:54:49 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.31 2005/08/22 19:58:29 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -205,19 +205,17 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | 207 | ||
| 208 | static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, | 208 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { |
| 209 | int style) { | ||
| 210 | int i; | 209 | int i; |
| 210 | int nfixargs = p->numparams; | ||
| 211 | Table *htab = NULL; | 211 | Table *htab = NULL; |
| 212 | StkId base, fixed; | 212 | StkId base, fixed; |
| 213 | if (actual < nfixargs) { | 213 | for (; actual < nfixargs; ++actual) |
| 214 | for (; actual < nfixargs; ++actual) | 214 | setnilvalue(L->top++); |
| 215 | setnilvalue(L->top++); | ||
| 216 | } | ||
| 217 | #if defined(LUA_COMPAT_VARARG) | 215 | #if defined(LUA_COMPAT_VARARG) |
| 218 | if (style & VARARG_NEEDSARG) { /* compatibility with old-style vararg */ | 216 | if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ |
| 219 | int nvar = actual - nfixargs; /* number of extra arguments */ | 217 | int nvar = actual - nfixargs; /* number of extra arguments */ |
| 220 | lua_assert(style & VARARG_HASARG); | 218 | lua_assert(p->is_vararg & VARARG_HASARG); |
| 221 | luaC_checkGC(L); | 219 | luaC_checkGC(L); |
| 222 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ | 220 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
| 223 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ | 221 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| @@ -276,16 +274,14 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 276 | CallInfo *ci; | 274 | CallInfo *ci; |
| 277 | StkId st, base; | 275 | StkId st, base; |
| 278 | Proto *p = cl->p; | 276 | Proto *p = cl->p; |
| 279 | if (p->is_vararg) { /* varargs? */ | 277 | luaD_checkstack(L, p->maxstacksize); |
| 280 | int nargs = cast(int, L->top - restorestack(L, funcr)) - 1; | 278 | func = restorestack(L, funcr); |
| 281 | luaD_checkstack(L, p->maxstacksize + nargs); | 279 | if (!p->is_vararg) /* no varargs? */ |
| 282 | base = adjust_varargs(L, p->numparams, nargs, p->is_vararg); | ||
| 283 | func = restorestack(L, funcr); | ||
| 284 | } | ||
| 285 | else { | ||
| 286 | luaD_checkstack(L, p->maxstacksize); | ||
| 287 | func = restorestack(L, funcr); | ||
| 288 | base = func + 1; | 280 | base = func + 1; |
| 281 | else { /* vararg function */ | ||
| 282 | int nargs = cast(int, L->top - func) - 1; | ||
| 283 | base = adjust_varargs(L, p, nargs); | ||
| 284 | func = restorestack(L, funcr); /* previous call may change the stack */ | ||
| 289 | } | 285 | } |
| 290 | ci = inc_ci(L); /* now `enter' new function */ | 286 | ci = inc_ci(L); /* now `enter' new function */ |
| 291 | ci->func = func; | 287 | ci->func = func; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 2.5 2005/08/22 18:54:49 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 2.6 2005/08/22 19:58:29 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -13,16 +13,6 @@ | |||
| 13 | #include "lzio.h" | 13 | #include "lzio.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | /* | ||
| 17 | ** macro to control inclusion of some hard tests on stack reallocation | ||
| 18 | */ | ||
| 19 | #ifndef HARDSTACKTESTS | ||
| 20 | #define condhardstacktests(x) ((void)0) | ||
| 21 | #else | ||
| 22 | #define condhardstacktests(x) x | ||
| 23 | #endif | ||
| 24 | |||
| 25 | |||
| 26 | #define luaD_checkstack(L,n) \ | 16 | #define luaD_checkstack(L,n) \ |
| 27 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ | 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ |
| 28 | luaD_growstack(L, n); \ | 18 | luaD_growstack(L, n); \ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.13 2005/04/25 19:24:10 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.14 2005/06/07 18:53:45 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -77,7 +77,9 @@ | |||
| 77 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) | 77 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | #define luaC_checkGC(L) { if (G(L)->totalbytes >= G(L)->GCthreshold) \ | 80 | #define luaC_checkGC(L) { \ |
| 81 | condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ | ||
| 82 | if (G(L)->totalbytes >= G(L)->GCthreshold) \ | ||
| 81 | luaC_step(L); } | 83 | luaC_step(L); } |
| 82 | 84 | ||
| 83 | 85 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.65 2005/03/09 16:28:07 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.66 2005/08/04 13:37:10 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 | */ |
| @@ -103,4 +103,13 @@ typedef lu_int32 Instruction; | |||
| 103 | #endif | 103 | #endif |
| 104 | 104 | ||
| 105 | 105 | ||
| 106 | /* | ||
| 107 | ** macro to control inclusion of some hard tests on stack reallocation | ||
| 108 | */ | ||
| 109 | #ifndef HARDSTACKTESTS | ||
| 110 | #define condhardstacktests(x) ((void)0) | ||
| 111 | #else | ||
| 112 | #define condhardstacktests(x) x | ||
| 113 | #endif | ||
| 114 | |||
| 106 | #endif | 115 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.51 2005/08/10 20:20:13 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.52 2005/08/22 18:54:49 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -763,13 +763,19 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 763 | CallInfo *ci = L->ci; | 763 | CallInfo *ci = L->ci; |
| 764 | int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1; | 764 | int n = cast(int, ci->base - ci->func) - cl->p->numparams - 1; |
| 765 | if (b == LUA_MULTRET) { | 765 | if (b == LUA_MULTRET) { |
| 766 | Protect(luaD_checkstack(L, n)); | ||
| 767 | ra = RA(i); /* previous call may change the stack */ | ||
| 766 | b = n; | 768 | b = n; |
| 767 | L->top = ra + n; | 769 | L->top = ra + n; |
| 768 | } | 770 | } |
| 769 | for (j=0; j<b && j<n; j++) | 771 | for (j = 0; j < b; j++) { |
| 770 | setobjs2s(L, ra+j, ci->base - n + j); | 772 | if (j < n) { |
| 771 | for (; j<b; j++) | 773 | setobjs2s(L, ra + j, ci->base - n + j); |
| 772 | setnilvalue(ra+j); | 774 | } |
| 775 | else { | ||
| 776 | setnilvalue(ra + j); | ||
| 777 | } | ||
| 778 | } | ||
| 773 | continue; | 779 | continue; |
| 774 | } | 780 | } |
| 775 | } | 781 | } |
