From 9a37dc0ce64c51fd57f5e658a5af8f3671a26b0a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 25 Jul 2019 13:55:29 -0300 Subject: 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. --- lapi.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lapi.h') diff --git a/lapi.h b/lapi.h index 5a4206f1..f48d14fd 100644 --- a/lapi.h +++ b/lapi.h @@ -11,12 +11,22 @@ #include "llimits.h" #include "lstate.h" + +/* Increments 'L->top', checking for stack overflows */ #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ "stack overflow");} + +/* +** If a call returns too many multiple returns, the callee may not have +** stack space to accomodate all results. In this case, this macro +** increases its stack space ('L->ci->top'). +*/ #define adjustresults(L,nres) \ { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } + +/* Ensure the stack has at least 'n' elements */ #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ "not enough elements in the stack") -- cgit v1.2.3-55-g6feb