Keep a local count of the max dependency list size.
authorPaul Smith <psmith@gnu.org>
Tue, 9 Jul 2013 23:14:40 +0000 (19:14 -0400)
committerPaul Smith <psmith@gnu.org>
Tue, 9 Jul 2013 23:14:40 +0000 (19:14 -0400)
This global variable could be modified during recursion so keep our
own local copy to compare against.

ChangeLog
implicit.c
tests/ChangeLog
tests/scripts/features/se_implicit

index b24186af6f6e6a1f0da0813885ef5f845ceabe7c..11442c76cfd7db8412bb76a8da0be773c9b0be2f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-09  Paul Smith  <psmith@gnu.org>
+
+       * implicit.c (pattern_search): Keep a local copy of the number of
+       deps in deplist: the global max might change due to recursion.
+       Fixes a bug reported by Martin d'Anjou <martin.danjou14@gmail.com>.
+
 2013-06-28  Paul Smith  <psmith@gnu.org>
 
        * misc.c (set_append_mode): Set the O_APPEND flag on a file descriptor.
index 97233a629bfceeebe88db968a0fe697769964c29..6d2e09b3208e529cca5ec062555407439d9a519d 100644 (file)
@@ -217,8 +217,8 @@ pattern_search (struct file *file, int archive,
   struct file *int_file = 0;
 
   /* List of dependencies found recursively.  */
-  struct patdeps *deplist
-    = xmalloc (max_pattern_deps * sizeof (struct patdeps));
+  unsigned int max_deps = max_pattern_deps;
+  struct patdeps *deplist = xmalloc (max_deps * sizeof (struct patdeps));
   struct patdeps *pat = deplist;
 
   /* Names of possible dependencies are constructed in this buffer.  */
@@ -651,13 +651,15 @@ pattern_search (struct file *file, int archive,
               /* If there are more than max_pattern_deps prerequisites (due to
                  2nd expansion), reset it and realloc the arrays.  */
 
-              if (deps_found > max_pattern_deps)
+              if (deps_found > max_deps)
                 {
                   unsigned int l = pat - deplist;
+                  /* This might have changed due to recursion.  */
+                  max_pattern_deps = MAX(max_pattern_deps, deps_found);
+                  max_deps = max_pattern_deps;
                   deplist = xrealloc (deplist,
-                                      deps_found * sizeof (struct patdeps));
+                                      max_deps * sizeof (struct patdeps));
                   pat = deplist + l;
-                  max_pattern_deps = deps_found;
                 }
 
               /* Go through the nameseq and handle each as a prereq name.  */
@@ -757,8 +759,8 @@ pattern_search (struct file *file, int archive,
                           pat->pattern = int_file->name;
                           int_file->name = d->name;
                           pat->file = int_file;
-                          (pat++)->name = d->name;
                           int_file = 0;
+                          (pat++)->name = d->name;
                           continue;
                         }
 
index 7bdc5a12a60853994e1b5866862be8335f22200d..978349aca96daab8eda938d706be06c40a5151a3 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-09  Paul Smith  <psmith@gnu.org>
+
+       * scripts/features/se_implicit: Add a test for SE rules depending
+       on other SE rules to be built.
+
 2013-05-26  Paul Smith  <psmith@gnu.org>
 
        * scripts/features/archives: Test for Savannah bug #38442.
index e9acb2f55e0172e57c040db6d8da3038a7f008dd..0a31948adf8c0eb5f22004a9cb11f3c23759a8a3 100644 (file)
@@ -222,5 +222,27 @@ foo.o:
 !,
               '', "\n");
 
+# Test #10: Test second expansion with second expansion prerequisites
+# Ensures pattern_search() recurses with SE prereqs.
+touch('a');
+run_make_test(q!
+.SECONDEXPANSION:
+sim_base_rgg := just_a_name
+sim_base_src := a
+sim_base_f := a a a
+sim_%.f: $${sim_$$*_f}
+       echo $@
+sim_%.src: $${sim_$$*_src}
+       echo $@
+sim_%: \
+       $$(if $$(sim_$$*_src),sim_%.src) \
+       $$(if $$(sim_$$*_f),sim_%.f) \
+       $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s)
+       echo $@
+!,
+              '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'.  Stop.", 512);
+
+unlink('a');
+
 # This tells the test driver that the perl test script executed properly.
 1;