From: Nicholas Clark Date: Sat, 1 Nov 2003 14:21:38 +0000 (+0000) Subject: Add Internals::HvREHASH to expose the rehashing flag X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=05619474c45b1f1e16eb70c1d9f8b991a7ad459a;p=p5sagit%2Fp5-mst-13.2.git Add Internals::HvREHASH to expose the rehashing flag t/op/hash.t tests that pathological data triggers rehashing p4raw-id: //depot/perl@21604 --- diff --git a/t/op/hash.t b/t/op/hash.t new file mode 100644 index 0000000..3beae84 --- /dev/null +++ b/t/op/hash.t @@ -0,0 +1,27 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; +} + +use strict; + +plan tests => 3; + +my %h; + +ok (!Internals::HvREHASH(%h), "hash doesn't start with rehash flag on"); + +foreach (1..10) { + $h{"\0"x$_}++; +} + +ok (!Internals::HvREHASH(%h), "10 entries doesn't trigger rehash"); + +foreach (11..20) { + $h{"\0"x$_}++; +} + +ok (Internals::HvREHASH(%h), "20 entries triggers rehash"); diff --git a/universal.c b/universal.c index 3a646ea..9a8ec1b 100644 --- a/universal.c +++ b/universal.c @@ -188,6 +188,7 @@ XS(XS_Internals_hv_clear_placehold); XS(XS_PerlIO_get_layers); XS(XS_Regexp_DESTROY); XS(XS_Internals_hash_seed); +XS(XS_Internals_HvREHASH); void Perl_boot_core_UNIVERSAL(pTHX) @@ -232,6 +233,7 @@ Perl_boot_core_UNIVERSAL(pTHX) XS_PerlIO_get_layers, file, "*;@"); newXS("Regexp::DESTROY", XS_Regexp_DESTROY, file); newXSproto("Internals::hash_seed",XS_Internals_hash_seed, file, ""); + newXSproto("Internals::HvREHASH", XS_Internals_HvREHASH, file, "\\%"); } @@ -916,3 +918,17 @@ XS(XS_Internals_hash_seed) XSRETURN_UV(PERL_HASH_SEED); } +XS(XS_Internals_HvREHASH) /* Subject to change */ +{ + dXSARGS; + if (SvROK(ST(0))) { + HV *hv = (HV *) SvRV(ST(0)); + if (items == 1 && SvTYPE(hv) == SVt_PVHV) { + if (HvREHASH(hv)) + XSRETURN_YES; + else + XSRETURN_NO; + } + } + Perl_croak(aTHX_ "Internals::HvREHASH $hashref"); +}