summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2016-08-08 18:53:20 +0200
committerYves Orton <demerphq@gmail.com>2016-08-14 11:44:20 +0200
commit10f9b9bf77ed09ee67da058d1ba1658a4ce67626 (patch)
treec7826b1a277b439fcc38aead5cdee3a7e8f29b6a
parenta149d1180209525972d84fd1a62f488da83e568a (diff)
downloadperl-10f9b9bf77ed09ee67da058d1ba1658a4ce67626.tar.gz
move Internals::hv_clear_placeholders() to Hash::Util::_clear_placeholders()
There is no reason for this code to be in Internals:: or in universal.c at all, it should only be used from Hash::Util during things like lock_keys(). Moves the function to the XS code in Hash::Util, and renames it as well, along with commented out documentation for what it does.
-rw-r--r--ext/Hash-Util/Util.xs10
-rw-r--r--ext/Hash-Util/lib/Hash/Util.pm27
-rw-r--r--t/lib/universal.t2
-rw-r--r--t/re/subst.t2
-rw-r--r--universal.c15
5 files changed, 33 insertions, 23 deletions
diff --git a/ext/Hash-Util/Util.xs b/ext/Hash-Util/Util.xs
index 01f52bfe44..611cc636df 100644
--- a/ext/Hash-Util/Util.xs
+++ b/ext/Hash-Util/Util.xs
@@ -7,6 +7,16 @@
MODULE = Hash::Util PACKAGE = Hash::Util
void
+_clear_placeholders(hashref)
+ HV *hashref
+ PROTOTYPE: \%
+ PREINIT:
+ HV *hv;
+ CODE:
+ hv = MUTABLE_HV(hashref);
+ hv_clear_placeholders(hv);
+
+void
all_keys(hash,keys,placeholder)
HV *hash
AV *keys
diff --git a/ext/Hash-Util/lib/Hash/Util.pm b/ext/Hash-Util/lib/Hash/Util.pm
index ff6b3b8d55..6dbc707b4c 100644
--- a/ext/Hash-Util/lib/Hash/Util.pm
+++ b/ext/Hash-Util/lib/Hash/Util.pm
@@ -39,9 +39,13 @@ our @EXPORT_OK = qw(
used_buckets
num_buckets
);
-our $VERSION = '0.20';
-require XSLoader;
-XSLoader::load();
+BEGIN {
+ # make sure all our XS routines are available early so their prototypes
+ # are correctly applied in the following code.
+ our $VERSION = '0.21';
+ require XSLoader;
+ XSLoader::load();
+}
sub import {
my $class = shift;
@@ -172,7 +176,7 @@ Both routines return a reference to the hash operated on.
sub lock_ref_keys {
my($hash, @keys) = @_;
- Internals::hv_clear_placeholders %$hash;
+ _clear_placeholders(%$hash);
if( @keys ) {
my %keys = map { ($_ => 1) } @keys;
my %original_keys = map { ($_ => 1) } keys %$hash;
@@ -207,6 +211,19 @@ sub unlock_ref_keys {
sub lock_keys (\%;@) { lock_ref_keys(@_) }
sub unlock_keys (\%) { unlock_ref_keys(@_) }
+#=item B<_clear_placeholders>
+#
+# This function removes any placeholder keys from a hash. See Perl_hv_clear_placeholders()
+# in hv.c for what it does exactly. It is currently exposed as XS by universal.c and
+# injected into the Hash::Util namespace.
+#
+# It is not intended for use outside of this module, and may be changed
+# or removed without notice or deprecation cycle.
+#
+#=cut
+#
+# sub _clear_placeholders {} # just in case someone searches...
+
=item B<lock_keys_plus>
lock_keys_plus(%hash,@additional_keys)
@@ -225,7 +242,7 @@ Returns a reference to %hash
sub lock_ref_keys_plus {
my ($hash,@keys) = @_;
my @delete;
- Internals::hv_clear_placeholders(%$hash);
+ _clear_placeholders(%$hash);
foreach my $key (@keys) {
unless (exists($hash->{$key})) {
$hash->{$key}=undef;
diff --git a/t/lib/universal.t b/t/lib/universal.t
index 5980cade35..feb3db98b9 100644
--- a/t/lib/universal.t
+++ b/t/lib/universal.t
@@ -14,11 +14,9 @@ for my $arg ('', 'q[]', qw( 1 undef )) {
sub tryit { eval shift or warn \$@ }
tryit "&Internals::SvREADONLY($arg)";
tryit "&Internals::SvREFCNT($arg)";
-tryit "&Internals::hv_clear_placeholders($arg)";
----
Usage: Internals::SvREADONLY(SCALAR[, ON]) at (eval 1) line 1.
Usage: Internals::SvREFCNT(SCALAR[, REFCOUNT]) at (eval 2) line 1.
-Usage: Internals::hv_clear_placeholders(hv) at (eval 3) line 1.
====
}
diff --git a/t/re/subst.t b/t/re/subst.t
index 26a78c774d..2de1a7b7be 100644
--- a/t/re/subst.t
+++ b/t/re/subst.t
@@ -996,7 +996,7 @@ SKIP:{
/e;
};
is $locker{key}, '3', 'locking target in $hash{key} =~ s//.../e';
- like $@, qr/^Modification of a read-only value/, 'err msg';
+ like $@, qr/^Modification of a read-only value/, 'err msg' . ($@ ? ": $@" : "");
}
delete $::{does_not_exist}; # just in case
eval { no warnings; $::{does_not_exist}=~s/(?:)/*{"does_not_exist"}; 4/e };
diff --git a/universal.c b/universal.c
index 39745d98c4..b4ae238882 100644
--- a/universal.c
+++ b/universal.c
@@ -627,20 +627,6 @@ XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */
}
-XS(XS_Internals_hv_clear_placehold); /* prototype to pass -Wmissing-prototypes */
-XS(XS_Internals_hv_clear_placehold)
-{
- dXSARGS;
-
- if (items != 1 || !SvROK(ST(0)))
- croak_xs_usage(cv, "hv");
- else {
- HV * const hv = MUTABLE_HV(SvRV(ST(0)));
- hv_clear_placeholders(hv);
- XSRETURN(0);
- }
-}
-
XS(XS_PerlIO_get_layers); /* prototype to pass -Wmissing-prototypes */
XS(XS_PerlIO_get_layers)
{
@@ -1079,7 +1065,6 @@ static const struct xsub_details details[] = {
{"Internals::SvREADONLY", XS_Internals_SvREADONLY, "\\[$%@];$"},
{"constant::_make_const", XS_constant__make_const, "\\[$@]"},
{"Internals::SvREFCNT", XS_Internals_SvREFCNT, "\\[$%@];$"},
- {"Internals::hv_clear_placeholders", XS_Internals_hv_clear_placehold, "\\%"},
{"PerlIO::get_layers", XS_PerlIO_get_layers, "*;@"},
{"Hash::Util::bucket_ratio", XS_hash_util_bucket_ratio, "\\%"},
{"Hash::Util::num_buckets", XS_hash_util_num_buckets, "\\%"},