Skip to content

Fix deep recursion stack overflow on Windows#72

Merged
atoomic merged 1 commit intogaru:masterfrom
atoomic:koan.atoomic/fix-deep-recursion-windows
Feb 17, 2026
Merged

Fix deep recursion stack overflow on Windows#72
atoomic merged 1 commit intogaru:masterfrom
atoomic:koan.atoomic/fix-deep-recursion-windows

Conversation

@Koan-Bot
Copy link
Contributor

Summary

Fixes t/10-deep_recursion.t crash on Windows (CPAN Testers: exit 255, 3/5 subtests failed).

Root cause: Deeply nested arrayrefs like [[[...]]] consume ~3 C stack frames per nesting level during recursive cloning. Windows has a 1MB default thread stack (vs 8MB on Linux/macOS), causing stack overflow well before the MAX_DEPTH safety limit was reached.

Three interrelated bugs fixed:

  1. Platform-adaptive MAX_DEPTH: 4000 on Windows (safe for ~2000 nesting levels), 32000 elsewhere
  2. MAX_DEPTH RV→AV routing: The depth check only handled SVt_PVAV but the [[[...]]] pattern alternates RV/AV — the limit was always first hit on an RV, falling through to SvREFCNT_inc(ref) which produced a shared (not deep-copied) inner structure
  3. av_clone_iterative rewrite: Fixed two bugs — returned chain tail instead of root (lost nesting levels), and used stale seen-hash key

Test rewrite: Removed Devel::Peek and Devel::Size dependencies (unnecessary risk), tests 35000-level nesting built iteratively, added clone-independence mutation test.

CPAN Testers report: https://magpie.cpantesters.org/results/5483df40-720f-1014-847a-9de21b4fca93

Test plan

  • All 205 tests pass locally (macOS, Perl 5.42.0)
  • CI passes on Linux + Windows matrix
  • Verify no memory leaks with deep structures (tested manually: 5 iterations of 20000-deep clone+free)

🤖 Generated with Claude Code

@Koan-Bot
Copy link
Contributor Author

Recreated: Fix deep recursion stack overflow on Windows

The original branch koan.atoomic/fix-deep-recursion-windows had diverged too far from master for a clean rebase. The feature has been reimplemented from scratch on top of current master.

Branch koan.atoomic/fix-deep-recursion-windows has been force-pushed with the recreation.

Actions

  • Read PR Fix deep recursion stack overflow on Windows #72: "Fix deep recursion stack overflow on Windows"
  • Created fresh branch koan.atoomic/fix-deep-recursion-windows from origin/master
  • Reimplemented feature from scratch
  • Tests pass
  • Force-pushed koan.atoomic/fix-deep-recursion-windows (recreated from scratch)

Automated by Kōan

Koan-Bot added a commit to atoomic/Clone that referenced this pull request Feb 17, 2026
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-deep-recursion-windows branch from 75f4b00 to 5de1aa8 Compare February 17, 2026 21:36
@atoomic atoomic force-pushed the koan.atoomic/fix-deep-recursion-windows branch from 5de1aa8 to 225430b Compare February 17, 2026 21:40
@atoomic atoomic marked this pull request as ready for review February 17, 2026 21:40
@atoomic atoomic merged commit 44cd9eb into garu:master Feb 17, 2026
27 checks passed
@atoomic atoomic deleted the koan.atoomic/fix-deep-recursion-windows branch February 17, 2026 21:44
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.

2 participants