fix: isolate mock state per interpreter for ithreads safety#81
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: isolate mock state per interpreter for ithreads safety#81Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
…afety The global OverloadFTOps pointer was shared across all Perl interpreters in a process, causing data races under ithreads: concurrent mock/unmock calls and OP handler reads on the same struct are undefined behavior. Convert to Perl's MY_CXT mechanism so each interpreter gets its own OverloadFTOps allocation. Add pTHX_ to C helper functions for correct interpreter context propagation. Add a CLONE method that gives each new thread a fresh (unmocked) copy with the original pp handlers. Closes cpan-authors#67 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
Converts the global
gl_overload_ftpointer to per-interpreter storage using Perl'sMY_CXTmechanism, eliminating data races under ithreads.Why
gl_overload_ftwas a DSO-level global shared by all interpreters in a process. Under ithreads, concurrent_xs_mock_op/_xs_unmock_opcalls and OP handler reads on the same struct are undefined behavior (C data race). This could cause incorrect mock state, memory leaks from double-allocation in BOOT, or in extreme cases, calling an invalidreal_ppfunction pointer.How
OverloadFTOps*anddebugflag moved into amy_cxt_tstruct managed byMY_CXT_overload_ft_ops,_overload_ft_ops_sv,_overload_ft_stat) now receivepTHX_for correct interpreter contextmock_opXS function declaredMY_CXTto access per-interpreter stateCLONEmethod (underUSE_ITHREADS) allocates a freshOverloadFTOpsfor each new thread, copyingreal_pppointers but starting with all ops unmockedTesting
Full test suite passes. The
CLONEpath is only compiled underUSE_ITHREADS; the non-threaded path is functionally identical to before (MY_CXT degrades to a simple global lookup).Closes #67
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 53 insertions(+), 12 deletions(-)
Code scan: clean
Tests: passed (0 Tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline