]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Fix bug #1744: mask extra arguments to recursive invocations of $(call ...)
authorPaul Smith <psmith@gnu.org>
Wed, 22 Jan 2003 13:45:44 +0000 (13:45 +0000)
committerPaul Smith <psmith@gnu.org>
Wed, 22 Jan 2003 13:45:44 +0000 (13:45 +0000)
ChangeLog
function.c
tests/ChangeLog
tests/scripts/functions/call

index 326a4a860029fb43473b536a16eac92ac1db6726..ef5bd87d9e5d7f8ceaebdbfcc8e9569f513489f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-01-22  Paul D. Smith  <psmith@gnu.org>
+
+       * function.c (func_call): Fix Bug #1744.  If we're inside a
+       recursive invocation of $(call ...), mask any of the outer
+       invocation's arguments that aren't used by this one, so that this
+       invocation doesn't "inherit" them accidentally.
+
 2002-11-16  Paul D. Smith  <psmith@gnu.org>
 
        * NMakefile.template (OBJS): Add hash.c object file.
index 5a27406b8d3746f5fe59a56f25f676e7e175b8af..a6a04d49af30bf2aeacd3077cc8b264bbdb1ce49 100644 (file)
@@ -1893,11 +1893,13 @@ handle_function (char **op, char **stringp)
 static char *
 func_call (char *o, char **argv, const char *funcname)
 {
+  static int max_args = 0;
   char *fname;
   char *cp;
   char *body;
   int flen;
   int i;
+  int saved_args;
   const struct function_table_entry *entry_p;
   struct variable *v;
 
@@ -1960,12 +1962,28 @@ func_call (char *o, char **argv, const char *funcname)
       define_variable (num, strlen (num), *argv, o_automatic, 0);
     }
 
+  /* If the number of arguments we have is < max_args, it means we're inside
+     a recursive invocation of $(call ...).  Fill in the remaining arguments
+     in the new scope with the empty value, to hide them from this
+     invocation.  */
+
+  for (; i < max_args; ++i)
+    {
+      char num[11];
+
+      sprintf (num, "%d", i);
+      define_variable (num, strlen (num), "", o_automatic, 0);
+    }
+
   /* Expand the body in the context of the arguments, adding the result to
      the variable buffer.  */
 
   v->exp_count = EXP_COUNT_MAX;
 
+  saved_args = max_args;
+  max_args = i;
   o = variable_expand_string (o, body, flen+3);
+  max_args = saved_args;
 
   v->exp_count = 0;
 
index e91ccc9bd5fd9d70bb1cbc7c40a16b66c685c7bb..2533bb8e7668176355fa2d02f9b451dca66b4e4f 100644 (file)
@@ -1,3 +1,8 @@
+2003-01-22  Paul D. Smith  <psmith@gnu.org>
+
+       * scripts/functions/call: Test recursive argument masking (bug
+       #1744).
+
 2002-10-25  Paul D. Smith  <psmith@gnu.org>
 
        * scripts/functions/eval: Test using $(eval ...) inside
index a8834cdced1ec394d08f66e440e58d4f98338c19..efee4769b4d7ff28c176ee69225998ceab325878 100644 (file)
@@ -69,4 +69,35 @@ $answer = "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz bl
 
 &compare_output($answer, &get_logfile(1));
 
+
+# TEST eclipsing of arguments when invoking sub-calls
+
+$makefile2 = &get_tmpfile;
+
+open(MAKEFILE,"> $makefile2");
+
+print MAKEFILE <<'EOF';
+
+all = $1 $2 $3 $4 $5 $6 $7 $8 $9
+
+level1 = $(call all,$1,$2,$3,$4,$5)
+level2 = $(call level1,$1,$2,$3)
+level3 = $(call level2,$1,$2,$3,$4,$5)
+
+all:
+       @echo $(call all,1,2,3,4,5,6,7,8,9,10,11)
+       @echo $(call level1,1,2,3,4,5,6,7,8)
+       @echo $(call level2,1,2,3,4,5,6,7,8)
+       @echo $(call level3,1,2,3,4,5,6,7,8)
+EOF
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile2, "", &get_logfile);
+
+# Create the answer to what should be produced by this Makefile
+$answer = "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n";
+
+&compare_output($answer,&get_logfile(1));
+
 1;