Submitted By: Jim Gifford (patches at jg555 dot com) Date: 2003-09-12 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));