m4-patches
[Top][All Lists]
Advanced

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

Re: more testsuite coverage for autoconf idioms


From: Eric Blake
Subject: Re: more testsuite coverage for autoconf idioms
Date: Thu, 01 Nov 2007 06:42:28 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

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

According to Eric Blake on 10/31/2007 9:04 AM:
> Eric Blake <ebb9 <at> byu.net> writes:
> 
>> I have been working away on a series of patches to speed up recursive
>> macro handling (with a goal to make $@ handling linear instead of
>> quadratic).  That series is not ready yet,
> 
> Still not ready to post, although I have made progress, and uncovered a 
> couple 
> more corner cases to be aware of.  Included in the patch below.

My work on $@ references turned up another failure that tripped autoconf,
but not the testsuite.  And diagnosis was tough, when all that autoconf
would say was "ERROR: end of file in string", with no indication of which
macro expansion went wrong (the real problem was an obstack issue
introduced by the current draft of my $@ code - I was calling obstack_free
before using the memory just freed.  For small strings it tends to work,
but for large strings, such as those used in autoconf, it crosses obstack
chunk boundaries with dire results.  I wish there were a debugging variant
of obstack_free which would overwrite the rest of the current chunk with a
known bit pattern, which would make failures like this easier to detect
with small strings).  So this patch improves the error message.

- --
Don't work too hard, make some time for fun as well!

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

iD8DBQFHKcm084KuGfSFAYARAmgcAKChLizU3D4JPpubsldZ9e6Cc5RTmQCgx3Ev
XRzhaMpIbCmRCTdUTZMB8Co=
=x+SA
-----END PGP SIGNATURE-----
>From 3a38f813357e5527db579eeb727360a366a68711 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 1 Nov 2007 06:31:22 -0600
Subject: [PATCH] Improve error message when early end of file occurs.

* doc/m4.texinfo (Macro Arguments, Changequote, Changecom)
(M4wrap): Adjust to new messages.
(Improved capitalize): Enhance test.
* src/m4.h (next_token): Adjust prototype.
* src/input.c (next_token): Add new parameter, and improve error
message.
(lex_debug): Adjust callers.
* src/symtab.c (symtab_debug): Likewise.
* src/macro.c (expand_input, collect_arguments): Likewise.
(expand_argument): Likewise, and add parameter.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog      |   14 ++++++++++++++
 doc/m4.texinfo |   34 ++++++++++++++++++++++------------
 src/input.c    |   26 +++++++++++++++-----------
 src/m4.h       |    4 ++--
 src/macro.c    |   33 +++++++++++++++++----------------
 src/symtab.c   |    2 +-
 6 files changed, 71 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a25c84d..aa00ce0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-11-01  Eric Blake  <address@hidden>
+
+       Improve error message when early end of file occurs.
+       * doc/m4.texinfo (Macro Arguments, Changequote, Changecom)
+       (M4wrap): Adjust to new messages.
+       (Improved capitalize): Enhance test.
+       * src/m4.h (next_token): Adjust prototype.
+       * src/input.c (next_token): Add new parameter, and improve error
+       message.
+       (lex_debug): Adjust callers.
+       * src/symtab.c (symtab_debug): Likewise.
+       * src/macro.c (expand_input, collect_arguments): Likewise.
+       (expand_argument): Likewise, and add parameter.
+
 2007-10-31  Eric Blake  <address@hidden>
 
        Test more corner cases.
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 42c5438..9a1816b 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -1507,7 +1507,7 @@ hello world
 @result{}hello world
 define(
 ^D
address@hidden:stdin:2: ERROR: end of file in argument list
address@hidden:stdin:2: define: end of file in argument list
 @end example
 
 @node Quoting Arguments
@@ -3692,7 +3692,14 @@ It is an error if the end of file occurs within a quoted 
string.
 @result{}hello world
 `dangling quote
 ^D
address@hidden:stdin:2: ERROR: end of file in string
address@hidden:stdin:2: end of file in string
address@hidden example
+
address@hidden status: 1
address@hidden
+ifelse(`dangling quote
+^D
address@hidden:stdin:1: ifelse: end of file in string
 @end example
 
 @node Changecom
@@ -3843,7 +3850,16 @@ changecom(`/*', `*/')
 @result{}
 /*dangling comment
 ^D
address@hidden:stdin:2: ERROR: end of file in comment
address@hidden:stdin:2: end of file in comment
address@hidden example
+
address@hidden status: 1
address@hidden
+changecom(`/*', `*/')
address@hidden
+len(/*dangling comment
+^D
address@hidden:stdin:2: len: end of file in comment
 @end example
 
 @node Changeword
@@ -4155,7 +4171,7 @@ file condition between two input files.
 m4wrap(`m4wrap(`)')len(abc')
 @result{}
 ^D
address@hidden:stdin:1: ERROR: end of file in argument list
address@hidden:stdin:1: len: end of file in argument list
 @end example
 
 @node File Inclusion
@@ -7117,14 +7133,8 @@ define(`active', `act1, ive')dnl
 define(`Active', `Act2, Ive')dnl
 define(`ACTIVE', `ACT3, IVE')dnl
 define(`A', `OOPS')dnl
-capitalize(active)
address@hidden,Ive
-capitalize(`active')
address@hidden, Ive
-capitalize(``active'')
address@hidden
-capitalize(```actIVE''')
address@hidden'
+capitalize(active; `active'; ``active''; ```actIVE''')
address@hidden,Ive; Act2, Ive; Active; `Active'
 undivert(`capitalize2.m4')dnl
 @result{}divert(`-1')
 @result{}# upcase(text)
diff --git a/src/input.c b/src/input.c
index 7f6f87b..b81d086 100644
--- a/src/input.c
+++ b/src/input.c
@@ -156,9 +156,9 @@ static struct re_pattern_buffer word_regexp;
 static int default_word_regexp;
 static struct re_registers regs;
 
-#else /* ! ENABLE_CHANGEWORD */
+#else /* !ENABLE_CHANGEWORD */
 # define default_word_regexp 1
-#endif /* ! ENABLE_CHANGEWORD */
+#endif /* !ENABLE_CHANGEWORD */
 
 #ifdef DEBUG_INPUT
 static const char *token_type_string (token_type);
@@ -814,17 +814,19 @@ set_word_regexp (const char *regexp)
 | TOKEN_STRING for a quoted string; TOKEN_WORD for something that is  |
 | a potential macro name; and TOKEN_SIMPLE for any single character   |
 | that is not a part of any of the previous types.  If LINE is not    |
-| NULL, set *LINE to the line where the token starts.                 |
-|                                                                     |
-| Next_token () return the token type, and passes back a pointer to   |
+| NULL, set *LINE to the line where the token starts.  Report errors  |
+| (unterminated comments or strings) on behalf of CALLER, if         |
+| non-NULL.                                                          |
+|                                                                    |
+| Next_token () returns the token type, and passes back a pointer to  |
 | the token data through TD.  The token text is collected on the      |
 | obstack token_stack, which never contains more than one token text  |
-| at a time.  The storage pointed to by the fields in TD is           |
+| at a time.  The storage pointed to by the fields in TD is          |
 | therefore subject to change the next time next_token () is called.  |
 `--------------------------------------------------------------------*/
 
 token_type
-next_token (token_data *td, int *line)
+next_token (token_data *td, int *line, const char *caller)
 {
   int ch;
   int quote_level;
@@ -876,7 +878,8 @@ next_token (token_data *td, int *line)
        /* current_file changed to "" if we see CHAR_EOF, use the
           previous value we stored earlier.  */
        M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
-                         "ERROR: end of file in comment"));
+                         "%s%send of file in comment",
+                         caller ? caller : "", caller ? ": " : ""));
 
       type = TOKEN_STRING;
     }
@@ -959,7 +962,8 @@ next_token (token_data *td, int *line)
            /* current_file changed to "" if we see CHAR_EOF, use
               the previous value we stored earlier.  */
            M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
-                             "ERROR: end of file in string"));
+                             "%s%send of file in string",
+                             caller ? caller : "", caller ? ": " : ""));
 
          if (MATCH (ch, rquote.string, true))
            {
@@ -1018,7 +1022,7 @@ peek_token (void)
     }
   else if ((default_word_regexp && (isalpha (ch) || ch == '_'))
 #ifdef ENABLE_CHANGEWORD
-      || (! default_word_regexp && word_start[ch])
+      || (!default_word_regexp && word_start[ch])
 #endif /* ENABLE_CHANGEWORD */
       )
     {
@@ -1117,7 +1121,7 @@ lex_debug (void)
   token_type t;
   token_data td;
 
-  while ((t = next_token (&td)) != TOKEN_EOF)
+  while ((t = next_token (&td, NULL, "<debug>")) != TOKEN_EOF)
     print_token ("lex", t, &td);
 }
 #endif
diff --git a/src/m4.h b/src/m4.h
index ce7bdc0..b4b9b85 100644
--- a/src/m4.h
+++ b/src/m4.h
@@ -93,7 +93,7 @@ typedef void builtin_func (struct obstack *, int, token_data 
**);
 typedef bool bool_bitfield;
 #else
 typedef unsigned int bool_bitfield;
-#endif /* ! __GNUC__ */
+#endif /* !__GNUC__ */
 
 /* Take advantage of GNU C compiler source level optimization hints,
    using portable macros.  */
@@ -286,7 +286,7 @@ typedef enum token_data_type token_data_type;
 
 void input_init (void);
 token_type peek_token (void);
-token_type next_token (token_data *, int *);
+token_type next_token (token_data *, int *, const char *);
 void skip_line (void);
 
 /* push back input */
diff --git a/src/macro.c b/src/macro.c
index f9c5fe1..0034789 100644
--- a/src/macro.c
+++ b/src/macro.c
@@ -64,7 +64,7 @@ expand_input (void)
   obstack_init (&argc_stack);
   obstack_init (&argv_stack);
 
-  while ((t = next_token (&td, &line)) != TOKEN_EOF)
+  while ((t = next_token (&td, &line, NULL)) != TOKEN_EOF)
     expand_token ((struct obstack *) NULL, t, &td, line);
 
   obstack_free (&argc_stack, NULL);
@@ -126,18 +126,19 @@ expand_token (struct obstack *obs, token_type t, 
token_data *td, int line)
 }
 
 
-/*-------------------------------------------------------------------------.
-| This function parses one argument to a macro call.  It expects the first |
-| left parenthesis, or the separating comma to have been read by the      |
-| caller.  It skips leading whitespace, and reads and expands tokens,     |
-| until it finds a comma or an right parenthesis at the same level of     |
-| parentheses.  It returns a flag indicating whether the argument read are |
-| the last for the active macro call.  The argument are build on the      |
-| obstack OBS, indirectly through expand_token ().                        |
-`-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------.
+| This function parses one argument to a macro call.  It expects the |
+| first left parenthesis or the separating comma to have been read   |
+| by the caller.  It skips leading whitespace, then reads and       |
+| expands tokens, until it finds a comma or right parenthesis at the |
+| same level of parentheses.  It returns a flag indicating whether   |
+| the argument read is the last for the active macro call.  The             |
+| argument is built on the obstack OBS, indirectly through          |
+| expand_token ().  Report errors on behalf of CALLER.              |
+`-------------------------------------------------------------------*/
 
 static bool
-expand_argument (struct obstack *obs, token_data *argp)
+expand_argument (struct obstack *obs, token_data *argp, const char *caller)
 {
   token_type t;
   token_data td;
@@ -151,7 +152,7 @@ expand_argument (struct obstack *obs, token_data *argp)
   /* Skip leading white space.  */
   do
     {
-      t = next_token (&td, NULL);
+      t = next_token (&td, NULL, caller);
     }
   while (t == TOKEN_SIMPLE && isspace (to_uchar (*TOKEN_DATA_TEXT (&td))));
 
@@ -193,7 +194,7 @@ expand_argument (struct obstack *obs, token_data *argp)
          /* current_file changed to "" if we see TOKEN_EOF, use the
             previous value we stored earlier.  */
          M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
-                           "ERROR: end of file in argument list"));
+                           "%s: end of file in argument list", caller));
          break;
 
        case TOKEN_WORD:
@@ -215,7 +216,7 @@ expand_argument (struct obstack *obs, token_data *argp)
          abort ();
        }
 
-      t = next_token (&td, NULL);
+      t = next_token (&td, NULL, caller);
     }
 }
 
@@ -241,10 +242,10 @@ collect_arguments (symbol *sym, struct obstack *argptr,
 
   if (peek_token () == TOKEN_OPEN)
     {
-      next_token (&td, NULL); /* gobble parenthesis */
+      next_token (&td, NULL, SYMBOL_NAME (sym)); /* gobble parenthesis */
       do
        {
-         more_args = expand_argument (arguments, &td);
+         more_args = expand_argument (arguments, &td, SYMBOL_NAME (sym));
 
          if (!groks_macro_args && TOKEN_DATA_TYPE (&td) == TOKEN_FUNC)
            {
diff --git a/src/symtab.c b/src/symtab.c
index 872cfaa..8195e2e 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -357,7 +357,7 @@ symtab_debug (void)
   int delete;
   static int i;
 
-  while (next_token (&td) == TOKEN_WORD)
+  while (next_token (&td, NULL, "<debug>") == TOKEN_WORD)
     {
       text = TOKEN_DATA_TEXT (&td);
       if (*text == '_')
-- 
1.5.3.2


reply via email to

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