From 8f75e59cf5eb79c75c2a06b9848c99fcc915dda2 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 19 Jul 1998 06:13:13 +0000 Subject: [PATCH] fixed more recursivity failures --- ChangeLog | 11 +++++++++++ automake.in | 35 ++++++++++++++++++++++++++++++++--- tests/ChangeLog | 2 ++ tests/Makefile.am | 2 +- tests/Makefile.in | 2 +- tests/recurs.test | 21 +++++++++++++++++++++ 6 files changed, 68 insertions(+), 5 deletions(-) create mode 100755 tests/recurs.test diff --git a/ChangeLog b/ChangeLog index d9ca14a70..389f23e4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ +Sun Jul 19 00:04:25 1998 Tom Tromey + + * automake.in (variable_conditions): Initialize %vars_scanned. + (variable_conditions_sub): Check it. Test cond5.test. + Sat Jul 18 00:24:14 1998 Tom Tromey + * automake.in (variable_value_as_list_worker): Renamed from + variable_value_as_list. Set entry in vars_scanned, and give error + if variable recursively defined. Test recurs.test. + (value_to_list): Call it instead. + (variable_value_as_list): New function. + * automake.in (variable_conditions_sub): If var is not conditional, but does have conditional subvariables, then return value should be all permutations of subvariable conditions. Test diff --git a/automake.in b/automake.in index fc16d7a18..352a674ec 100755 --- a/automake.in +++ b/automake.in @@ -4708,6 +4708,7 @@ sub variable_conditions local (%uniqify); local ($cond); + %vars_scanned = (); foreach $cond (&variable_conditions_sub ($var, '', ())) { $uniqify{$cond} = 1; @@ -4723,6 +4724,13 @@ sub variable_conditions_sub local ($var, $parent, @parent_conds) = @_; local (@new_conds) = (); + if (defined $vars_scanned{$var}) + { + &am_line_error ($parent, "variable \`$var' recursively defined"); + return (); + } + $vars_scanned{$var} = 1; + if (! $conditional{$var}) { foreach (split (' ', $contents{$var})) @@ -4963,7 +4971,9 @@ sub variable_value # conditions should be returned; if COND is a particular condition # (all conditions are surrounded by @...@) then only the value for # that condition should be returned; otherwise, warn if VAR is -# conditionally defined. +# conditionally defined. SCANNED is a global hash listing whose keys +# are all the variables already scanned; it is an error to rescan a +# variable. sub value_to_list { local ($var, $val, $cond) = @_; @@ -4993,7 +5003,7 @@ sub value_to_list } # Find the value. - @temp_list = &variable_value_as_list ($1, $cond, $var); + @temp_list = &variable_value_as_list_worker ($1, $cond, $var); # Now rewrite the value if appropriate. if ($from) @@ -5020,7 +5030,7 @@ sub value_to_list # that condition should be returned; otherwise, warn if VAR is # conditionally defined. If PARENT is specified, it is the name of # the including variable; this is only used for error reports. -sub variable_value_as_list +sub variable_value_as_list_worker { local ($var, $cond, $parent) = @_; local (@result); @@ -5033,8 +5043,15 @@ sub variable_value_as_list { &am_line_error ($parent, "variable \`$var' not defined"); } + elsif (defined $vars_scanned{$var}) + { + # `vars_scanned' is a global we use to keep track of which + # variables we've already examined. + &am_line_error ($parent, "variable \`$var' recursively defined"); + } elsif ($cond eq 'all' && $conditional{$var}) { + $vars_scanned{$var} = 1; local (@condvals) = split (' ', $conditional{$var}); while (@condvals) { @@ -5045,6 +5062,7 @@ sub variable_value_as_list } elsif ($cond && $conditional{$var}) { + $vars_scanned{$var} = 1; local (@condvals) = split (' ', $conditional{$var}); local ($onceflag); while (@condvals) @@ -5064,6 +5082,7 @@ sub variable_value_as_list } else { + $vars_scanned{$var} = 1; &variable_conditionally_defined ($var, $parent); $content_seen{$var} = 1; push (@result, &value_to_list ($var, $contents{$var}, $cond)); @@ -5072,6 +5091,16 @@ sub variable_value_as_list return @result; } +# This is just a wrapper for variable_value_as_list_worker that +# initializes the global hash `vars_scanned'. This hash is used to +# avoid infinite recursion. +sub variable_value_as_list +{ + local ($var, $cond, $parent) = @_; + %vars_scanned = (); + return &variable_value_as_list_worker ($var, $cond, $parent); +} + # Define a new variable, but only if not already defined. sub define_variable { diff --git a/tests/ChangeLog b/tests/ChangeLog index 0482b3d19..7a8f53645 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,7 @@ Sat Jul 18 00:27:26 1998 Tom Tromey + * recurs.test: New file. + * cond3.test: Changed to match recent fixes. Fri Jul 17 23:44:49 1998 Tom Tromey diff --git a/tests/Makefile.am b/tests/Makefile.am index f4fe367a6..7e41beb20 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,7 +31,7 @@ aclocal.test alpha.test whoami.test unused.test condman.test \ texinfo5.test aclocali.test texinfo6.test condman2.test colon4.test \ java.test sinclude.test javaprim.test javasubst.test aclocalii.test \ lex2.test libobj8.test version3.test instdata.test exdir2.test \ -colon5.test library.test syntax.test cond4.test cond5.test +colon5.test library.test syntax.test cond4.test cond5.test recurs.test EXTRA_DIST = defs $(TESTS) diff --git a/tests/Makefile.in b/tests/Makefile.in index eddd23a6d..be6af76c3 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -94,7 +94,7 @@ aclocal.test alpha.test whoami.test unused.test condman.test \ texinfo5.test aclocali.test texinfo6.test condman2.test colon4.test \ java.test sinclude.test javaprim.test javasubst.test aclocalii.test \ lex2.test libobj8.test version3.test instdata.test exdir2.test \ -colon5.test library.test syntax.test cond4.test cond5.test +colon5.test library.test syntax.test cond4.test cond5.test recurs.test EXTRA_DIST = defs $(TESTS) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs diff --git a/tests/recurs.test b/tests/recurs.test new file mode 100755 index 000000000..9816df1a0 --- /dev/null +++ b/tests/recurs.test @@ -0,0 +1,21 @@ +#! /bin/sh + +# Test to make sure recursive variable definitions die. + +. $srcdir/defs || exit 1 + +cat > configure.in << 'END' +AM_INIT_AUTOMAKE(nonesuch, nonesuch) +AC_PROG_CC +AM_CONDITIONAL(ONE, true) +AM_CONDITIONAL(TWO, false) +AC_OUTPUT(Makefile) +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = $(foo) +foo = $(bin_PROGRAMS) +END + +$AUTOMAKE && exit 1 +exit 0 -- 2.47.3