From 2c63ab038c7ca47dd682182d41a91dbb20c0faba Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 7 Oct 2025 09:53:15 -0700 Subject: [PATCH] asm/preproc.c: generalize pp_pre_command() Generalize pp_pre_command() so that the first argument doesn't have to be a preprocessor token. Instead, the two arguments are now both turned into token streams, separated by a whitespace token. Signed-off-by: H. Peter Anvin (Intel) --- asm/preproc.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/asm/preproc.c b/asm/preproc.c index cda0fee1..22b7f72f 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -1100,6 +1100,19 @@ static Token *cut_tlist(Token *t) return nt; } +/* + * Find the pointer to the end of a tlist. If the tlist is empty, + * return the incoming pointer. + */ +static Token **tlist_endptr(Token **tptr) +{ + Token *t; + while ((t = *tptr)) + tptr = &t->next; + + return tptr; +} + /* * Allocate a new MMacro. This does not claim a refcount; the appropriate * get_mmacro() calls need to be added. @@ -8920,13 +8933,17 @@ void pp_pre_undefine(char *definition) /* Insert an early preprocessor command that doesn't need special handling */ void pp_pre_command(const char *what, char *string) { - Token *def, *space; + Token *def; Line *l; def = tokenize(string); + if (what) { - space = new_White(def); - def = new_Token(space, TOKEN_PREPROC_ID, what, 0); + Token *wt = tokenize(what); + Token **tailp = tlist_endptr(&wt); + + *tailp = new_White(def); + def = wt; } nasm_new(l);