From: Peter Johnson Date: Tue, 16 Dec 2003 03:54:15 +0000 (-0000) Subject: Properly handle fatal errors (like missing include file) from the real X-Git-Tag: v0.4.0~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c50b6c3198361cae4d52c8b248f0501cfb674a2;p=yasm Properly handle fatal errors (like missing include file) from the real NASM parser by changing the libyasm yasm_fatal() interface to use va_list instead of ... variable arguments. Add a yasm__fatal() function that takes ... and calls yasm_fatal(). Bugzilla bug #22 Reported by: mu@tortall.net svn path=/trunk/yasm/; revision=1086 --- diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 22d791c5..91e6efd0 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -100,7 +100,7 @@ static void print_error(const char *fmt, ...); static /*@exits@*/ void handle_yasm_int_error(const char *file, unsigned int line, const char *message); -static /*@exits@*/ void handle_yasm_fatal(const char *message, ...); +static /*@exits@*/ void handle_yasm_fatal(const char *message, va_list va); static const char *handle_yasm_gettext(const char *msgid); static void print_yasm_error(const char *filename, unsigned long line, const char *msg); @@ -1002,13 +1002,10 @@ handle_yasm_int_error(const char *file, unsigned int line, const char *message) } static /*@exits@*/ void -handle_yasm_fatal(const char *fmt, ...) +handle_yasm_fatal(const char *fmt, va_list va) { - va_list va; fprintf(stderr, "yasm: %s: ", _("FATAL")); - va_start(va, fmt); vfprintf(stderr, gettext(fmt), va); - va_end(va); fputc('\n', stderr); exit(EXIT_FAILURE); } diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index af07f2d0..9d2c9382 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -45,14 +45,14 @@ /* Default handlers for replacable functions */ static /*@exits@*/ void def_internal_error_ (const char *file, unsigned int line, const char *message); -static /*@exits@*/ void def_fatal(const char *message, ...); +static /*@exits@*/ void def_fatal(const char *message, va_list va); static const char *def_gettext_hook(const char *msgid); /* Storage for errwarn's "extern" functions */ /*@exits@*/ void (*yasm_internal_error_) (const char *file, unsigned int line, const char *message) = def_internal_error_; -/*@exits@*/ void (*yasm_fatal) (const char *message, ...) = def_fatal; +/*@exits@*/ void (*yasm_fatal) (const char *message, va_list va) = def_fatal; const char * (*yasm_gettext_hook) (const char *msgid) = def_gettext_hook; /* Enabled warnings. See errwarn.h for a list. */ @@ -165,13 +165,10 @@ def_internal_error_(const char *file, unsigned int line, const char *message) * memory), so just exit immediately. */ static void -def_fatal(const char *fmt, ...) +def_fatal(const char *fmt, va_list va) { - va_list va; fprintf(stderr, "%s: ", yasm_gettext_hook(N_("FATAL"))); - va_start(va, fmt); vfprintf(stderr, yasm_gettext_hook(fmt), va); - va_end(va); fputc('\n', stderr); exit(EXIT_FAILURE); } @@ -392,3 +389,13 @@ yasm_errwarn_output_all(yasm_linemap *lm, int warning_as_error, print_warning(filename, line, we->msg); } } + +void +yasm__fatal(const char *message, ...) +{ + va_list va; + va_start(va, message); + yasm_fatal(message, va); + /*@notreached@*/ + va_end(va); +} diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 8d33c253..67c6dfd5 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -71,9 +71,17 @@ extern /*@exits@*/ void (*yasm_internal_error_) * \warning This function must NOT return to calling code; exit or longjmp * instead. * \param message fatal error message + * \param va va_list argument list for message + */ +extern /*@exits@*/ void (*yasm_fatal) (const char *message, va_list va); + +/** Reporting point of fatal errors, with variable arguments (internal only). + * \warning This function calls #yasm_fatal, and thus does not return to the + * calling code. + * \param message fatal error message * \param ... argument list for message */ -extern /*@exits@*/ void (*yasm_fatal) (const char *message, ...); +/*@exits@*/ void yasm__fatal(const char *message, ...); /** Log an error at a given line, displaying a different line. va_list version * of yasm__error_at(). diff --git a/libyasm/xmalloc.c b/libyasm/xmalloc.c index 24e84777..a6ebeaa6 100644 --- a/libyasm/xmalloc.c +++ b/libyasm/xmalloc.c @@ -26,7 +26,7 @@ */ #define YASM_LIB_INTERNAL #include "util.h" -RCSID("$IdPath: yasm/libyasm/xmalloc.c,v 1.13 2003/03/15 05:07:48 peter Exp $"); +RCSID("$IdPath$"); #include "coretype.h" #include "errwarn.h" @@ -66,7 +66,7 @@ def_xmalloc(size_t size) size = 1; newmem = malloc(size); if (!newmem) - yasm_fatal(N_("out of memory")); + yasm__fatal(N_("out of memory")); return newmem; } @@ -81,7 +81,7 @@ def_xcalloc(size_t nelem, size_t elsize) newmem = calloc(nelem, elsize); if (!newmem) - yasm_fatal(N_("out of memory")); + yasm__fatal(N_("out of memory")); return newmem; } @@ -98,7 +98,7 @@ def_xrealloc(void *oldmem, size_t size) else newmem = realloc(oldmem, size); if (!newmem) - yasm_fatal(N_("out of memory")); + yasm__fatal(N_("out of memory")); return newmem; } diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 349eb5f4..872a4abd 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -490,7 +490,7 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) pos = ftell(info->f); if (pos == -1) { - yasm_fatal(N_("could not get file position on output file")); + yasm__fatal(N_("could not get file position on output file")); /*@notreached@*/ return 1; } @@ -518,7 +518,7 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) pos = ftell(info->f); if (pos == -1) { - yasm_fatal(N_("could not get file position on output file")); + yasm__fatal(N_("could not get file position on output file")); /*@notreached@*/ return 1; } @@ -599,7 +599,7 @@ coff_objfmt_output(FILE *f, yasm_object *object, int all_syms) /* Allocate space for headers by seeking forward */ if (fseek(f, (long)(20+40*(coff_objfmt_parse_scnum-1)), SEEK_SET) < 0) { - yasm_fatal(N_("could not seek on output file")); + yasm__fatal(N_("could not seek on output file")); /*@notreached@*/ return; } @@ -629,7 +629,7 @@ coff_objfmt_output(FILE *f, yasm_object *object, int all_syms) } pos = ftell(f); if (pos == -1) { - yasm_fatal(N_("could not get file position on output file")); + yasm__fatal(N_("could not get file position on output file")); /*@notreached@*/ return; } @@ -790,7 +790,7 @@ coff_objfmt_output(FILE *f, yasm_object *object, int all_syms) /* Write headers */ if (fseek(f, 0, SEEK_SET) < 0) { - yasm_fatal(N_("could not seek on output file")); + yasm__fatal(N_("could not seek on output file")); /*@notreached@*/ return; } diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c index 88a42750..6bd93780 100644 --- a/modules/preprocs/nasm/nasm-preproc.c +++ b/modules/preprocs/nasm/nasm-preproc.c @@ -100,7 +100,8 @@ nasm_efunc(int severity, const char *fmt, ...) yasm__error_va(yasm_linemap_get_current(cur_lm), fmt, va); break; case ERR_FATAL: - yasm_fatal(N_("unknown")); /* FIXME */ + yasm_fatal(fmt, va); + /*@notreached@*/ break; case ERR_PANIC: yasm_internal_error(fmt); /* FIXME */ diff --git a/modules/preprocs/nasm/tests/Makefile.inc b/modules/preprocs/nasm/tests/Makefile.inc index 16dad51d..57fc86a7 100644 --- a/modules/preprocs/nasm/tests/Makefile.inc +++ b/modules/preprocs/nasm/tests/Makefile.inc @@ -5,3 +5,5 @@ TESTS += modules/preprocs/nasm/tests/nasmpp_test.sh EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp_test.sh EXTRA_DIST += modules/preprocs/nasm/tests/ifcritical-err.asm EXTRA_DIST += modules/preprocs/nasm/tests/ifcritical-err.errwarn +EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.asm +EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.errwarn diff --git a/modules/preprocs/nasm/tests/noinclude-err.asm b/modules/preprocs/nasm/tests/noinclude-err.asm new file mode 100644 index 00000000..08625396 --- /dev/null +++ b/modules/preprocs/nasm/tests/noinclude-err.asm @@ -0,0 +1 @@ +%include "doesnotexist.inc" diff --git a/modules/preprocs/nasm/tests/noinclude-err.errwarn b/modules/preprocs/nasm/tests/noinclude-err.errwarn new file mode 100644 index 00000000..68f7152e --- /dev/null +++ b/modules/preprocs/nasm/tests/noinclude-err.errwarn @@ -0,0 +1 @@ +yasm: FATAL: unable to open include file `doesnotexist.inc'