@@ -218,6 +218,52 @@ function count_char(text, ch, n, i) {
218218 if (substr(text, i, 1) == ch) n++
219219 return n
220220}
221+ BEGIN {
222+ infn = 0; started = 0; depth = 0
223+ pre = 0; slot1 = 0; env = 0; pre_drop = 0; alloc = 0; claim = 0
224+ slot2 = 0; zerogrow = 0; grow = 0; copy = 0; store = 0
225+ publish = 0; drop = 0
226+ }
227+ /^LUA_API void lua_pushcclosure\(lua_State \*L,/ { infn = 1; next }
228+ infn {
229+ if (index($0, "{")) started = 1
230+ depth += count_char($0, "{")
231+ depth -= count_char($0, "}")
232+ if (/api_checkclaim\(L, &preclaim\)/) pre = NR
233+ if (/lj_checkapi_slot\(n\)/) slot1 = NR
234+ if (/getcurrenv/) env = NR
235+ if (/lj_state_dropclaim\(&preclaim\)/) pre_drop = NR
236+ if (/lj_func_newC/) alloc = NR
237+ if (/lj_state_resumeclaim/) claim = NR
238+ if (/lj_checkapi_slot\(nup\)/) slot2 = NR
239+ if (/nup == 0/) zerogrow = NR
240+ if (/api_checkstack1_claimed/) grow = NR
241+ if (/copyTVrel\(L, &fn->c.upvalue/) copy = NR
242+ if (/setfuncV/) store = NR
243+ if (/lj_state_stack_pubtv/) publish = NR
244+ if (/lj_state_dropresumeclaim/) drop = NR
245+ if (started && depth == 0) infn = 0
246+ }
247+ END {
248+ if (!pre || !slot1 || !env || !pre_drop || !alloc || !claim || !slot2 ||
249+ !zerogrow || !grow || !copy || !store || !publish || !drop ||
250+ pre > slot1 || slot1 > env || env > pre_drop || pre_drop > alloc ||
251+ alloc > claim || claim > slot2 || slot2 > zerogrow ||
252+ zerogrow > grow || grow > copy || copy > store || store > publish ||
253+ publish > drop) {
254+ print "lua_pushcclosure must snapshot env, allocate unclaimed, and publish claimed"
255+ exit 1
256+ }
257+ }
258+ ]=] , " src/lj_api.c" )
259+
260+ awk ([=[
261+ function count_char(text, ch, n, i) {
262+ n = 0
263+ for (i = 1; i <= length(text); i++)
264+ if (substr(text, i, 1) == ch) n++
265+ return n
266+ }
221267BEGIN {
222268 infn = 0; started = 0; depth = 0
223269 pre = 0; env = 0; pre_drop = 0; alloc = 0; claim = 0; grow = 0
0 commit comments