Skip to content

Guard host userdata identity against stale-reference reuse - #8

Merged
rbroderi merged 2 commits into
mainfrom
guard-lupa-294-host-identity
Sep 12, 2026
Merged

rbroderi merged 2 commits into
mainfrom
guard-lupa-294-host-identity

Conversation

@rbroderi

Copy link
Copy Markdown
Owner

Add a regression guard for the failure mode reported in scoder/lupa#294.

Lupa's Lua 5.5 bug came from reusing a cached host-object reference slot before the old Lua userdata wrapper had actually been collected, allowing a stale wrapper to resolve to a different live Python object.

LuaPyre currently avoids that mechanism entirely: opaque host userdata is represented by the Python object reference itself rather than a recyclable registry handle. This PR makes that an explicit invariant and locks it in with stress coverage.

Changes:

  • add a 20,000-iteration host userdata round-trip test with temporary Lua table creation and repeated forced collection
  • verify three distinct host objects remain distinct Lua table keys across GC cycles
  • document in LuaRuntime._to_lua() that reusable host-reference registries must use identity/generation validation on reuse and finalization

Validation:

  • branch CI passes on Python 3.13 and 3.14
  • full existing suite remains green
  • Lupa Lua 5.5 backend verification remains green

Reference:

@rbroderi
rbroderi merged commit 2c4361d into main Sep 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant