diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-25 13:55:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-25 13:55:29 -0300 |
commit | 9a37dc0ce64c51fd57f5e658a5af8f3671a26b0a (patch) | |
tree | 32d5d49d87ea9124c8209803d1ac78c94ec7a881 /lapi.h | |
parent | 0eb6aa4013051c8c0148c09d8c85ee7cbdc96f42 (diff) | |
download | lua-9a37dc0ce64c51fd57f5e658a5af8f3671a26b0a.tar.gz lua-9a37dc0ce64c51fd57f5e658a5af8f3671a26b0a.tar.bz2 lua-9a37dc0ce64c51fd57f5e658a5af8f3671a26b0a.zip |
Small corrections when setting 'L->top'
- OP_NEWTABLE can use 'ra + 1' to set top (instead of ci->top);
- OP_CLOSE doesn't need to set top ('Protect' already does that);
- OP_TFORCALL must use 'ProtectNT', to preserve the top already set.
(That was a small bug, because iterators could be called with
extra parameters besides the state and the control variable.)
- Comments and an extra test for the bug in previous item.
Diffstat (limited to 'lapi.h')
-rw-r--r-- | lapi.h | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -11,12 +11,22 @@ | |||
11 | #include "llimits.h" | 11 | #include "llimits.h" |
12 | #include "lstate.h" | 12 | #include "lstate.h" |
13 | 13 | ||
14 | |||
15 | /* Increments 'L->top', checking for stack overflows */ | ||
14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ | 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ |
15 | "stack overflow");} | 17 | "stack overflow");} |
16 | 18 | ||
19 | |||
20 | /* | ||
21 | ** If a call returns too many multiple returns, the callee may not have | ||
22 | ** stack space to accomodate all results. In this case, this macro | ||
23 | ** increases its stack space ('L->ci->top'). | ||
24 | */ | ||
17 | #define adjustresults(L,nres) \ | 25 | #define adjustresults(L,nres) \ |
18 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } | 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } |
19 | 27 | ||
28 | |||
29 | /* Ensure the stack has at least 'n' elements */ | ||
20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ | 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ |
21 | "not enough elements in the stack") | 31 | "not enough elements in the stack") |
22 | 32 | ||