cvs commit: patches/make make-3.80-crash-1.patch make-3.80-eval-1.patch make-3.80-variables-1.patch

jim at linuxfromscratch.org jim at linuxfromscratch.org
Sun Sep 14 00:07:42 PDT 2003


jim         03/09/14 01:07:42

  Added:       make     make-3.80-crash-1.patch make-3.80-eval-1.patch
                        make-3.80-variables-1.patch
  Log:
  Added Make 3.80 updates
  
  Revision  Changes    Path
  1.1                  patches/make/make-3.80-crash-1.patch
  
  Index: make-3.80-crash-1.patch
  ===================================================================
  Submitted By: Jim Gifford (patches at jg555 dot com)
  Date: 09-12-2003
  Initial Package Version: 3.80
  Origin: http://savannah.gnu.org/bugs/?func=detailbug&bug_id=1517&group_id=71
  Description: Using $(eval ...) can lead to fatal errors about allocating too
  	     much memory, or it can evaluate to a value (the manual says it
  	     always evaluates to the empty string). See: 
  
  e0 = $(foreach s,foobar,$(eval $s:)) 
  e1 = $(foreach s,foobar, $(eval $s:)) 
  
  all: ; @echo e0 == $(e0) e1 == $(e1) 
  
  $ make 
  e0 == e1 == f 
  
  The e0 value is correct, but e1 is wrong.
  
  diff -Naur make-3.80.orig/expand.c make-3.80/expand.c
  --- make-3.80.orig/expand.c	2002-07-11 06:38:57.000000000 +0000
  +++ make-3.80/expand.c	2003-09-12 06:09:50.000000000 +0000
  @@ -564,3 +564,28 @@
   
     return value;
   }
  +
  +/* Install a new variable_buffer context, returning the current one for
  +   safe-keeping.  */
  +
  +void
  +install_variable_buffer (char **bufp, unsigned int *lenp)
  +{
  +  *bufp = variable_buffer;
  +  *lenp = variable_buffer_length;
  +
  +  variable_buffer = 0;
  +  initialize_variable_output ();
  +}
  +
  +/* Restore a previously-saved variable_buffer setting (free the current one).
  + */
  +
  +void
  +restore_variable_buffer (char *buf, unsigned int len)
  +{
  +  free (variable_buffer);
  +
  +  variable_buffer = buf;
  +  variable_buffer_length = len;
  +}
  diff -Naur make-3.80.orig/function.c make-3.80/function.c
  --- make-3.80.orig/function.c	2002-10-04 02:13:42.000000000 +0000
  +++ make-3.80/function.c	2003-09-12 06:09:50.000000000 +0000
  @@ -1281,8 +1281,18 @@
        char **argv;
        const char *funcname;
   {
  +  char *buf;
  +  unsigned int len;
  +
  +  /* Eval the buffer.  Pop the current variable buffer setting so that the
  +     eval'd code can use its own without conflicting.  */
  +
  +  install_variable_buffer (&buf, &len);
  +
     eval_buffer (argv[0]);
   
  +  restore_variable_buffer (buf, len);
  +
     return o;
   }
   
  diff -Naur make-3.80.orig/variable.h make-3.80/variable.h
  --- make-3.80.orig/variable.h	2002-08-08 00:11:19.000000000 +0000
  +++ make-3.80/variable.h	2003-09-12 06:09:50.000000000 +0000
  @@ -107,6 +107,8 @@
   extern char *expand_argument PARAMS ((char *str, char *end));
   extern char *variable_expand_string PARAMS ((char *line, char *string,
                                                long length));
  +extern void install_variable_buffer PARAMS ((char **bufp, unsigned int *lenp));
  +extern void restore_variable_buffer PARAMS ((char *buf, unsigned int len));
   
   /* function.c */
   extern int handle_function PARAMS ((char **op, char **stringp));
  
  
  
  1.1                  patches/make/make-3.80-eval-1.patch
  
  Index: make-3.80-eval-1.patch
  ===================================================================
  Submitted By: Jim Gifford (patches at jg555 dot com)
  Date: 09-12-03
  Initial Package Version: 3.80
  Origin: http://savannah.gnu.org/bugs/?func=detailbug&bug_id=1516&group_id=71
  Description: Using $(eval ...) inside a conditional (that is parsed)
  	     will cause an error like this: 
  	     Makefile:10: *** missing `endif'. Stop
  
  diff -Naur make-3.80.orig/read.c make-3.80/read.c
  --- make-3.80.orig/read.c	2002-10-04 02:13:42.000000000 +0000
  +++ make-3.80/read.c	2003-09-12 06:06:22.000000000 +0000
  @@ -272,6 +272,34 @@
     return read_makefiles;
   }
   
  +/* Install a new conditional and return the previous one.  */
  +
  +static struct conditionals *
  +install_conditionals (struct conditionals *new)
  +{
  +  struct conditionals *save = conditionals;
  +
  +  bzero ((char *) new, sizeof (*new));
  +  conditionals = new;
  +
  +  return save;
  +}
  +
  +/* Free the current conditionals and reinstate a saved one.  */
  +
  +static void
  +restore_conditionals (struct conditionals *saved)
  +{
  +  /* Free any space allocated by conditional_line.  */
  +  if (conditionals->ignoring)
  +    free (conditionals->ignoring);
  +  if (conditionals->seen_else)
  +    free (conditionals->seen_else);
  +
  +  /* Restore state.  */
  +  conditionals = saved;
  +}
  +
   static int
   eval_makefile (filename, flags)
        char *filename;
  @@ -391,6 +419,8 @@
        char *buffer;
   {
     struct ebuffer ebuf;
  +  struct conditionals *saved;
  +  struct conditionals new;
     const struct floc *curfile;
     int r;
   
  @@ -405,8 +435,12 @@
     curfile = reading_file;
     reading_file = &ebuf.floc;
   
  +  saved = install_conditionals (&new);
  +
     r = eval (&ebuf, 1);
   
  +  restore_conditionals (saved);
  +
     reading_file = curfile;
   
     return r;
  @@ -415,13 +449,8 @@
   
   /* Read file FILENAME as a makefile and add its contents to the data base.
   
  -   SET_DEFAULT is true if we are allowed to set the default goal.
  +   SET_DEFAULT is true if we are allowed to set the default goal.  */
   
  -   FILENAME is added to the `read_makefiles' chain.
  -
  -   Returns 0 if a file was not found or not read.
  -   Returns 1 if FILENAME was found and read.
  -   Returns 2 if FILENAME was read, and we kept a reference (don't free it).  */
   
   static int
   eval (ebuf, set_default)
  @@ -787,9 +816,7 @@
   
   	  /* Save the state of conditionals and start
   	     the included makefile with a clean slate.  */
  -	  save = conditionals;
  -	  bzero ((char *) &new_conditionals, sizeof new_conditionals);
  -	  conditionals = &new_conditionals;
  +	  save = install_conditionals (&new_conditionals);
   
   	  /* Record the rules that are waiting so they will determine
   	     the default goal before those in the included makefile.  */
  @@ -815,14 +842,8 @@
                   }
   	    }
   
  -	  /* Free any space allocated by conditional_line.  */
  -	  if (conditionals->ignoring)
  -	    free (conditionals->ignoring);
  -	  if (conditionals->seen_else)
  -	    free (conditionals->seen_else);
  -
  -	  /* Restore state.  */
  -	  conditionals = save;
  +	  /* Restore conditional state.  */
  +	  restore_conditionals (save);
   
             goto rule_complete;
   	}
  diff -Naur make-3.80.orig/tests/scripts/functions/eval make-3.80/tests/scripts/functions/eval
  --- make-3.80.orig/tests/scripts/functions/eval	2002-07-08 02:26:48.000000000 +0000
  +++ make-3.80/tests/scripts/functions/eval	2003-09-12 06:06:22.000000000 +0000
  @@ -57,4 +57,35 @@
   
   &compare_output($answer,&get_logfile(1));
   
  +# Test to make sure eval'ing inside conditionals works properly
  +
  +$makefile3 = &get_tmpfile;
  +
  +open(MAKEFILE,"> $makefile3");
  +
  +print MAKEFILE <<'EOF';
  +FOO = foo
  +
  +all:: ; @echo it
  +
  +define Y
  +  all:: ; @echo worked
  +endef
  +
  +ifdef BAR
  +$(eval $(Y))
  +endif
  +
  +EOF
  +
  +close(MAKEFILE);
  +
  +&run_make_with_options($makefile3, "", &get_logfile);
  +$answer = "it\n";
  +&compare_output($answer,&get_logfile(1));
  +
  +&run_make_with_options($makefile3, "BAR=1", &get_logfile);
  +$answer = "it\nworked\n";
  +&compare_output($answer,&get_logfile(1));
  +
   1;
  
  
  
  1.1                  patches/make/make-3.80-variables-1.patch
  
  Index: make-3.80-variables-1.patch
  ===================================================================
  Submitted By: Jim Gifford (patches at jg555 dot com)
  Date: 9-12-2003
  Initial Package Version: 3.80
  Origin: http://savannah.gnu.org/bugs/?func=detailbug&bug_id=2238&group_id=71
  Description: Make 3.80: At last, a (simple) way to reverse a list. 
  	     Consider this function: 
  
  ..9 := 0 1 2 3 4 5 6 7 8 9 
  
  rev=$(eval res:=)$(foreach word,$1,$(eval res:=${word} ${res}))${res} 
  
  When used with this makefile snippet: 
  
  $(error [$(call rev,${..9})]) 
  
  we get: 
  
  $ make -f bug.mak 
  1:3: *** [ 9 8 7 6 5 4 3 2 1 0 ]. Stop. 
  
  This is fine. However, if we generate the result via a simply expanded
  variable, then oddness occurs. Change the $(error...) above to: 
  
  a:=$(call rev,${..9}) 
  $(error [${a}]) 
  
  This time make reports: 
  
  $ make -f bug.mak 
  1:5: *** [ 9 8 7 6 5 4 3 2 1 0 1 0 ]. Stop. 
  
  What's that extra "1 0 " doing there? Strangely, things start working
  again if we change "a" to a recursive variable. 
  
  diff -Naur make-3.80.orig/read.c make-3.80/read.c
  --- make-3.80.orig/read.c	2003-09-12 06:06:22.000000000 +0000
  +++ make-3.80/read.c	2003-09-12 06:20:00.000000000 +0000
  @@ -457,8 +457,8 @@
        struct ebuffer *ebuf;
        int set_default;
   {
  -  static char *collapsed = 0;
  -  static unsigned int collapsed_length = 0;
  +  char *collapsed = 0;
  +  unsigned int collapsed_length = 0;
     unsigned int commands_len = 200;
     char *commands;
     unsigned int commands_idx = 0;
  @@ -571,9 +571,7 @@
         if (collapsed_length < linelen+1)
   	{
   	  collapsed_length = linelen+1;
  -	  if (collapsed != 0)
  -	    free (collapsed);
  -	  collapsed = (char *) xmalloc (collapsed_length);
  +	  collapsed = (char *) xrealloc (collapsed, collapsed_length);
   	}
         strcpy (collapsed, line);
         /* Collapse continuation lines.  */
  @@ -1230,6 +1228,8 @@
     /* At eof, record the last rule.  */
     record_waiting_files ();
   
  +  if (collapsed)
  +    free ((char *) collapsed);
     free ((char *) commands);
   
     return 1;
  
  
  



More information about the patches mailing list