summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-12-28 12:36:16 +0000
committerNicholas Clark <nick@ccl4.org>2008-12-28 12:36:16 +0000
commit90acdc2acfdb8c512ef84ee08df225ccf527f635 (patch)
tree879952b7fb650a41c43ab8a2771014d6ce6e215c
parent58ca560a9acfccd7c196fdebef1d0c50c1b4b155 (diff)
downloadperl-90acdc2acfdb8c512ef84ee08df225ccf527f635.tar.gz
Verify that pre-computing hashes with shared hash key scalars does not cause
problems.
-rw-r--r--ext/XS/APItest/t/hash.t43
1 files changed, 30 insertions, 13 deletions
diff --git a/ext/XS/APItest/t/hash.t b/ext/XS/APItest/t/hash.t
index cb8b26b1ef..c7581b2036 100644
--- a/ext/XS/APItest/t/hash.t
+++ b/ext/XS/APItest/t/hash.t
@@ -150,6 +150,32 @@ if ($] > 5.009) {
}
}
+sub test_precomputed_hashes {
+ my $what = shift;
+ my $hash_it = shift;
+ my $ord = shift;
+ my $key_copy = $_[0];
+ $key_copy .= '';
+
+ my %hash;
+ is (XS::APItest::Hash::common({hv => \%hash,
+ "key$what" => $_[0],
+ val => $ord,
+ "hash_$what" => $hash_it,
+ action => XS::APItest::HV_FETCH_ISSTORE}),
+ $ord, "store $ord with $what \$hash_it = $hash_it");
+ is_deeply ([each %hash], [$_[0], $ord], "First key read is good");
+ is_deeply ([each %hash], [], "No second key good");
+
+ is ($hash{$_[0]}, $ord, "Direct hash read finds $ord");
+
+ is_deeply ([each %hash], [$key_copy, $ord],
+ "First key read is good with a copy");
+ is_deeply ([each %hash], [], "No second key good");
+
+ is ($hash{$key_copy}, $ord, "Direct hash read finds $ord");
+}
+
{
my $as_utf8 = "\241" . chr 256;
chop $as_utf8;
@@ -158,20 +184,11 @@ if ($] > 5.009) {
my $ord = ord $key;
foreach my $hash_it (0, 1) {
foreach my $what (qw(pv sv)) {
- my %hash;
- is (XS::APItest::Hash::common({hv => \%hash,
- "key$what" => $key,
- val => $ord,
- "hash_$what" => $hash_it,
- action =>
- XS::APItest::HV_FETCH_ISSTORE}),
- $ord, "store $ord with $what \$hash_it = $hash_it");
- is_deeply ([each %hash], [$key, $ord],
- "First key read is good");
- is_deeply ([each %hash], [], "No second key good");
-
- is ($hash{$key}, $ord, "Direct hash read finds $ord");
+ test_precomputed_hashes($what, $hash_it, $ord, $key);
}
+ # Generate a shared hash key scalar
+ my %h = ($key => 1);
+ test_precomputed_hashes('sv', $hash_it, $ord, (keys %h)[0]);
}
}
}