Remove fixed-size array for macro arguments

This commit is contained in:
aaaaaa123456789
2020-05-12 06:46:07 -03:00
parent 4d0d6664d7
commit a828f82414
3 changed files with 9 additions and 9 deletions

View File

@@ -720,10 +720,10 @@ macroargs : /* empty */ {
}
| T_STRING {
$$ = macro_NewArgs();
macro_AppendArg($$, strdup($1));
macro_AppendArg(&($$), strdup($1));
}
| macroargs ',' T_STRING {
macro_AppendArg($$, strdup($3));
macro_AppendArg(&($$), strdup($3));
}
;

View File

@@ -10,13 +10,12 @@
#include "asm/warning.h"
struct MacroArgs {
char *args[MAXMACROARGS];
unsigned int nbArgs;
unsigned int shift;
char *args[];
};
static struct MacroArgs defaultArgs = { .nbArgs = 0, .shift = 0 };
static struct MacroArgs *macroArgs = &defaultArgs;
static struct MacroArgs *macroArgs = NULL;
static uint32_t uniqueID = -1;
/*
* The initialization is somewhat harmful, since it is never used, but it
@@ -40,12 +39,13 @@ struct MacroArgs *macro_NewArgs(void)
return args;
}
void macro_AppendArg(struct MacroArgs *args, char *s)
void macro_AppendArg(struct MacroArgs **args, char *s)
{
if (args->nbArgs == MAXMACROARGS)
if ((**args).nbArgs == MAXMACROARGS)
yyerror("A maximum of " EXPAND_AND_STR(MAXMACROARGS)
" arguments is allowed");
args->args[args->nbArgs++] = s;
*args = realloc(*args, sizeof **args + sizeof (char *) * (1 + (**args).nbArgs));
(**args).args[(**args).nbArgs++] = s;
}
void macro_UseNewArgs(struct MacroArgs *args)