Fix header_consumers.py silently blanking 79% of a file when a string contains "//" - #1153
Merged
Merged
Conversation
… contains "//" strip_noise() applied three regexes in sequence: block comments, then line comments, then string literals. No ordering of three independent substitutions can be correct here, because each construct may contain the others' delimiters. Comments-first -- what it did -- blanks from the `//` of a URL to the end of the line, taking the string's closing quote with it. The surviving opening quote then pairs with the next quote further down the file, and STRING_LIT replaces everything between them with "". Measured on src/gui/actions/help.c: 7550 of 9491 characters gone, and its three dt_control_log() calls with them. 129 files in this tree contain `//` inside a string literal, including src/darktable.h and src/views/darkroom.c. Strings-first fails symmetrically: an unbalanced `"` inside a comment starts a literal that eats real code. The damage lands in the worst possible bucket. CLAUDE.md documents that "files using nothing from it" does NOT mean the include can be dropped -- those files reach the symbols through some other include and, under this tree's rule, need the include added EXPLICITLY. A FALSE entry there invites deleting an include the file genuinely needs, which is exactly the failure that broke build-nofeatures when colorprofiles/colorspaces.h was split. Two false entries were being reported: src/gui/actions/help.c against control/control.h (it calls dt_control_log three times), and src/gui/privacy_consent.c against gui/application.h (dt_gui_get_global, dt_gui_get_ui, dt_gui_main_window). Replaced with a single pass that tracks which construct it is inside. Newlines are preserved so line numbers stay meaningful. Verified on eight adversarial inputs -- URL in a string, a quote inside a line comment, `//` and a quote inside a block comment, an escaped quote, a quoted apostrophe in a char literal, an apostrophe in a comment, an unterminated string, and `/*` inside a string -- each of which must keep the code after it and drop the noise. All eight pass; before the fix the first one alone swallowed the rest of the file. Found while acting on doc/control-split.md, whose PR1 depends on this tool telling the truth about control.h's 125 includers. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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.



strip_noise()applied three regexes in sequence — block comments, then line comments, then string literals. No ordering of three independent substitutions can be correct here, because each construct may contain the others' delimiters.Comments-first — what it did — blanks from the
//of a URL to the end of the line, taking the string's closing quote with it. The surviving opening quote then pairs with the next quote further down the file, andSTRING_LITreplaces everything between with"".Measured on
src/gui/actions/help.c: 7550 of 9491 characters gone (79%), and its threedt_control_log()calls with them. 129 files in this tree contain//inside a string literal, includingsrc/darktable.handsrc/views/darkroom.c.Strings-first fails symmetrically: an unbalanced
"inside a comment starts a literal that eats real code. So this is a scanner, not a reordering.Why this bucket is the dangerous one
CLAUDE.md is explicit that "files using nothing from it" does not mean the include can be dropped — those files reach the symbols through some other include and, under this tree's rule, need the include added explicitly. A false entry there invites deleting an include the file genuinely needs — precisely the failure that broke
build-nofeatureswhencolorprofiles/colorspaces.hwas split.Two false entries were being reported:
control/control.hsrc/gui/actions/help.cdt_control_log×3gui/application.hsrc/gui/privacy_consent.cdt_gui_get_global,dt_gui_get_ui,dt_gui_main_windowBoth hidden by a URL in a string literal.
The fix
One pass that tracks which construct it is inside. Newlines preserved, so line numbers stay meaningful.
Verified on eight adversarial inputs, each of which must keep the code after it and drop the noise: URL in a string, a quote inside a line comment,
//and a quote inside a block comment, an escaped quote, a quoted apostrophe in a char literal, an apostrophe in a comment, an unterminated string, and/*inside a string. All eight pass — before the fix, the first alone swallowed the rest of the file.Before/after on real headers (
buggy → fixedcount of the "using nothing" bucket):control/control.h1 → 0,gui/application.h1 → 0, andcontrol/signal.h7 → 7,develop/imageop.h4 → 4,common/image.h1 → 1 unchanged — the genuine ones stay put.Found while acting on
doc/control-split.md(#1152), whose PR1 depends on this tool telling the truth aboutcontrol.h's 125 includers.🤖 Generated with Claude Code