Skip to content

feat(decompiler): Rec 31 #31-3 RAII Stage 2B — xml_parse global_scan unique_ptr (v2)#73

Merged
CryptoJones merged 1 commit into
masterfrom
feat/rec-31-raii-stage2b-xml-globalscan-v2
May 26, 2026
Merged

feat(decompiler): Rec 31 #31-3 RAII Stage 2B — xml_parse global_scan unique_ptr (v2)#73
CryptoJones merged 1 commit into
masterfrom
feat/rec-31-raii-stage2b-xml-globalscan-v2

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Replaces #52 which auto-closed when the merge conflict with the squash-merged #51 couldn't auto-resolve. Same exact change — cherry-picked onto a clean branch off master (now that #51's lvalue migration is in make_unique is available in xml.hh's using-decls).

Converts xml_parse()'s pairing of global_scan = new XmlScan(i) / delete global_scan; to a scope-bound unique_ptr that holds ownership across the yyparse call:

auto scan = make_unique<XmlScan>(i);
global_scan = scan.get();    // raw observer pointer for grammar actions
...
int4 res = yyparse();
...
global_scan = (XmlScan *)0;  // null observer before scan goes out of scope
return res;

global_scan stays a static XmlScan * (raw observer) because it's accessed from yyparse / yylex / grammar semantic actions — those see it through the symbol declared at file scope, and changing it to unique_ptr would require changing every accessor. The observer pattern keeps the surface area minimal: only xml_parse owns; everyone else just borrows during the parse.

After this PR, the only raw news remaining in the xml.y / xml.cc epilogue are Element (parse-tree ownership) and Document (return-value), both scoped as separate PRs in docs/decompiler/RAII_STAGE_2C_XML.md.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

…unique_ptr

Stacked PR on top of the XmlScan::lvalue migration (PR #51). Same
hand-edit pattern: epilogue change in xml.y + matching parallel edit
in xml.cc, no bison regeneration required.

Converts xml_parse()'s pairing of `global_scan = new XmlScan(i)` /
`delete global_scan;` to a scope-bound unique_ptr that holds ownership
across the yyparse call:

  auto scan = make_unique<XmlScan>(i);
  global_scan = scan.get();  // raw observer pointer for grammar actions
  ...
  int4 res = yyparse();
  ...
  global_scan = (XmlScan *)0;  // null observer before scan goes out of scope
  return res;

`global_scan` stays a `static XmlScan *` (raw observer) because it's
accessed from yyparse / yylex / grammar semantic actions — those see
it through the symbol declared at file scope, and changing it to
unique_ptr would require changing every accessor. The observer pattern
keeps the surface area minimal: only xml_parse owns; everyone else
just borrows during the parse.

The explicit `global_scan = nullptr` before return is defensive — if
anything ever tries to dereference global_scan after xml_parse exits,
crash on null is far better than use-after-free on dangling.

After this PR, the only raw `new`s remaining in the xml.y / xml.cc
epilogue are:

  - line 538 `new Element(cur)` — parse-tree node allocation, owned
    by parent's children list; needs Element class field refactor.
  - line 624 `new Document()` — returned across xml_tree() API to
    XmlDecode; needs xml.hh + XmlDecode coordination.

Both are separate PRs. The bison semantic-action raw `new`s
(xml.y:150, 153, 198, 200, 208) remain blocked on `%union` redesign.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones added a commit that referenced this pull request May 26, 2026
PR #51's branch was inadvertently based on the in-flight PR #50
CodeQL-fix branch (not master), so PR #51's squash-merge included
PR #50's broken first commit alongside the intended lvalue RAII
change. Master at f41d8fc ended up with the broken CodeQL
config; PR #50 couldn't merge as-is; PR #52 (xml global_scan,
stacked on PR #51) also auto-closed when its base disappeared.

Mitigation:
  - PR #74 cherry-picks PR #50's second commit (binutils-dev
    fix) onto current master cleanly.
  - PR #73 cherry-picks PR #52's global_scan commit onto current
    master cleanly.

Adds an entry to Apologies.md at the top (per the log policy)
recording cause + downstream damage + mitigation.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit cf82e10 into master May 26, 2026
14 of 15 checks passed
@CryptoJones CryptoJones deleted the feat/rec-31-raii-stage2b-xml-globalscan-v2 branch May 26, 2026 08:56
CryptoJones added a commit that referenced this pull request May 26, 2026
…leased] (#76)

The catch-up changelog PR (#72) listed #50, #51, #52 as in-flight.
Now resolved:

  - #51 (lvalue) — merged (was the lone in-flight item that landed
    cleanly).
  - #50 (CodeQL fix) — superseded by #74 after the stacking mistake.
    #74 landed and Analyze (c-cpp) now passes on master.
  - #52 (global_scan) — superseded by #73 after the same stacking
    mistake. #73 landed.
  - #75 (Apologies) — landed alongside, recording the chain.

Removes the "in flight" footnote and replaces with a paragraph
explaining the chain of events so readers understand why #50 / #52
are absent from the merged ledger and #73 / #74 are present
covering the same scope.

Aaron's per-PR changelog feedback (feedback_changelog_per_pr.md)
applied: this PR ships its own changelog touch alongside the actual
state change, not as a catch-up.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Co-authored-by: Claude Opus 4.7 (1M context) <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