From 65b07dd53d7938a60112fc4473f5cad3473e3534 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 11 Mar 2024 14:05:06 -0300 Subject: API asserts for illegal pops of to-be-closed variables --- lapi.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lapi.h') diff --git a/lapi.h b/lapi.h index 43845648..757bf3d2 100644 --- a/lapi.h +++ b/lapi.h @@ -29,8 +29,18 @@ /* Ensure the stack has at least 'n' elements */ #define api_checknelems(L,n) \ - api_check(L, (n) < (L->top.p - L->ci->func.p), \ - "not enough elements in the stack") + api_check(L, (n) < (L->top.p - L->ci->func.p), \ + "not enough elements in the stack") + + +/* Ensure the stack has at least 'n' elements to be popped. (Some +** functions only update a slot after checking it for popping, but that +** is only an optimization for a pop followed by a push.) +*/ +#define api_checkpop(L,n) \ + api_check(L, (n) < L->top.p - L->ci->func.p && \ + L->tbclist.p < L->top.p - (n), \ + "not enough free elements in the stack") /* -- cgit v1.2.3-55-g6feb