# HG changeset patch # User bellard # Date 1053278180 0 # Node ID 2c98072b92c4c998a20b44456275091f49f4e770 # Parent 924bde5db2b49b8642643473a1c8fd92942d23f5 [project @ 2003-05-18 17:16:20 by bellard] fixed macro argument substitution diff -r 924bde5db2b4 -r 2c98072b92c4 tcc.c --- a/tcc.c Sun May 18 17:08:55 2003 +0000 +++ b/tcc.c Sun May 18 17:16:20 2003 +0000 @@ -681,8 +681,8 @@ void vdup(void); int get_reg(int rc); -static void macro_subst(TokenString *tok_str, - Sym **nested_list, const int *macro_str); +static void macro_subst(TokenString *tok_str, Sym **nested_list, + const int *macro_str, int can_read_stream); int save_reg_forced(int r); void gen_op(int op); void force_charshort_cast(int t); @@ -3711,7 +3711,9 @@ } } } else { - macro_subst(&str, nested_list, st); + /* NOTE: the stream cannot be read when macro + substituing an argument */ + macro_subst(&str, nested_list, st, 0); } } else { tok_str_add(&str, t); @@ -3736,7 +3738,7 @@ macros we got inside to avoid recursing. Return non zero if no substitution needs to be done */ static int macro_subst_tok(TokenString *tok_str, - Sym **nested_list, Sym *s) + Sym **nested_list, Sym *s, int can_read_stream) { Sym *args, *sa, *sa1; int mstr_allocated, parlevel, *mstr, t; @@ -3785,7 +3787,7 @@ next token. XXX: find better solution */ if (macro_ptr) { t = *macro_ptr; - if (t == 0) { + if (t == 0 && can_read_stream) { /* end of macro stream: we must look at the token after in the file */ macro_ptr = NULL; @@ -3862,7 +3864,7 @@ mstr_allocated = 1; } sym_push2(nested_list, s->v, 0, 0); - macro_subst(tok_str, nested_list, mstr); + macro_subst(tok_str, nested_list, mstr, 1); /* pop nested defined symbol */ sa1 = *nested_list; *nested_list = sa1->prev; @@ -4009,8 +4011,8 @@ /* do macro substitution of macro_str and add result to (tok_str,tok_len). 'nested_list' is the list of all macros we got inside to avoid recursing. */ -static void macro_subst(TokenString *tok_str, - Sym **nested_list, const int *macro_str) +static void macro_subst(TokenString *tok_str, Sym **nested_list, + const int *macro_str, int can_read_stream) { Sym *s; int *saved_macro_ptr, *macro_str1; @@ -4039,7 +4041,7 @@ saved_macro_ptr = macro_ptr; macro_ptr = (int *)ptr; tok = t; - ret = macro_subst_tok(tok_str, nested_list, s); + ret = macro_subst_tok(tok_str, nested_list, s, can_read_stream); ptr = (int *)macro_ptr; macro_ptr = saved_macro_ptr; if (ret != 0) @@ -4071,7 +4073,7 @@ /* we have a macro: we try to substitute */ tok_str_new(&str); nested_list = NULL; - if (macro_subst_tok(&str, &nested_list, s) == 0) { + if (macro_subst_tok(&str, &nested_list, s, 1) == 0) { /* substitution done, NOTE: maybe empty */ tok_str_add(&str, 0); macro_ptr = str.str;