Skip to content

fix: reset Perl-level mock state in ithreads CLONE#102

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-ithreads-perl-mock-state
Draft

fix: reset Perl-level mock state in ithreads CLONE#102
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-ithreads-perl-mock-state

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 4, 2026

What

Reset $_current_mocks and $_last_call_for when a child thread is created under ithreads.

Why

The XS CLONE handler correctly starts each child interpreter with all ops unmocked (is_mocked = 0), but the Perl-level $_current_mocks hash was deep-copied with stale entries from the parent. This caused mock_file_check() in child threads to croak "-X is already mocked" for any op that was mocked in the parent thread.

How

  • Added _clone_init() in FileCheck.pm that resets both $_current_mocks and $_last_call_for
  • Called from XS CLONE via call_pv() after the OverloadFTOps struct is allocated

Testing

  • New t/ithreads-clone.t — verifies child threads can mock independently, parent state doesn't leak, parent mock survives child exit. Skips on non-threaded perls.
  • All existing tests pass.

🤖 Generated with Claude Code


Quality Report

Changes: 3 files changed, 84 insertions(+)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The XS CLONE handler correctly starts child threads with all ops
unmocked (is_mocked=0), but the Perl-level $_current_mocks hash
was not cleared. This caused mock_file_check() in child threads
to croak "already mocked" for ops mocked in the parent.

Add _clone_init() called from XS CLONE to reset $_current_mocks
and $_last_call_for. Add ithreads-clone.t (skips on non-threaded
perls).

Co-Authored-By: Claude <noreply@anthropic.com>
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