Repository navigation
Issue #545 : yield across pcall or a Go call boundary raises the Lua 5.1 error - #548
Open
eldologuzzo wants to merge 1 commit into
Open
eldologuzzo wants to merge 1 commit into
eldologuzzo wants to merge 1 commit into
Conversation
…Lua 5.1 error A coroutine that yielded from a Lua function called by Go code (pcall, xpcall, table.sort, any Go function calling Lua) unwound the nested main loop of that Go call, and the next resume dereferenced a nil frame. LState.nCcalls counts the Go-to-Lua calls (callR) in progress on the thread; PCall restores it when it recovers an error. A yield with a nested call in progress raises "attempt to yield across metamethod/C-call boundary", which the enclosing pcall catches, as in Lua 5.1. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The counter remains balanced across normal and protected-error paths, and the tests cover the reported crash and preserved yield behavior.
0 open findings
What changed in this PR
Prevents coroutine yields from crossing non-resumable Go call boundaries, matching Lua 5.1 behavior and avoiding resume crashes.
Changes:
- Tracks active Go-to-Lua calls and restores the counter after protected errors.
- Raises the Lua 5.1 boundary error for invalid yields.
- Adds regression coverage for
pcall,table.sort, continuation, and normal yields.
| File | Description |
|---|---|
_state.go |
Implements call-boundary tracking and recovery. |
state.go |
Regenerated state implementation. |
_vm.go |
Rejects invalid cross-boundary yields. |
vm.go |
Regenerated VM implementation. |
value.go |
Adds the per-thread call counter. |
_glua-tests/coroutine.lua |
Adds coroutine regression tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #545 .
Changes proposed in this pull request:
pcall,xpcall, atable.sortcomparator, any Go function calling Lua) unwound the nested main loop of that Go call. The next resume then crashed with a nil pointer dereference.LState.nCcalls: it counts the Go-to-Lua calls (callR) in progress on the thread, andPCallrestores it when it recovers an error.attempt to yield across metamethod/C-call boundary. The enclosingpcallcatches it and the coroutine keeps running, which is the Lua 5.1 behavior discussed in pcall doesn't work in conjection with coroutines. #45._state.goand_vm.go;state.goandvm.goare regenerated withmake build._glua-tests/coroutine.lua(yield insidepcall, inside atable.sortcomparator, the coroutine continuing after the caught error, plain yields). On current master they fail.🤖 Generated with Claude Code