From 11dfa1a5a5f3bf080b6150a2d318e337a741839b Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 2 Jul 2008 18:11:04 -0700 Subject: [PATCH] preproc: Allow anonymous contexts Allow %push and %repl without a context name. For a lot of uses, it is only a potential source of namespace pollution. --- preproc.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/preproc.c b/preproc.c index 1d89cb88..952f4814 100644 --- a/preproc.c +++ b/preproc.c @@ -1491,7 +1491,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) free_tlist(origline); return -1; } - if (!nasm_stricmp(tline->text, cstk->name)) + if (cstk->name && !nasm_stricmp(tline->text, cstk->name)) j = true; tline = tline->next; } @@ -2191,17 +2191,22 @@ static int do_directive(Token * tline) tline = tline->next; skip_white_(tline); tline = expand_id(tline); - if (!tok_type_(tline, TOK_ID)) { - error(ERR_NONFATAL, "`%%push' expects a context identifier"); - free_tlist(origline); - return DIRECTIVE_FOUND; /* but we did _something_ */ - } - if (tline->next) - error(ERR_WARNING, "trailing garbage after `%%push' ignored"); + if (tline) { + if (!tok_type_(tline, TOK_ID)) { + error(ERR_NONFATAL, "`%%push' expects a context identifier"); + free_tlist(origline); + return DIRECTIVE_FOUND; /* but we did _something_ */ + } + if (tline->next) + error(ERR_WARNING, "trailing garbage after `%%push' ignored"); + p = nasm_strdup(tline->text); + } else { + p = NULL; /* Anonymous context */ + } ctx = nasm_malloc(sizeof(Context)); ctx->next = cstk; hash_init(&ctx->localmac, HASH_SMALL); - ctx->name = nasm_strdup(tline->text); + ctx->name = p; ctx->number = unique++; cstk = ctx; free_tlist(origline); @@ -2211,18 +2216,23 @@ static int do_directive(Token * tline) tline = tline->next; skip_white_(tline); tline = expand_id(tline); - if (!tok_type_(tline, TOK_ID)) { - error(ERR_NONFATAL, "`%%repl' expects a context identifier"); - free_tlist(origline); - return DIRECTIVE_FOUND; /* but we did _something_ */ - } - if (tline->next) - error(ERR_WARNING, "trailing garbage after `%%repl' ignored"); + if (tline) { + if (!tok_type_(tline, TOK_ID)) { + error(ERR_NONFATAL, "`%%repl' expects a context identifier"); + free_tlist(origline); + return DIRECTIVE_FOUND; /* but we did _something_ */ + } + if (tline->next) + error(ERR_WARNING, "trailing garbage after `%%repl' ignored"); + p = nasm_strdup(tline->text); + } else { + p = NULL; + } if (!cstk) error(ERR_NONFATAL, "`%%repl': context stack is empty"); else { nasm_free(cstk->name); - cstk->name = nasm_strdup(tline->text); + cstk->name = p; } free_tlist(origline); break; @@ -4326,7 +4336,7 @@ static void pp_cleanup(int pass) nasm_free(i->path); nasm_free(i); } - } + } } void pp_include_path(char *path) -- 2.11.4.GIT