0146d90
diff -Bburpd make-3.81_orig/file.c make-3.81/file.c
0146d90
--- make-3.81_orig/file.c	2006-05-23 13:59:11.000000000 +0200
0146d90
+++ make-3.81/file.c	2006-05-23 14:39:34.000000000 +0200
0146d90
@@ -490,7 +490,7 @@ expand_deps (struct file *f)
0146d90
 
0146d90
               o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
0146d90
 
0146d90
-              free (d->name);
0146d90
+              hash_strfree (d->name);
0146d90
               d->name = savestring (buffer, o - buffer);
0146d90
               d->staticpattern = 0; /* Clear staticpattern so that we don't
0146d90
                                        re-expand %s below. */
0146d90
@@ -549,7 +549,7 @@ expand_deps (struct file *f)
0146d90
                         dp->name[0] = '\0';
0146d90
                       else
0146d90
                         {
0146d90
-                          free (dp->name);
0146d90
+                          hash_strfree (dp->name);
0146d90
                           dp->name = savestring (buffer, o - buffer);
0146d90
                         }
0146d90
                     }
0146d90
@@ -580,7 +580,7 @@ expand_deps (struct file *f)
0146d90
           if (d1->file == 0)
0146d90
             d1->file = enter_file (d1->name);
0146d90
           else
0146d90
-            free (d1->name);
0146d90
+            hash_strfree (d1->name);
0146d90
           d1->name = 0;
0146d90
           d1->staticpattern = 0;
0146d90
           d1->need_2nd_expansion = 0;
0146d90
Only in make-3.81: file.c~
0146d90
diff -Bburpd make-3.81_orig/implicit.c make-3.81/implicit.c
0146d90
--- make-3.81_orig/implicit.c	2006-05-23 13:59:11.000000000 +0200
0146d90
+++ make-3.81/implicit.c	2006-05-23 14:40:01.000000000 +0200
0146d90
@@ -864,7 +864,7 @@ pattern_search (struct file *file, int a
0146d90
 	      dep->file = enter_file (dep->name);
0146d90
               /* enter_file uses dep->name _if_ we created a new file.  */
0146d90
               if (dep->name != dep->file->name)
0146d90
-                free (dep->name);
0146d90
+                hash_strfree (dep->name);
0146d90
 	      dep->name = 0;
0146d90
 	      dep->file->tried_implicit |= dep->changed;
0146d90
 	    }
0146d90
Only in make-3.81: implicit.c~
0146d90
diff -Bburpd make-3.81_orig/main.c make-3.81/main.c
0146d90
--- make-3.81_orig/main.c	2006-05-23 13:59:11.000000000 +0200
0146d90
+++ make-3.81/main.c	2006-05-23 14:40:49.000000000 +0200
0146d90
@@ -540,6 +540,7 @@ initialize_global_hash_tables (void)
0146d90
   init_hash_files ();
0146d90
   hash_init_directories ();
0146d90
   hash_init_function_table ();
0146d90
+  init_hash_strings ();
0146d90
 }
0146d90
 
0146d90
 static struct file *
0146d90
Only in make-3.81: main.c~
0146d90
diff -Bburpd make-3.81_orig/make.h make-3.81/make.h
0146d90
--- make-3.81_orig/make.h	2006-05-23 13:59:11.000000000 +0200
0146d90
+++ make-3.81/make.h	2006-05-23 14:41:21.000000000 +0200
0146d90
@@ -431,6 +431,11 @@ extern void print_spaces PARAMS ((unsign
0146d90
 extern char *find_percent PARAMS ((char *));
0146d90
 extern FILE *open_tmpfile PARAMS ((char **, const char *));
0146d90
 
0146d90
+extern void init_hash_strings PARAMS ((void));
0146d90
+extern char *hash_strdup PARAMS ((const char *));
0146d90
+extern char *hash_savestring PARAMS ((const char *, unsigned int));
0146d90
+extern void hash_strfree PARAMS ((char *));
0146d90
+
0146d90
 #ifndef NO_ARCHIVES
0146d90
 extern int ar_name PARAMS ((char *));
0146d90
 extern void ar_parse_name PARAMS ((char *, char **, char **));
0146d90
Only in make-3.81: make.h~
0146d90
diff -Bburpd make-3.81_orig/misc.c make-3.81/misc.c
0146d90
--- make-3.81_orig/misc.c	2006-05-23 13:59:11.000000000 +0200
0146d90
+++ make-3.81/misc.c	2006-05-23 14:42:59.000000000 +0200
0146d90
@@ -16,8 +16,10 @@ You should have received a copy of the G
0146d90
 GNU Make; see the file COPYING.  If not, write to the Free Software
0146d90
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
0146d90
 
0146d90
+#include <assert.h>
0146d90
 #include "make.h"
0146d90
 #include "dep.h"
0146d90
+#include "hash.h"
0146d90
 #include "debug.h"
0146d90
 
0146d90
 /* Variadic functions.  We go through contortions to allow proper function
0146d90
@@ -511,7 +513,7 @@ void
0146d90
 free_dep (struct dep *d)
0146d90
 {
0146d90
   if (d->name != 0)
0146d90
-    free (d->name);
0146d90
+    hash_strfree (d->name);
0146d90
 
0146d90
   if (d->stem != 0)
0146d90
     free (d->stem);
0146d90
@@ -535,7 +537,7 @@ copy_dep_chain (const struct dep *d)
0146d90
       bcopy ((char *) d, (char *) c, sizeof (struct dep));
0146d90
 
0146d90
       if (c->name != 0)
0146d90
-	c->name = xstrdup (c->name);
0146d90
+	c->name = hash_strdup (c->name);
0146d90
       if (c->stem != 0)
0146d90
 	c->stem = xstrdup (c->stem);
0146d90
 
0146d90
@@ -909,3 +911,154 @@ close_stdout (void)
0146d90
       exit (EXIT_FAILURE);
0146d90
     }
0146d90
 }
0146d90
+
0146d90
+/* Hash table of duplicated strings.  */
0146d90
+
0146d90
+struct hash_string
0146d90
+{
0146d90
+  char *string;
0146d90
+  unsigned int count;
0146d90
+};
0146d90
+
0146d90
+static unsigned long
0146d90
+string_hash_1 (key)
0146d90
+    const void *key;
0146d90
+{
0146d90
+  return_ISTRING_HASH_1 (((const struct hash_string *) key)->string);
0146d90
+}
0146d90
+
0146d90
+static unsigned long
0146d90
+string_hash_2 (key)
0146d90
+    const void *key;
0146d90
+{
0146d90
+  return_ISTRING_HASH_2 (((const struct hash_string *) key)->string);
0146d90
+}
0146d90
+
0146d90
+static int
0146d90
+string_hash_cmp (x, y)
0146d90
+    const void *x;
0146d90
+    const void *y;
0146d90
+{
0146d90
+  return_ISTRING_COMPARE (((const struct hash_string *) x)->string,
0146d90
+			  ((const struct hash_string *) y)->string);
0146d90
+}
0146d90
+
0146d90
+static struct hash_table strings;
0146d90
+
0146d90
+void
0146d90
+init_hash_strings ()
0146d90
+{
0146d90
+  hash_init (&strings, 1000, string_hash_1, string_hash_2,
0146d90
+	     string_hash_cmp);
0146d90
+}
0146d90
+
0146d90
+/* Keep track duplicated string and return the old one if exists.  */
0146d90
+
0146d90
+char *
0146d90
+hash_strdup (ptr)
0146d90
+     const char *ptr;
0146d90
+{
0146d90
+  struct hash_string *h, key;
0146d90
+
0146d90
+  if (*ptr == '\0')
0146d90
+    return "";
0146d90
+
0146d90
+  key.string = (char *) ptr;
0146d90
+  key.count = 0;
0146d90
+  h = (struct hash_string *) hash_find_item (&strings, &key);
0146d90
+  if (h == NULL)
0146d90
+    {
0146d90
+      char *result = (char *) malloc (strlen (ptr) + 1);
0146d90
+
0146d90
+      if (result == NULL)
0146d90
+	fatal (NILF, _("virtual memory exhausted"));
0146d90
+
0146d90
+      strcpy (result, ptr);
0146d90
+
0146d90
+      h = (struct hash_string *) malloc (sizeof (struct hash_string));
0146d90
+      if (h == NULL)
0146d90
+	fatal (NILF, _("virtual memory exhausted"));
0146d90
+
0146d90
+      h->string = result;
0146d90
+      h->count = 1;
0146d90
+      hash_insert (&strings, h);
0146d90
+    }
0146d90
+  else
0146d90
+    {
0146d90
+      h->count++;
0146d90
+      assert (h->count != 0);
0146d90
+    }
0146d90
+
0146d90
+  return h->string;
0146d90
+}
0146d90
+
0146d90
+char *
0146d90
+hash_savestring (str, length)
0146d90
+     const char *str;
0146d90
+     unsigned int length;
0146d90
+{
0146d90
+  struct hash_string *h, key;
0146d90
+
0146d90
+  if (length == 0 || *str == '\0')
0146d90
+    return "";
0146d90
+
0146d90
+  key.string = alloca (length + 1);
0146d90
+  key.count = 0;
0146d90
+  bcopy (str, key.string, length);
0146d90
+  key.string [length] = '\0';
0146d90
+
0146d90
+  h = (struct hash_string *) hash_find_item (&strings, &key);
0146d90
+  if (h == NULL)
0146d90
+    {
0146d90
+      char *out = (char *) xmalloc (length + 1);
0146d90
+      bcopy (str, out, length);
0146d90
+      out[length] = '\0';
0146d90
+
0146d90
+      h = (struct hash_string *) malloc (sizeof (struct hash_string));
0146d90
+      if (h == NULL)
0146d90
+	fatal (NILF, _("virtual memory exhausted"));
0146d90
+
0146d90
+      h->string = out;
0146d90
+      h->count = 1;
0146d90
+      hash_insert (&strings, h);
0146d90
+    }
0146d90
+  else
0146d90
+    {
0146d90
+      h->count++;
0146d90
+      assert (h->count != 0);
0146d90
+    }
0146d90
+
0146d90
+  return h->string;
0146d90
+}
0146d90
+
0146d90
+void
0146d90
+hash_strfree (ptr)
0146d90
+     char *ptr;
0146d90
+{
0146d90
+  struct hash_string *h, key;
0146d90
+
0146d90
+  if (*ptr == '\0')
0146d90
+    return;
0146d90
+
0146d90
+  key.string = ptr;
0146d90
+  key.count = 0;
0146d90
+  h = (struct hash_string *) hash_find_item (&strings, &key);
0146d90
+
0146d90
+  /* Check if string comes from hash_strdup or hash_savestring.  */
0146d90
+  if (h == NULL || h->string != ptr)
0146d90
+    {
0146d90
+      free (ptr);
0146d90
+      return;
0146d90
+    }
0146d90
+
0146d90
+  h->count--;
0146d90
+  if (h->count == 0)
0146d90
+    {
0146d90
+      struct hash_string *d;
0146d90
+
0146d90
+      d = hash_delete (&strings, h);
0146d90
+      assert (d == h);
0146d90
+      free (h->string);
0146d90
+      free (h);
0146d90
+    }
0146d90
+}
0146d90
Only in make-3.81: misc.c~
0146d90
Only in make-3.81: read.c~