Skip to content

Claude/upgrade ape c library mm z gd#112

Merged
staalmannen merged 7 commits into
mainfrom
claude/upgrade-ape-c-library-mmZGd
May 19, 2026
Merged

Claude/upgrade ape c library mm z gd#112
staalmannen merged 7 commits into
mainfrom
claude/upgrade-ape-c-library-mmZGd

Conversation

@staalmannen
Copy link
Copy Markdown
Owner

No description provided.

claude and others added 7 commits May 19, 2026 10:00
…paths

writemain() calls ExtUtils::Miniperl which uses:
  Exporter        → dist/Exporter/lib/Exporter.pm
  use strict      → lib/strict.pm  (already present)
  ExtUtils::Embed → lib/ExtUtils/Embed.pm
  use Config      → lib/Config.pm  (generated by ./Configure — stub added)
  File::Spec      → dist/PathTools/lib/File/Spec.pm

Config.pm is normally generated by ./Configure and absent from the
source tree.  Add a minimal stub at lib/Config.pm with the handful of
keys used by ExtUtils::Embed's writemain code path (lib_ext, static_ext,
path_sep, usedl).  Expand as the build system matures.

Update mkfile to pass all required -I paths explicitly rather than
relying on the user copying files to /sys/lib/perl.

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
…apexp_compiler_improvements.md

Documents the compound literal implementation (compoundlit, addable guard,
OLIST→OCOMMA, struct/union limitation) and the in-progress DWARF debug
support in the Plan9 linkers (ld/dwarf.c, libdwarf, dwarfdump, adbg).

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
kencc implements _Bool as TUCHAR (unsigned char), so (bool)(x) truncates to the
low byte.  For 8-byte-aligned heap pointers, this is always 0x00; for flags like
SVf_UTF8=0x20000000, the low byte is also 0x00 — making cBOOL(SvUTF8(sv)) always
false regardless of the flag.

Fix: override cBOOL with !! under _PLAN9_SOURCE in handy.h.  This produces int
0/1 via double-negation, which works correctly for pointers and wide flag values.

Also remove all debug diagnostics added during investigation (LLNULL trail,
SPLDIAG, SCOPEDIAG, CFDIAG, LLDIAG) — root causes identified and fixed.

op.h OpMAYBESIB_set retains the comma-operator form to avoid relying on kencc's
broken bitfield-assignment expression value (which always evaluates to 0).

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
First step of adding proper _Bool support to kencc. TBOOL (etype=3)
is inserted between TUCHAR and TSHORT. Remaining work: lex.c, com.c
normalization, and arch txt.c files.

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
- lex.c: map _Bool and bool keywords to TBOOL (not TUCHAR)
- lex.c: initialize types[TBOOL] in cinit()
- com.c: add TBOOL to integer promotion cases alongside TUCHAR
- com64.c: convvtox() normalizes TBOOL to 0/1 (not byte-truncation)
- sub.c: add TBOOL to thashinit, tnamesinit, qnamesinit, trelinit
- sub.c: insert TBOOL column in tab[][] arithmetic-promotion matrix

Remaining: arch txt.c files (ewidth, ncast, gmove, regalloc).

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
…rkaround

All 7 arch compilers (1c 2c 5c 6c 7c 8c 9c) updated:
- txt.c: ewidth[TBOOL]=SZ_CHAR, ncast[TBOOL]=BCHAR|BUCHAR|BBOOL
- txt.c: case TBOOL: in regalloc, gmove load/store, CASE() widening paths
- reg.c: TBOOL alongside TUCHAR in register-class tables
- cgen.c (6c/7c): TBOOL in byte-operation dispatch
- sgen.c (1c/2c): TBOOL in scalar generation

cc front-end completed:
- com.c: OCAST-to-TBOOL normalizes to (expr != 0) at compile and runtime
- com64.c: initetconv[] and vlong-cast dispatch include TBOOL
- dcl.c: scalar-init and integer-promotion switches include TBOOL
- funct.c: gtabinit[] vasop suffix for TBOOL
- acid.c/pickle.c: TBOOL serialization entries

perl/handy.h: revert _PLAN9_SOURCE cBOOL workaround — compiler now handles
(_Bool)(x) correctly for all values including aligned pointers and wide flags.

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
@staalmannen staalmannen merged commit dc6024b into main May 19, 2026
1 check passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive support for the _Bool type across the Plan 9 C compiler suite (1c, 2c, 5c, 6c, 7c, 8c, 9c) and the core cc library, including normalization logic to ensure boolean values are strictly 0 or 1. It also updates documentation for compound literals and DWARF support, fixes Perl build scripts by adding necessary include paths, and cleans up diagnostic code in the Perl source. A critical issue was identified in sys/src/external/perl/op.c where changing the return value of Perl_op_linklist to NULL could break the construction of the Perl op tree, potentially leading to interpreter crashes.

Comment on lines +1827 to +1829
o = o->op_sibparent;
if (!o)
return NULL; /* detached/partially-built subtree */
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change from return _prev->op_next to return NULL appears to be incorrect and could introduce a critical bug.

When op_linklist is called on a detached subtree, this !o condition will be met when ascending from the subtree's root. The original code attempted to recover by returning the linearized list of the subtree's children (_prev->op_next). By returning NULL, the linearized subtree is lost.

Callers like S_new_logop in op.c rely on LINKLIST (which is op_linklist) to return a valid OP* to construct the op tree. For example, logop->op_next = LINKLIST(first); will set op_next to NULL, breaking the op list construction and likely leading to crashes or incorrect behavior in the interpreter.

Please restore the original logic of returning the processed part of the tree.

        OP* _prev = o;
        o = o->op_sibparent;
        if (!o) return _prev->op_next;

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