From: nasm-bot f. C. G. <gor...@gm...> - 2018-11-24 22:48:16
|
Commit-ID: c3527dd6b294d65267bda5be80c2812e60d9fdd4 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=c3527dd6b294d65267bda5be80c2812e60d9fdd4 Author: Cyrill Gorcunov <gor...@gm...> AuthorDate: Sat, 24 Nov 2018 22:17:47 +0300 Committer: Cyrill Gorcunov <gor...@gm...> CommitDate: Sun, 25 Nov 2018 01:15:51 +0300 error: Cover all levels with helpers Signed-off-by: Cyrill Gorcunov <gor...@gm...> --- asm/error.c | 65 ++++++++++++++++++++++++++++++++++++++++--------------- asm/nasm.c | 24 ++++++++++---------- asm/preproc-nop.c | 2 +- asm/preproc.c | 2 +- include/error.h | 10 +++++++-- nasmlib/file.c | 8 +++---- 6 files changed, 73 insertions(+), 38 deletions(-) diff --git a/asm/error.c b/asm/error.c index 970dec0..f99baaa 100644 --- a/asm/error.c +++ b/asm/error.c @@ -91,39 +91,65 @@ void nasm_error(int severity, const char *fmt, ...) va_end(ap); } -fatal_func nasm_fatal(const char *fmt, ...) +#define nasm_error_generatorf(__sev, __flags, __fmt) \ + va_list __ap; \ + va_start(__ap, __fmt); \ + nasm_verror(__sev | __flags, __fmt, __ap) + +#define nasm_error_generator(__sev, __fmt) \ + nasm_error_generatorf(__sev, 0, __fmt) + +void nasm_debug(const char *fmt, ...) { - va_list ap; + nasm_error_generator(ERR_DEBUG, fmt); +} - va_start(ap, fmt); - nasm_verror(ERR_FATAL, fmt, ap); - abort(); +void nasm_debugf(int flags, const char *fmt, ...) +{ + nasm_error_generatorf(ERR_DEBUG, flags, fmt); } -fatal_func nasm_fatal_fl(int flags, const char *fmt, ...) +void nasm_warn(const char *fmt, ...) { - va_list ap; + nasm_error_generator(ERR_WARNING, fmt); +} - va_start(ap, fmt); - nasm_verror(flags | ERR_FATAL, fmt, ap); - abort(); +void nasm_warnf(int flags, const char *fmt, ...) +{ + nasm_error_generatorf(ERR_WARNING, flags, fmt); } -fatal_func nasm_panic(const char *fmt, ...) +void nasm_nonfatal(const char *fmt, ...) { - va_list ap; + nasm_error_generator(ERR_NONFATAL, fmt); +} - va_start(ap, fmt); - nasm_verror(ERR_PANIC, fmt, ap); +void nasm_nonfatalf(int flags, const char *fmt, ...) +{ + nasm_error_generatorf(ERR_NONFATAL, flags, fmt); +} + +fatal_func nasm_fatal(const char *fmt, ...) +{ + nasm_error_generator(ERR_FATAL, fmt); abort(); } -fatal_func nasm_panic_fl(int flags, const char *fmt, ...) +fatal_func nasm_fatalf(int flags, const char *fmt, ...) { - va_list ap; + nasm_error_generatorf(ERR_FATAL, flags, fmt); + abort(); +} - va_start(ap, fmt); - nasm_verror(flags | ERR_PANIC, fmt, ap); +fatal_func nasm_panic(const char *fmt, ...) +{ + nasm_error_generator(ERR_PANIC, fmt); + abort(); +} + +fatal_func nasm_panicf(int flags, const char *fmt, ...) +{ + nasm_error_generatorf(ERR_PANIC, flags, fmt); abort(); } @@ -137,6 +163,9 @@ fatal_func nasm_assert_failed(const char *file, int line, const char *msg) nasm_panic("assertion %s failed at %s:%d", msg, file, line); } +#undef nasm_error_generator +#undef nasm_error_generatorf + /* * This is called when processing a -w or -W option, or a warning directive. * Returns true if if the action was successful. diff --git a/asm/nasm.c b/asm/nasm.c index 8f23b4b..a3ed2df 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -489,7 +489,7 @@ int main(int argc, char **argv) } else { dfmt = dfmt_find(ofmt, debug_format); if (!dfmt) { - nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, + nasm_fatalf(ERR_NOFILE | ERR_USAGE, "unrecognized debug format `%s' for" " output format `%s'", debug_format, ofmt->shortname); @@ -549,9 +549,9 @@ int main(int argc, char **argv) if (outname) { ofile = nasm_open_write(outname, NF_TEXT); if (!ofile) - nasm_fatal_fl(ERR_NOFILE, - "unable to open output file `%s'", - outname); + nasm_fatalf(ERR_NOFILE, + "unable to open output file `%s'", + outname); } else ofile = NULL; @@ -594,7 +594,7 @@ int main(int argc, char **argv) if (operating_mode & OP_NORMAL) { ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY); if (!ofile) - nasm_fatal_fl(ERR_NOFILE, + nasm_fatalf(ERR_NOFILE, "unable to open output file `%s'", outname); ofmt->init(); @@ -892,7 +892,7 @@ static bool process_arg(char *p, char *q, int pass) if (pass == 1) { ofmt = ofmt_find(param, &ofmt_alias); if (!ofmt) { - nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, + nasm_fatalf(ERR_NOFILE | ERR_USAGE, "unrecognised output format `%s' - " "use -hf for a list", param); } @@ -992,9 +992,9 @@ static bool process_arg(char *p, char *q, int pass) else if (nasm_stricmp("gnu", param) == 0) nasm_set_verror(nasm_verror_gnu); else - nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, - "unrecognized error reporting format `%s'", - param); + nasm_fatalf(ERR_NOFILE | ERR_USAGE, + "unrecognized error reporting format `%s'", + param); } break; @@ -1391,19 +1391,19 @@ static void parse_cmdline(int argc, char **argv, int pass) return; if (!inname) - nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, "no input file specified"); + nasm_fatalf(ERR_NOFILE | ERR_USAGE, "no input file specified"); else if ((errname && !strcmp(inname, errname)) || (outname && !strcmp(inname, outname)) || (listname && !strcmp(inname, listname)) || (depend_file && !strcmp(inname, depend_file))) - nasm_fatal_fl(ERR_USAGE, "will not overwrite input file"); + nasm_fatalf(ERR_USAGE, "will not overwrite input file"); if (errname) { error_file = nasm_open_write(errname, NF_TEXT); if (!error_file) { error_file = stderr; /* Revert to default! */ - nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, + nasm_fatalf(ERR_NOFILE | ERR_USAGE, "cannot open file `%s' for error messages", errname); } diff --git a/asm/preproc-nop.c b/asm/preproc-nop.c index 655eff7..43c0fbe 100644 --- a/asm/preproc-nop.c +++ b/asm/preproc-nop.c @@ -70,7 +70,7 @@ static void nop_reset(const char *file, int pass, struct strlist *deplist) nop_fp = nasm_open_read(file, NF_TEXT); if (!nop_fp) - nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file); + nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file); (void)pass; /* placate compilers */ strlist_add(deplist, file); diff --git a/asm/preproc.c b/asm/preproc.c index 76bd722..808303e 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -4950,7 +4950,7 @@ pp_reset(const char *file, int apass, struct strlist *dep_list) src_set(0, file); istk->lineinc = 1; if (!istk->fp) - nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file); + nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file); defining = NULL; nested_mac_count = 0; nested_rep_count = 0; diff --git a/include/error.h b/include/error.h index 1ee1afb..c87ea68 100644 --- a/include/error.h +++ b/include/error.h @@ -44,10 +44,16 @@ * An error reporting function should look like this. */ void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...); +void printf_func(1, 2) nasm_debug(const char *fmt, ...); +void printf_func(2, 3) nasm_debugf(int flags, const char *fmt, ...); +void printf_func(1, 2) nasm_warn(const char *fmt, ...); +void printf_func(2, 3) nasm_warnf(int flags, const char *fmt, ...); +void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...); +void printf_func(2, 3) nasm_nonfatalf(int flags, const char *fmt, ...); fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...); +fatal_func printf_func(2, 3) nasm_fatalf(int flags, const char *fmt, ...); fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...); -fatal_func printf_func(2, 3) nasm_fatal_fl(int flags, const char *fmt, ...); -fatal_func printf_func(2, 3) nasm_panic_fl(int flags, const char *fmt, ...); +fatal_func printf_func(2, 3) nasm_panicf(int flags, const char *fmt, ...); fatal_func nasm_panic_from_macro(const char *file, int line); #define panic() nasm_panic_from_macro(__FILE__, __LINE__); diff --git a/nasmlib/file.c b/nasmlib/file.c index c7bd1a6..4902bb5 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -119,8 +119,8 @@ FILE *nasm_open_read(const char *filename, enum file_flags flags) f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb"); if (!f && (flags & NF_FATAL)) - nasm_fatal_fl(ERR_NOFILE, "unable to open input file: `%s': %s", - filename, strerror(errno)); + nasm_fatalf(ERR_NOFILE, "unable to open input file: `%s': %s", + filename, strerror(errno)); return f; } @@ -132,8 +132,8 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags) f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb"); if (!f && (flags & NF_FATAL)) - nasm_fatal_fl(ERR_NOFILE, "unable to open output file: `%s': %s", - filename, strerror(errno)); + nasm_fatalf(ERR_NOFILE, "unable to open output file: `%s': %s", + filename, strerror(errno)); return f; } |