Skip to content

Commit

Permalink
Merge pull request #3623 from masatake/C-related-minor-fixes
Browse files Browse the repository at this point in the history
C,Asm,LdScript: minor fixes
  • Loading branch information
masatake authored Jan 9, 2023
2 parents c7daaa3 + 33e6b28 commit 9213292
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--param-CPreProcessor._expand=1
--fields-CPreProcessor=+{macrodef}
--fields=+{language}{signature}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
X input.S /^#define X /;" d language:CPreProcessor file: macrodef:Y
Y input.S /^#define Y Y$/;" d language:CPreProcessor file: macrodef:Y
Y input.S /^X:$/;" l language:Asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define X Y
#define Y Y
X:
nop
7 changes: 5 additions & 2 deletions parsers/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ static const unsigned char *readOperator (

// We stop applying macro replacements if the unget buffer gets too big
// as it is a sign of recursive macro expansion
#define ASM_SCRIPT_PARSER_MAXIMUM_UNGET_BUFFER_SIZE_FOR_MACRO_REPLACEMENTS 65536
#define ASM_PARSER_MAXIMUM_UNGET_BUFFER_SIZE_FOR_MACRO_REPLACEMENTS 65536

// We stop applying macro replacements if a macro is used so many
// times in a recursive macro expansion.
#define ASM_SCRIPT_PARSER_MAXIMUM_MACRO_USE_COUNT 8
#define ASM_PARSER_MAXIMUM_MACRO_USE_COUNT 8

static bool collectCppMacroArguments (ptrArray *args)
{
Expand Down Expand Up @@ -429,6 +429,9 @@ static bool processCppMacroX (vString *identifier, int lastChar, vString *line)
if (!macroInfo)
goto out;

if(macroInfo && (macroInfo->useCount >= ASM_PARSER_MAXIMUM_MACRO_USE_COUNT))
goto out;

if (lastChar != EOF)
cppUngetc (lastChar);

Expand Down
7 changes: 5 additions & 2 deletions parsers/ldscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ static bool expandCppMacro (cppMacroInfo *macroInfo)
}

#ifdef DO_TRACING
for (int i = 0; i < ptrArrayCount(args); i++)
TRACE_PRINT("[%d] %s", i, (const char *)ptrArrayItem (args, i));
if (args)
{
for (int i = 0; i < ptrArrayCount(args); i++)
TRACE_PRINT("[%d] %s", i, (const char *)ptrArrayItem (args, i));
}
#endif

cppBuildMacroReplacementWithPtrArrayAndUngetResult (macroInfo, args);
Expand Down

0 comments on commit 9213292

Please sign in to comment.