Fix %clear infinite loop and enable recursive macro support#230
Open
magicelk235 wants to merge 1 commit into
Open
Fix %clear infinite loop and enable recursive macro support#230magicelk235 wants to merge 1 commit into
magicelk235 wants to merge 1 commit into
Conversation
c37f9c2 to
52ff78e
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates NASM’s preprocessor (asm/preproc.c) to (1) fix a hang when parsing %clear options (notably %clear context define), and (2) re-enable recursive multi-line macro (%rmacro) support by restoring the saved-invocation mechanism and adjusting cleanup/reference handling.
Changes:
- Fix
%clearoption parsing loop to advance tokens and avoid the previous infinite loop. - Reintroduce recursive mmacro invocation save/restore (
MMacroInvocation,push_mmacro(),pop_rmacro()). - Adjust recursive macro unwind logic and reference counting helpers to support recursion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8794
to
+8798
| if (fm->in_progress == 0) { | ||
| /* Only do full cleanup when all recursion levels done */ | ||
| if (fm->nolist & NL_LINE) { | ||
| istk->noline--; | ||
| } else if (!istk->noline) { |
Comment on lines
6962
to
+6966
| i->prev = m->prev; | ||
| i->params = m->params; | ||
| i->iline = m->iline; | ||
| i->iname = m->iname; | ||
| i->mstk = m->mstk; |
d047a5c to
505a802
Compare
…pport Fix infinite loop in %clear directive parsing. When parsing options like "%clear context define", the while loop never advanced to the next token, causing the preprocessor to hang indefinitely on the same token. Also re-enable the previously disabled recursive macro (rmacro) support: - Restore MMacroInvocation struct for saving/restoring macro state - Re-enable push_mmacro() to save invocation state before recursion - Add pop_rmacro() to properly restore state after recursive expansion - Add unref_mmacro() helper for reference counting during recursion - Fix macro exit handling to properly clean up at each recursion level
505a802 to
6394ef1
Compare
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.
What's this about?
I ran into an issue where
%clear context definewould hang the preprocessor indefinitely. After digging into it, I found a simple bug in the token parsing loop - it never moved to the next token, so it just kept processing the same one forever.While I was in there, I also noticed the recursive macro (rmacro) support was commented out with
#if 0. I've re-enabled it and fixed up the reference counting so macros can properly recurse without leaking memory or crashing.Changes
%clear fix:
t = t->nextat the end of the option parsing loopbreakinstead of settingt = NULL(which would crash on the next iteration)Recursive macro support:
MMacroInvocationstruct that saves/restores macro state between recursive callspush_mmacro()to save state before recursingpop_rmacro()to restore state when unwindingunref_mmacro()helper for cleaner reference count managementTesting
Verified
%clear context defineno longer hangs and error messages for invalid options still work correctly.