mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
d1289ac8f9
RETURN_IF_TASK_STOPPED used to bail out of mrb_vm_exec as soon as task.switching was set, even when the exec was called re-entrantly from inside a heap-walk callback (e.g. ObjectSpace.each_object via mrb_yield). Bailing in that situation only unwinds the inner exec, leaving the outer C iteration to keep calling the callback. The call-info stack drifts on each subsequent mrb_yield, and the program either trips the cibase assertion in mrb_vm_run or crashes in __longjmp. Hold off the switch while mrb->gc.iterating is set so the heap walk finishes intact; the switch then fires at the next OP boundary once the walk releases the flag. MRB_TASK_STOPPED is intentionally not deferred, since exiting promptly is still correct when the task itself is going away. Fixes #6862. Co-authored-by: Claude <noreply@anthropic.com>