diff options
author | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-07-21 17:58:05 +0100 |
---|---|---|
committer | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-10-31 00:26:33 +0000 |
commit | 52e6404590f0a8824cf5f9522a2dc3151c2af9f3 (patch) | |
tree | e4ec826064680c1e7fa867ce6314273335d2f58c /lib/Automake | |
parent | 073b1fe85068620eb6c06432b1be13c40394a177 (diff) | |
download | automake-52e6404590f0a8824cf5f9522a2dc3151c2af9f3.tar.gz |
automake: account for perl hash order randomization
Try to explicitly order the keys of some perl hashes when looping
on them to do sanity/correctness checks and possibly display warning
messages; this should ensure a more reproducible output. Not really
a big deal, but I prefer to keep the order of such output reproducible
if possible.
Issue revealed by spurious testsuite failures with perl 5.18, as
reported in automake bug#14891. See also:
<http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Hash_randomization>
<http://onionstand.blogspot.ie/2012/12/are-you-relying-on-hash-keys-being.html>
* lib/Automake/Variable.pm (variables): Explicitly order the values of
the returned Automake::Variable instances.
(variables_dump): Simplify, using the knowledge that 'variables()' now
sorts its output.
* t/preproc-errmsg.sh: Adjust.
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Diffstat (limited to 'lib/Automake')
-rw-r--r-- | lib/Automake/Variable.pm | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm index f1559f58c..4751563a3 100644 --- a/lib/Automake/Variable.pm +++ b/lib/Automake/Variable.pm @@ -317,21 +317,21 @@ use vars '%_variable_dict', '%_primary_dict'; sub variables (;$) { my ($suffix) = @_; + my @vars = (); if ($suffix) { if (exists $_primary_dict{$suffix}) { - return values %{$_primary_dict{$suffix}}; - } - else - { - return (); + @vars = values %{$_primary_dict{$suffix}}; } } else { - return values %_variable_dict; + @vars = values %_variable_dict; } + # The behaviour of the 'sort' built-in is undefined in scalar + # context, hence we need an ad-hoc handling for such context. + return wantarray ? sort { $a->name cmp $b->name } @vars : scalar @vars; } =item C<Automake::Variable::reset> @@ -1080,7 +1080,7 @@ For debugging. sub variables_dump () { my $text = "all variables:\n{\n"; - foreach my $var (sort { $a->name cmp $b->name } variables) + foreach my $var (variables()) { $text .= $var->dump; } |