Skip to content

Fix Partials merging adjacent #define macros when one has a comment with an apostrophe (#1262) - #1270

Merged
mkarlesky merged 2 commits into
masterfrom
fix/1262-partials-macro-newline-master
Sep 8, 2026
Merged

Fix Partials merging adjacent #define macros when one has a comment with an apostrophe (#1262)#1270
mkarlesky merged 2 commits into
masterfrom
fix/1262-partials-macro-newline-master

Conversation

@mkarlesky

Copy link
Copy Markdown
Member

Fixes #1262. This is a port of #1269 (already merged/green on next_version) to master, for inclusion in 1.1.8.

Root cause

_collect_directive (the #define/directive scanner in c_extractor_preprocessing.rb) scanned every " or ' character on a directive line as the start of a string/char literal — including one appearing inside a trailing // or /* */ comment. An ordinary English contraction in a macro's comment, e.g.:

#define START_ADDRESS 0x00 // don't change this
#define IDX_DATARATE (ADS124S08_REG_ADDR_DATARATE - START_ADDRESS)

opened what looked like an unterminated char literal at the apostrophe in "don't", sending skip_c_string hunting for a closing ' straight through this directive's own newline and into the following #define line(s) — silently merging them into a single macro_definitions entry with no separating newline.

Partials generation (generator_partials.rb) then faithfully wrote that already-corrupted, newline-less text back out, producing a generated ..._impl.h with two #define lines concatenated onto one physical line — a hard stray '#' in program compile error, exactly as reported.

Fix

Comment content (both // and /* */) is now captured verbatim without being scanned for string/char literal delimiters. A \ immediately before the newline inside a // comment still splices lines (matching how backslash-newline continuation already works everywhere else in a directive), so a multi-line macro whose continuation line happens to start with a comment still extracts correctly.

Tests

Same coverage as #1269: new #try_extract_directive cases in c_extractor_preprocessing_spec.rb, adjacency-reconstruction tests in c_extractor_integration_spec.rb, and byte-exact adjacency tests (macros/typedefs/aggregates) in generator_partials_spec.rb. Unit tests only, no system tests. bundle exec rake specs:units clean on host (1989 examples, 0 failures, 1 pre-existing unrelated pending).

🤖 Generated with Claude Code

mkarlesky and others added 2 commits September 8, 2026 15:43
…ith an apostrophe

_collect_directive scanned every '"' or "'" on a directive line as the start
of a string/char literal, including inside a trailing // or /* */ comment.
An ordinary contraction like "don't" in a macro's comment opened what looked
like an unterminated char literal, sending skip_c_string hunting for a
closing match straight through the directive's own newline and into
whatever followed -- silently merging the next #define(s) into one
macro_definitions entry with no separating newline between them.

Partials generation faithfully wrote that corrupted, newline-less text back
out, producing a generated ..._impl.h with two #define lines concatenated
onto one physical line -- a hard "stray '#' in program" compile error
(GH #1262).

Comment content (both // and /* */) is now captured verbatim without being
scanned for literal delimiters. A '\' immediately before the newline inside
a // comment still splices lines, matching how backslash-newline
continuation already works everywhere else in a directive.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
[skip ci]

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mkarlesky
mkarlesky merged commit 9dbaf27 into master Sep 8, 2026
@mkarlesky
mkarlesky deleted the fix/1262-partials-macro-newline-master branch September 8, 2026 20:42
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.

Partials generator merges two adjacent single-line #defines onto one line ("stray '#' in program")

1 participant