Commit 6d70b4bd
6d70b4bd233fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 6 files · +2 added · ~4 modified
Description
codegen,runtime: at_exit hooks run in LIFO after main returns
Previously the `at_exit { ... }` block was silently dropped (the codegen returned 1 from compile_block_iteration_stmt and the block was never installed). Add a static LIFO array sp_at_exit_hooks[] in the runtime, register the proc on at_exit { ... } via compile_proc_literal, and emit a tail loop in main() that walks the array in reverse-registration order before returning. The emit is gated on @needs_at_exit so the typical "no at_exit" build gets a zero-cost no-op.
Cap at 256 hooks (more than enough for any subset program; if ever insufficient the cap can be lifted to a malloc-backed sp_PtrArray).
Update test/warn_kernel.rb / .expected which previously asserted "block is ignored" — now reflects the new semantics.
Fixes #990
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 6d70b4bd233f
- Parent
- a3c671cdb248
lib/sp_runtime.hmodifiedView file
a->len -= n; return r;}/* at_exit hooks: a static LIFO of registered procs. Initialized zero-len in BSS; main()'s tail walks it in reverse-registration order before returning. */#define SP_AT_EXIT_MAX 256struct sp_Proc;static struct sp_Proc *sp_at_exit_hooks[SP_AT_EXIT_MAX];static mrb_int sp_at_exit_count = 0;static sp_PtrArray *sp_PtrArray_slice_bang(sp_PtrArray *a, mrb_int from, mrb_int n) { if (from < 0) from += a->len; if (from < 0) from = 0;spinel_codegen.rbmodifiedView file
Loading diff…
test/at_exit_lifo.rbaddedView file
Loading diff…
test/at_exit_lifo.rb.expectedaddedView file
Loading diff…
test/warn_kernel.rbmodifiedView file
Loading diff…
test/warn_kernel.rb.expectedmodifiedView file
Loading diff…