Eric Blake <ebb9 <at> byu.net> writes: Hi Gary,
> > > Man, I wish I could get glibc to provide a va_list variant of > > error/error_at_line (I'm in the process of proposing that, trying to bring > > gnulib and glibc back in sync and fix other bugs in the error.c module). > > Without it, and due to the fact that error_print_progname takes no > > arguments, I have to use the relatively gross hack of another global > > variable that tells the callback whether it was invoked from error or > > error_at_line. > > I agree with you that the current glibc API doesn't fit our needs at > all, but I also don't think using a kludgy macro to paper over the > cracks is a good approach. I see no problem with writing our own error > module with an API we like, and using that. We can write it in such a > way as to not break the existing glibc API, and if gnulib or glibc take > the code (or an equivalent) in due course, then all well and good, but > even if they don't: we still have a sensible API for our use. > If my proposed[1] gnulib module verror is accepted, then this patch would clean up m4 to avoid the hacks. A subsequent mechanical cleanup could then avoid calling macros, if desired. (Maybe it's just me, but M4ERROR(()) doesn't look as nice as m4_error().) [1]http://www.nabble.com/new-module-proposal%3A-verror-tf2052120.html#a5653449 2006-08-04 Eric Blake <[EMAIL PROTECTED]> * m4/gnulib-cache.m4: Augment with gnulib-tool --import verror. * src/m4.h (m4_error): New function. (M4ERROR, M4ERROR_AT_LINE): Reimplement without hacking around error module deficiencies. (reference_error): No longer needed. * src/m4.c (m4_error): Implement. (main): No longer need to install error callback. Index: m4/gnulib-cache.m4 =================================================================== RCS file: /sources/m4/m4/m4/Attic/gnulib-cache.m4,v retrieving revision 1.1.2.10 diff -u -r1.1.2.10 gnulib-cache.m4 --- m4/gnulib-cache.m4 30 Jul 2006 23:46:51 -0000 1.1.2.10 +++ m4/gnulib-cache.m4 4 Aug 2006 16:27:20 -0000 @@ -15,10 +15,10 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 -- doc-base=doc --aux-dir=. --macro-prefix=M4 alloca binary-io close-stream error fdl fopen-safer free gendocs getopt mkstemp obstack regex stdlib-safer strtol tmpfile-safer unlocked-io xalloc xvasprintf +# gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 -- doc-base=doc --aux-dir=. --no-libtool --macro-prefix=M4 alloca binary-io close- stream error fdl fopen-safer free gendocs getopt mkstemp obstack regex stdlib- safer strtol tmpfile-safer unlocked-io verror xalloc xvasprintf # Specification in the form of a few gnulib-tool.m4 macro invocations: -gl_MODULES([alloca binary-io close-stream error fdl fopen-safer free gendocs getopt mkstemp obstack regex stdlib-safer strtol tmpfile-safer unlocked-io xalloc xvasprintf]) +gl_MODULES([alloca binary-io close-stream error fdl fopen-safer free gendocs getopt mkstemp obstack regex stdlib-safer strtol tmpfile-safer unlocked-io verror xalloc xvasprintf]) gl_AVOID([]) gl_SOURCE_BASE([lib]) gl_M4_BASE([m4]) Index: src/m4.c =================================================================== RCS file: /sources/m4/m4/src/Attic/m4.c,v retrieving revision 1.1.1.1.2.25 diff -u -r1.1.1.1.2.25 m4.c --- src/m4.c 4 Aug 2006 13:19:41 -0000 1.1.1.1.2.25 +++ src/m4.c 4 Aug 2006 16:27:20 -0000 @@ -91,22 +91,16 @@ argument. */ boolean suppress_line; -/*---------------------------------------------------------------. -| Callback used by error to print program name, source, and line | -| reference. | -`---------------------------------------------------------------*/ +/*-----------------------. +| Wrapper around error. | +`-----------------------*/ void -reference_error (void) +m4_error (int status, int errnum, const char *format, ...) { - /* error already flushed stdout before calling us. */ - if (suppress_line) - { - fprintf (stderr, "%s:", program_name); - suppress_line = FALSE; - } - else - fprintf (stderr, "%s:%s:%d: ", program_name, current_file, current_line); + va_list args; + va_start (args, format); + verror_at_line (status, errnum, current_file, current_line, format, args); } #ifdef USE_STACKOVF @@ -278,7 +272,6 @@ FILE *fp; program_name = argv[0]; - error_print_progname = reference_error; retcode = EXIT_SUCCESS; include_init (); Index: src/m4.h =================================================================== RCS file: /sources/m4/m4/src/m4.h,v retrieving revision 1.1.1.1.2.25 diff -u -r1.1.1.1.2.25 m4.h --- src/m4.h 4 Aug 2006 13:19:41 -0000 1.1.1.1.2.25 +++ src/m4.h 4 Aug 2006 16:27:20 -0000 @@ -56,6 +56,7 @@ #include "stdio--.h" #include "stdlib--.h" #include "unistd--.h" +#include "verror.h" #include "xalloc.h" /* If FALSE is defined, we presume TRUE is defined too. In this case, @@ -123,33 +124,10 @@ extern int retcode; extern const char *program_name; -/* It would be so much nicer if the gnulib error module provided a - va_list version of error, so that we wouldn't need to use macros - and a global hook variable. Oh well. */ -#if 0 void m4_error (int, int, const char *, ...) M4_GNUC_PRINTF(3, 4); -/* Would be implemented as: -void -m4_error (int status, int errnum, const char *format, ...) -{ - va_list args; - va_start (args, format); - verror_at_line (status, errnum, current_file, current_line, format, args); -} -*/ -#endif - -#define M4ERROR(Arglist) (error Arglist) -#define M4ERROR_AT_LINE(Arglist) \ - do \ - { \ - suppress_line = TRUE; \ - (error_at_line Arglist); \ - } \ - while (0) -extern boolean suppress_line; -void reference_error (void); +#define M4ERROR(Arglist) (m4_error Arglist) +#define M4ERROR_AT_LINE(Arglist) (error_at_line Arglist) #ifdef USE_STACKOVF void setup_stackovf_trap (char *const *, char *const *, _______________________________________________ M4-discuss mailing list M4-discuss@gnu.org http://lists.gnu.org/mailman/listinfo/m4-discuss