@@ -104,7 +104,6 @@ static enum preproc_opt ppopt;
104104
105105typedef struct SMacro SMacro ;
106106typedef struct MMacro MMacro ;
107- typedef struct MMacroInvocation MMacroInvocation ;
108107typedef struct Context Context ;
109108typedef struct Token Token ;
110109typedef struct Line Line ;
@@ -226,9 +225,10 @@ struct SMacro {
226225 intorptr expandpvt ;
227226 struct smac_param * params ;
228227 int nparam ;
228+ int in_progress ;
229+ bool recursive ;
229230 bool varadic ; /* greedy or supports > nparam arguments */
230231 bool casesense ;
231- bool in_progress ;
232232 bool alias ; /* This is an alias macro */
233233};
234234
@@ -3059,10 +3059,10 @@ static SMacro *define_smacro(const char *mname, bool casesense,
30593059 /* It is an alias macro; follow the alias link */
30603060 SMacro * s ;
30613061
3062- smac -> in_progress = true ;
3062+ smac -> in_progress ++ ;
30633063 s = define_smacro (tok_text (smac -> expansion ), casesense ,
30643064 expansion , tmpl );
3065- smac -> in_progress = false ;
3065+ smac -> in_progress -- ;
30663066 return s ;
30673067 }
30683068 }
@@ -3147,6 +3147,7 @@ static SMacro *define_smacro(const char *mname, bool casesense,
31473147 if (tmpl ) {
31483148 smac -> params = tmpl -> params ;
31493149 smac -> alias = tmpl -> alias ;
3150+ smac -> recursive = tmpl -> recursive ;
31503151 if (tmpl -> expand ) {
31513152 smac -> expand = tmpl -> expand ;
31523153 smac -> expandpvt = tmpl -> expandpvt ;
@@ -5605,11 +5606,11 @@ static SMacro *expand_one_smacro(Token ***tpp)
56055606 }
56065607 }
56075608
5608- if (m -> in_progress )
5609+ if (m -> in_progress && ! m -> recursive )
56095610 goto not_a_macro ;
56105611
56115612 /* Expand the macro */
5612- m -> in_progress = true ;
5613+ m -> in_progress ++ ;
56135614
56145615 if (nparam ) {
56155616 /* Extract parameters */
@@ -5874,7 +5875,8 @@ static SMacro *expand_one_smacro(Token ***tpp)
58745875 for (t = tline ; t && t != tafter ; t = t -> next )
58755876 * tpp = & t -> next ;
58765877
5877- m -> in_progress = false;
5878+ /* Expansion complete */
5879+ m -> in_progress -- ;
58785880
58795881 /* Don't do this until after expansion or we will clobber mname */
58805882 free_tlist (mstart );
@@ -6997,11 +6999,16 @@ static void pp_add_magic_stdmac(void)
69976999 enum preproc_token pt ;
69987000 char name_buf [PP_TOKLEN_MAX + 1 ];
69997001
7000- /* Simple standard magic macros */
7002+ /*
7003+ * Simple standard magic macros and functions.
7004+ * Note that preprocessor functions are allowed to recurse.
7005+ */
70017006 nasm_zero (tmpl );
70027007 for (m = magic_macros ; m -> name ; m ++ ) {
70037008 tmpl .nparam = m -> nparam ;
70047009 tmpl .expand = m -> func ;
7010+ tmpl .recursive = m -> nparam && m -> name [0 ] == '%' ;
7011+
70057012 if (m -> nparam ) {
70067013 int i ;
70077014 enum sparmflags flags = m -> flags ;
@@ -7024,6 +7031,7 @@ static void pp_add_magic_stdmac(void)
70247031 tmpl .nparam = 1 ;
70257032 tmpl .varadic = true;
70267033 tmpl .expand = stdmac_is ;
7034+ tmpl .recursive = true;
70277035 name_buf [0 ] = '%' ;
70287036 name_buf [1 ] = 'i' ;
70297037 name_buf [2 ] = 's' ;
0 commit comments