m4-commit
[Top][All Lists]
Advanced

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

[SCM] GNU M4 source repository branch, branch-1_4, updated. branch-cvs-r


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, branch-1_4, updated. branch-cvs-readonly-11-g6bfe1ba
Date: Tue, 13 Nov 2007 19:05:22 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=6bfe1ba306cacd8d9316647f3b9f276cf56b31a8

The branch, branch-1_4 has been updated
       via  6bfe1ba306cacd8d9316647f3b9f276cf56b31a8 (commit)
      from  143b597a5a4d66362c29709cce78b7bd10c64817 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6bfe1ba306cacd8d9316647f3b9f276cf56b31a8
Author: Eric Blake <address@hidden>
Date:   Tue Nov 13 11:59:43 2007 -0700

    Fix memory leak in tail recursion.
    
    * src/input.c (push_string_init): Let go of memory earlier.
    (next_char_1): Make end of string detection reliable.
    (match_input): Simplify use of push_string_init.
    * NEWS: Document this fix.
    
    Signed-off-by: Eric Blake <address@hidden>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog   |    8 ++++++++
 NEWS        |    1 +
 src/input.c |   53 +++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 86d8ad4..b52f3e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-11-13  Eric Blake  <address@hidden>
+
+       Fix memory leak in tail recursion.
+       * src/input.c (push_string_init): Let go of memory earlier.
+       (next_char_1): Make end of string detection reliable.
+       (match_input): Simplify use of push_string_init.
+       * NEWS: Document this fix.
+
 2007-11-07  Eric Blake  <address@hidden>
 
        * doc/m4.texinfo (Pseudo Arguments): Test more corner cases.
diff --git a/NEWS b/NEWS
index 6d667f0..b92630b 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Version 1.4.11 - ?? ??? 2007, by ????  (git version 1.4.10a-*)
   possible to concatenate a builtin macro with anything else.
 * Several improvements in `index', `regexp', and `patsubst' builtins to
   speed up typical Autoconf usage.
+* Memory usage is greatly reduced in recursive macros.
 * A number of portability improvements inherited from gnulib.
 
 Version 1.4.10 - 09 Jul 2007, by Eric Blake  (CVS version 1.4.9c)
diff --git a/src/input.c b/src/input.c
index 23903f3..3ef7b83 100644
--- a/src/input.c
+++ b/src/input.c
@@ -241,7 +241,37 @@ push_macro (builtin_func *func)
 struct obstack *
 push_string_init (void)
 {
+  /* Free any memory occupied by completely parsed strings.  */
+  bool pruning = true;
   assert (next == NULL);
+  while (isp && pruning)
+    {
+      switch (isp->type)
+       {
+       case INPUT_STRING:
+         if (*isp->u.u_s.string)
+           pruning = false;
+         break;
+
+       case INPUT_FILE:
+       case INPUT_MACRO:
+         pruning = false;
+         break;
+
+       default:
+         assert (!"push_string_init");
+         abort ();
+       }
+      if (pruning)
+       {
+         next = isp;
+         isp = isp->prev;
+       }
+    }
+  if (next)
+    obstack_free (current_input, next);
+
+  /* Reserve the next location on the obstack.  */
   next = (input_block *) obstack_alloc (current_input,
                                        sizeof (struct input_block));
   next->type = INPUT_STRING;
@@ -497,9 +527,12 @@ next_char_1 (void)
       switch (isp->type)
        {
        case INPUT_STRING:
-         ch = to_uchar (*isp->u.u_s.string++);
+         ch = to_uchar (*isp->u.u_s.string);
          if (ch != '\0')
-           return ch;
+           {
+             *isp->u.u_s.string++;
+             return ch;
+           }
          break;
 
        case INPUT_FILE:
@@ -536,10 +569,10 @@ next_char_1 (void)
     }
 }
 
-/*------------------------------------------------------------------------.
-| skip_line () simply discards all immediately following characters, upto |
-| the first newline.  It is only used from m4_dnl ().                    |
-`------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------.
+| skip_line () simply discards all immediately following characters, |
+| up to the first newline.  It is only used from m4_dnl ().          |
+`-------------------------------------------------------------------*/
 
 void
 skip_line (void)
@@ -607,12 +640,8 @@ match_input (const char *s, bool consume)
     }
 
   /* Failed or shouldn't consume, push back input.  */
-  {
-    struct obstack *h = push_string_init ();
-
-    /* `obstack_grow' may be macro evaluating its arg 1 several times. */
-    obstack_grow (h, t, n);
-  }
+  push_string_init ();
+  obstack_grow (current_input, t, n);
   push_string_finish ();
   return result;
 }


hooks/post-receive
--
GNU M4 source repository




reply via email to

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