Skip to content

fix: support cloning Perl 5.38+ class instances (SVt_PVOBJ)#140

Draft
Koan-Bot wants to merge 2 commits into
garu:masterfrom
Koan-Bot:koan.atoomic/fix-pvobj-class-clone
Draft

fix: support cloning Perl 5.38+ class instances (SVt_PVOBJ)#140
Koan-Bot wants to merge 2 commits into
garu:masterfrom
Koan-Bot:koan.atoomic/fix-pvobj-class-clone

Conversation

@Koan-Bot

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

Copy link
Copy Markdown
Contributor

What

Deep-clone support for use feature 'class' objects (SVt_PVOBJ, Perl 5.38+).

Why

clone() crashes with unknown type: 0x10 on any object created with the core class keyword — a feature that's been in Perl since 5.38 and increasingly adopted. Neither Clone nor Storable::dclone handle this type today.

How

  • Added SVt_PVOBJ case in sv_clone's type switch: creates a new PVOBJ via newSV(0) + sv_upgrade, then clones each field from the ObjectFIELDS array in the post-magic section (same pattern as PVHV/PVAV).
  • Blessing uses direct SvOBJECT_on + SvSTASH_set instead of sv_bless, which rejects class stashes with "Attempt to bless into a class" on Perl 5.38+.
  • Guarded with #if PERL_VERSION >= 38 — no impact on older Perls.
  • Fields are recursively deep-cloned with proper depth decrement and hseen cycle detection.

Testing

12 new tests in t/28-class-objects.t covering:

  • Basic field preservation and class name retention
  • Field independence (mutating clone doesn't affect original)
  • Nested class objects (deep clone, not shared)
  • Reference-typed fields (hash/array isolation)
  • Class objects inside circular structures
  • Depth-limited clone
  • Memory stability over 500 clone/destroy cycles

All existing tests continue to pass.


🤖 Generated with Claude Code


Quality Report

Changes: 3 files changed, 188 insertions(+)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Koan-Bot and others added 2 commits May 14, 2026 01:40
Clone crashed with "unknown type: 0x10" when cloning objects created
with the `use feature 'class'` syntax introduced in Perl 5.38.  The
new SVt_PVOBJ type was not handled in sv_clone's type switch.

Add deep-clone support for PVOBJ by iterating ObjectFIELDS and
recursively cloning each field value.  Blessing uses direct stash
assignment instead of sv_bless, which rejects class stashes with
"Attempt to bless into a class" on Perl 5.38+.

Both Clone and Storable::dclone failed on class objects before this
change; Clone now handles them correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
install-with-cpm@v1 regressed on Perl 5.8-5.22 after a recent cpm
update requiring Perl 5.24+.  Bump to @v2 for action-based jobs
and use direct `cpm install` in the Docker-based Linux matrix
(where cpm is pre-installed).

Matches the approach approved by @atoomic in PR garu#120.

Co-Authored-By: Claude Opus 4.6 <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