From 374312cde4d44f8849d602cc5c9ea634798b9c50 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 00:17:13 -0800 Subject: strlist, warnings: improve strlist, buffer warnings until error Make strlist_free() take a pointer to a pointer, so we can set it to NULL. Buffer warnings on a strlist until we either get an error or we are in pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS* bullshit, which far too often causes messages to get lost. asm/labels.c contains one example of a warning that cannot be made correct with a specific pass number. Signed-off-by: H. Peter Anvin (Intel) --- nasmlib/strlist.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'nasmlib') diff --git a/nasmlib/strlist.c b/nasmlib/strlist.c index 93a6787f..506ad50e 100644 --- a/nasmlib/strlist.c +++ b/nasmlib/strlist.c @@ -136,21 +136,24 @@ strlist_printf(struct strlist *list, const char *fmt, ...) } /* - * Free a string list + * Free a string list. Sets the pointed to pointer to NULL. */ -void strlist_free(struct strlist *list) +void strlist_free(struct strlist **listp) { - if (list) { - struct strlist_entry *e, *tmp; + struct strlist *list = *listp; + struct strlist_entry *e, *tmp; - if (list->uniq) - hash_free(&list->hash); + if (!list) + return; - list_for_each_safe(e, tmp, list->head) - nasm_free(e); + if (list->uniq) + hash_free(&list->hash); - nasm_free(list); - } + list_for_each_safe(e, tmp, list->head) + nasm_free(e); + + nasm_free(list); + *listp = NULL; } /* @@ -187,3 +190,17 @@ void *strlist_linearize(const struct strlist *list, char sep) return buf; } + +/* + * Output a string list to a file. The separator can be any string. + */ +void strlist_write(const struct strlist *list, const char *sep, FILE *f) +{ + const struct strlist_entry *sl; + size_t seplen = strlen(sep); + + strlist_for_each(sl, list) { + fwrite(sl->str, 1, sl->size - 1, f); + fwrite(sep, 1, seplen, f); + } +} -- cgit v1.2.1