Fix Partials merging adjacent #define macros when one has a comment with an apostrophe (#1262) - #1270
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1262. This is a port of #1269 (already merged/green on
next_version) tomaster, for inclusion in 1.1.8.Root cause
_collect_directive(the#define/directive scanner inc_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.:opened what looked like an unterminated char literal at the apostrophe in "don't", sending
skip_c_stringhunting for a closing'straight through this directive's own newline and into the following#defineline(s) — silently merging them into a singlemacro_definitionsentry with no separating newline.Partials generation (
generator_partials.rb) then faithfully wrote that already-corrupted, newline-less text back out, producing a generated..._impl.hwith two#definelines concatenated onto one physical line — a hardstray '#' in programcompile 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_directivecases inc_extractor_preprocessing_spec.rb, adjacency-reconstruction tests inc_extractor_integration_spec.rb, and byte-exact adjacency tests (macros/typedefs/aggregates) ingenerator_partials_spec.rb. Unit tests only, no system tests.bundle exec rake specs:unitsclean on host (1989 examples, 0 failures, 1 pre-existing unrelated pending).🤖 Generated with Claude Code