m4-commit
[Top][All Lists]
Advanced

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

Changes to m4/modules/gnu.c,v


From: Eric Blake
Subject: Changes to m4/modules/gnu.c,v
Date: Tue, 03 Oct 2006 12:57:18 +0000

CVSROOT:        /sources/m4
Module name:    m4
Changes by:     Eric Blake <ericb>      06/10/03 12:57:18

Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- modules/gnu.c       29 Sep 2006 18:20:12 -0000      1.59
+++ modules/gnu.c       3 Oct 2006 12:57:18 -0000       1.60
@@ -109,6 +109,7 @@
   struct re_registers regs;    /* match registers */
 } m4_pattern_buffer;
 
+static m4_pattern_buffer buf;  /* compiled regular expression */
 
 /* Compile a REGEXP using the RESYNTAX bits, and return the buffer.
    Report errors on behalf of CALLER.  If NO_SUB, optimize the
@@ -126,10 +127,8 @@
      for its syntax (but at least the compiled regex remembers its
      syntax even if the global variable changes later), and since we
      use a static variable.  To be reentrant, we would need a mutex in
-     this method, and we should have a way to free the memory used by
-     buf when this module is unloaded.  */
+     this method, and move the storage for buf into context.  */
 
-  static m4_pattern_buffer buf;        /* compiled regular expression */
   const char *msg;             /* error message from re_compile_pattern */
 
   re_set_syntax (resyntax);
@@ -280,6 +279,17 @@
 }
 
 
+/* Reclaim memory used by this module.  */
+M4FINISH_HANDLER(gnu)
+{
+  regfree (&buf.pat);
+  free (buf.regs.start);
+  free (buf.regs.end);
+  /* If this module was preloaded, then we need to explicitly reset
+     the memory in case it gets reloaded.  */
+  memset (&buf, 0, sizeof buf);
+}
+
 
 
 /**




reply via email to

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