Subject: make patches
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Christos Zoulas <christos@deshaw.com>
List: current-users
Date: 03/21/1994 16:31:07
Hello,

The following two patches fix a couple of problems with make(1)

1. Null Suffixes were not being copied, but they were being free'd
   This caused rules of the form:

   .c:
	${CC} ...

   to access invalid memory and potentially core dump..
   [That was always broken; I did not break that one :-)]

2. My recent fixes to parse ${VAR:%.foo=%.bar} handled the null string
   case incorrectly (${VAR:=.c} was broken).

Thanks to Keith Bostic for finding the bugs...

To answer the recent note about make memory leaks:

Unfortunately the original author of make (Adam De Boor) played some
nasty tricks with memory allocation (like partially freeing lists
without freeing their contents for efficiency) and the program has a
lot of memory leaks which can be verified with purify. I think that it
is not easy to fix most of them without a lot of work (but I will try
when I get some spare time). I personally have not seen make grow to
14M...  Another thing I don't like about make, is that it uses the list
package extensively for most of it's data structures, even when it
should be using other ADT's like trees or hash tables.

christos

*** suff.c.orig	Fri Nov 19 15:35:53 1993
--- suff.c	Mon Mar 21 16:15:25 1994
***************
*** 151,156 ****
--- 151,157 ----
  static int SuffSuffIsPrefix __P((Suff *, char *));
  static int SuffGNHasNameP __P((GNode *, char *));
  static void SuffFree __P((Suff *));
+ static Suff* SuffCopy __P((Suff *));
  static void SuffInsert __P((Lst, Suff *));
  static Boolean SuffParseTransform __P((char *, Suff **, Suff **));
  static int SuffRebuildGraph __P((GNode *, Suff *));
***************
*** 472,478 ****
  		 * XXX: Use emptySuff over suffNull?
  		 */
  		*srcPtr = single;
! 		*targPtr = suffNull;
  		return(TRUE);
  	    }
  	    return (FALSE);
--- 473,479 ----
  		 * XXX: Use emptySuff over suffNull?
  		 */
  		*srcPtr = single;
! 		*targPtr = SuffCopy(suffNull);
  		return(TRUE);
  	    }
  	    return (FALSE);
***************
*** 2114,2119 ****
--- 2115,2151 ----
      suffNull->flags =  	    SUFF_NULL;
  
  }
+ 
+ 
+ /*-
+  *-----------------------------------------------------------------------
+  * SuffCopy  --
+  *	Create a copy of the source suffix.
+  *	Currently does not copy children or parents
+  *
+  * Results:
+  *	a new suffix is returned
+  *
+  * Side Effects:
+  *	none
+  *-----------------------------------------------------------------------
+  */
+ static Suff *
+ SuffCopy(s)
+     Suff *s;
+ {
+     Suff *n = (Suff *) emalloc (sizeof (Suff));
+     n->name =       strdup (s->name);
+     n->nameLen =    s->nameLen;
+     n->searchPath = Lst_Init (FALSE);
+     Dir_Concat(suffNull->searchPath, s->searchPath);
+     n->children =   Lst_Init (FALSE);
+     n->parents =    Lst_Init (FALSE);
+     n->sNum =       s->sNum;   
+     n->flags = 	    s->flags;
+     return n;
+ }
+ 
  
  /********************* DEBUGGING FUNCTIONS **********************/
  
*** str.c.orig	Mon Mar 21 15:26:26 1994
--- str.c	Mon Mar 21 15:26:32 1994
***************
*** 365,372 ****
      char *w = word;
      char *m;
  
!     if (*p == '\0')
! 	return NULL;
  
      if ((m = strchr(p, '%')) != NULL) {
  	/* check that the prefix matches */
--- 365,375 ----
      char *w = word;
      char *m;
  
!     if (*p == '\0') {
! 	/* Null pattern is the whole string */
! 	*len = strlen(w);
! 	return w;
!     }
  
      if ((m = strchr(p, '%')) != NULL) {
  	/* check that the prefix matches */

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