m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch-1_4 debian bug 175365 - line NONE:0


From: Eric Blake
Subject: branch-1_4 debian bug 175365 - line NONE:0
Date: Tue, 01 Aug 2006 07:05:10 -0600
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=175365 complains about

> $ m4 file.m4
> ...
> NONE:0: m4: ERROR: EOF in argument list
>
> why can't it make error lines with filename and line number so we can
> jump to them in emacs' compile mode?

Fixing this for m4wrap is prohibitive for the branch (see
http://lists.gnu.org/archive/html/m4-patches/2006-07/msg00079.html), but I
hope to get it done before m4 2.0.  But m4wrap tends to be less of a
problem for generating dangling input.

Fixing it for EOF in argument list, string, or comment should be done per
the patch below.  It was more difficult than what was attempted several
years ago on CVS head:
http://cvs.savannah.gnu.org/viewcvs/m4/m4/input.c?root=m4&r1=1.19&r2=1.20

Oops - valgrind won't normally catch the memory bug in revision 1.20 of
input.c, thanks to obstacks being so generous.  But saving m4_current_file
(which points to storage on the current_input obstack), then using it
after the obstack has been shrunk in pop_input, is asking for problems, on
the rare corner cases where you can coerce obstack_free to free the
storage used by m4_current_file (such as if the input filename was more
than an obstack_chunk in size).  So I will have to port this patch to CVS
head before m4 2.0 is released.

2006-08-01  Eric Blake  <address@hidden>

        * src/input.c (skip_line, next_token): Remember current file in
        case input file ends abruptly.  Addresses debian bug 175365.
        (pop_input): Defer freeing storage that holds previous file
        name...
        (pop_wrapup): to here, after error message is issued.
        * src/macro.c (expand_argument): Remember current file in case
        input file ends abruptly.
        * doc/m4.texinfo (Macro Arguments, Dnl, Changequote, Changecom)
        (M4wrap): Adjust testsuite accordingly.
        (Errprint): Document line number limitation of m4wrap.
        * NEWS: Document this fix.
        * THANKS: Update.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEz1GG84KuGfSFAYARAlRFAJ9pzXYYfYtOvQ3NDWYC+jDCj7B7vgCghx0Y
7h3aUNpBKoYUBAY/SrQfHS0=
=VQ+f
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.46
diff -u -p -r1.1.1.1.2.46 NEWS
--- NEWS        1 Aug 2006 02:53:35 -0000       1.1.1.1.2.46
+++ NEWS        1 Aug 2006 13:02:08 -0000
@@ -17,6 +17,8 @@ Version 1.4.6 - ?? 2006, by ??  (CVS ver
   collection.
 * The dnl macro now warns if end of file is encountered instead of a
   newline.
+* The error message when end of file is encountered now uses the file where
+  the dangling construct started, rather than "NONE:0".
 * The __file__ macro, and the -s/--synclines option, now show what
   directory a file was found in when the -I/--include option or M4PATH
   variable had an effect.
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.58
diff -u -p -r1.1.1.1.2.58 m4.texinfo
--- doc/m4.texinfo      1 Aug 2006 02:53:35 -0000       1.1.1.1.2.58
+++ doc/m4.texinfo      1 Aug 2006 13:02:09 -0000
@@ -1043,10 +1043,9 @@ It is an error if the end of file occurs
 @example
 define(
 ^D
address@hidden:0: m4: ERROR: end of file in argument list
address@hidden:stdin:1: ERROR: end of file in argument list
 @end example
 
-
 @node Quoting Arguments
 @section Quoting macro arguments
 
@@ -2317,7 +2316,7 @@ m4wrap(`m4wrap(`2 hi
 ')0 hi dnl 1 hi')
 @result{}
 ^D
address@hidden:0: m4: Warning: end of file treated as newline
address@hidden:NONE:0: Warning: end of file treated as newline
 @result{}0 HI 2 HI
 @end example
 
@@ -2454,7 +2453,7 @@ It is an error if the end of file occurs
 @example
 `dangling quote
 ^D
address@hidden:0: m4: ERROR: end of file in string
address@hidden:stdin:1: ERROR: end of file in string
 @end example
 
 @node Changecom
@@ -2551,7 +2550,7 @@ changecom(`/*', `*/')
 @result{}
 /*dangling comment
 ^D
address@hidden:0: m4: ERROR: end of file in comment
address@hidden:stdin:1: ERROR: end of file in comment
 @end example
 
 @node Changeword
@@ -2778,7 +2777,7 @@ file condition between two input files.
 m4wrap(`m4wrap(`)')len(abc')
 @result{}
 ^D
address@hidden:0: m4: ERROR: end of file in argument list
address@hidden:NONE:0: ERROR: end of file in argument list
 @end example
 
 @node File Inclusion
@@ -4054,6 +4053,11 @@ include(`incl.m4')
 @result{}
 @end example
 
+Currently, all text wrapped with @code{m4wrap} (@pxref{M4wrap}) behaves
+as though it came from line 0 of the file ``NONE''.  It is hoped that a
+future release of @code{m4} can overcome this limitation and remember
+which file invoked the call to @code{m4wrap}.
+
 @node M4exit
 @section Exiting from @code{m4}
 
Index: src/input.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/input.c,v
retrieving revision 1.1.1.1.2.14
diff -u -p -r1.1.1.1.2.14 input.c
--- src/input.c 1 Aug 2006 02:53:35 -0000       1.1.1.1.2.14
+++ src/input.c 1 Aug 2006 13:02:09 -0000
@@ -323,8 +323,22 @@ pop_input (void)
       current_line = isp->u.u_f.lineno;
       output_current_line = isp->u.u_f.out_lineno;
       start_of_input_line = isp->u.u_f.advance_line;
-      if (tmp != NULL)
-       output_current_line = -1;
+      if (tmp == NULL)
+       {
+         /* We have exhausted the current input stack.  However,
+            freeing the obstack now is a bad idea, since if we are in
+            the middle of a quote, comment, dnl, or argument
+            collection, there is still a pointer to the former
+            current_file that we must not invalidate until after the
+            warning message has been issued.  Setting next to a
+            non-string is safe in this case, because the only place
+            more input could come from is another push_file or
+            pop_wrapup, both of which then free the input_block.  */
+         next = isp;
+         isp = NULL;
+         return;
+       }
+      output_current_line = -1;
       break;
 
     default:
@@ -347,6 +361,7 @@ pop_input (void)
 boolean
 pop_wrapup (void)
 {
+  next = NULL;
   obstack_free (current_input, NULL);
   free (current_input);
 
@@ -508,11 +523,16 @@ void
 skip_line (void)
 {
   int ch;
+  const char *file = current_file;
+  int line = current_line;
 
   while ((ch = next_char ()) != CHAR_EOF && ch != '\n')
     ;
   if (ch == CHAR_EOF)
-    M4ERROR ((warning_status, 0, "Warning: end of file treated as newline"));
+    /* current_file changed to "NONE" if we see CHAR_EOF, use the
+       previous value we stored earlier.  */
+    error_at_line (warning_status, 0, file, line,
+                  "Warning: end of file treated as newline");
 }
 
 
@@ -730,6 +750,8 @@ next_token (token_data *td)
   int startpos;
   char *orig_text = 0;
 #endif
+  const char *file = current_file;
+  int line = current_line;
 
   obstack_free (&token_stack, token_bottom);
   obstack_1grow (&token_stack, '\0');
@@ -759,8 +781,10 @@ next_token (token_data *td)
       if (ch != CHAR_EOF)
        obstack_grow (&token_stack, ecomm.string, ecomm.length);
       else
-        M4ERROR ((EXIT_FAILURE, 0,
-                  "ERROR: end of file in comment"));
+       /* current_file changed to "NONE" if we see CHAR_EOF, use the
+          previous value we stored earlier.  */
+       error_at_line (EXIT_FAILURE, 0, file, line,
+                      "ERROR: end of file in comment");
 
       type = TOKEN_STRING;
     }
@@ -829,8 +853,10 @@ next_token (token_data *td)
        {
          ch = next_char ();
          if (ch == CHAR_EOF)
-           M4ERROR ((EXIT_FAILURE, 0,
-                     "ERROR: end of file in string"));
+           /* current_file changed to "NONE" if we see CHAR_EOF, use
+              the previous value we stored earlier.  */
+           error_at_line (EXIT_FAILURE, 0, file, line,
+                          "ERROR: end of file in string");
 
          if (MATCH (ch, rquote.string))
            {
Index: src/macro.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/macro.c,v
retrieving revision 1.1.1.1.2.7
diff -u -p -r1.1.1.1.2.7 macro.c
--- src/macro.c 27 Jul 2006 21:41:12 -0000      1.1.1.1.2.7
+++ src/macro.c 1 Aug 2006 13:02:09 -0000
@@ -115,6 +115,8 @@ expand_argument (struct obstack *obs, to
   token_data td;
   char *text;
   int paren_level;
+  const char *file = current_file;
+  int line = current_line;
 
   TOKEN_DATA_TYPE (argp) = TOKEN_VOID;
 
@@ -157,8 +159,10 @@ expand_argument (struct obstack *obs, to
          break;
 
        case TOKEN_EOF:
-         M4ERROR ((EXIT_FAILURE, 0,
-                   "ERROR: end of file in argument list"));
+         /* current_file changed to "NONE" if we see TOKEN_EOF, use the
+            previous value we stored earlier.  */
+         error_at_line (EXIT_FAILURE, 0, file, line,
+                        "ERROR: end of file in argument list");
          break;
 
        case TOKEN_WORD:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]