Skip to content

refactor: fix TRACEME debug infrastructure for 64-bit#141

Draft
Koan-Bot wants to merge 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/fix-traceme-64bit-format
Draft

refactor: fix TRACEME debug infrastructure for 64-bit#141
Koan-Bot wants to merge 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/fix-traceme-64bit-format

Conversation

@Koan-Bot

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

Copy link
Copy Markdown
Contributor

What

Fix three issues in the DEBUG_CLONE tracing infrastructure that make it
unusable on modern 64-bit systems.

Why

The debug tracing code predates the iterative clone functions added
in recent releases. Anyone trying to debug Clone.xs with
-DDEBUG_CLONE would hit compile errors (from the CLONE_STORE
macro hardcoding variable names) and get truncated pointer addresses
(from %x format on 64-bit).

How

  • Pointer format: %xPTR2UV() + UVxf (Perl's portable
    pointer format macros, correct on all architectures).
  • CLONE_STORE macro: replaced hardcoded ref/clone variable
    names with the macro's own parameters x/y.
  • TRACEME macro: __FUNCTION____func__ (C99 standard),
    && sequencing → do { ... } while (0) wrapper.

Testing

  • Standard build: clean compile, full test suite passes.
  • Debug build (DEFINE="-DDEBUG_CLONE"): clean compile, no warnings.
  • Zero production code changes — all modifications are inside
    #ifdef DEBUG_CLONE blocks.

🤖 Generated with Claude Code


Quality Report

Changes: 1 file changed, 19 insertions(+), 16 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Three issues in the DEBUG_CLONE tracing code:

1. All pointer prints used %x (unsigned int format) for SV* pointers,
   which is undefined behavior on 64-bit and truncates addresses to
   32 bits.  Replaced with PTR2UV() + UVxf (Perl's portable pointer
   format macros).

2. CLONE_STORE macro's trace output hardcoded 'ref' and 'clone' as
   variable names — compile error when called from iterative clone
   functions where the arguments have different names (e.g.
   inner_sv, new_av).  Now uses macro parameters directly.

3. TRACEME macro used __FUNCTION__ (GCC extension) instead of
   __func__ (C99 standard), and relied on && short-circuit for
   sequencing printf calls.  Replaced with __func__ and do/while(0)
   wrapper.

No changes to production code paths — all modifications are inside
#ifdef DEBUG_CLONE blocks.

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