diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2019-08-12 10:27:18 +0100 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2019-08-12 10:27:18 +0100 |
commit | 96684a73b5f81ca2a88309182dbc2dca9ab1601a (patch) | |
tree | 36ace7371f73eeee5dc83d4bbfd0f6390d53e486 /cpan/Scalar-List-Utils | |
parent | 255b632a2a78b37a9400b7f7509a23f0e040de5c (diff) | |
download | perl-96684a73b5f81ca2a88309182dbc2dca9ab1601a.tar.gz |
Update Scalar-List-Utils to CPAN version 1.51
[DELTA]
1.51 -- 2019-08-08 14:31:32
[CHANGES]
* Add TO_JSON to List::Util::_Pair (thanks ilmari)
* Various minor docs fixes
[BUGFIXES]
* Don't segfault in subname() on deleted stashes (thanks ilmari)
* Fix uniqnum for large floats and numeric strings (thanks ilmari)
Diffstat (limited to 'cpan/Scalar-List-Utils')
-rw-r--r-- | cpan/Scalar-List-Utils/ListUtil.xs | 28 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/lib/List/Util.pm | 12 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/lib/List/Util/XS.pm | 4 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/lib/Scalar/Util.pm | 8 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/lib/Sub/Util.pm | 10 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/t/pair.t | 7 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/t/subname.t | 17 | ||||
-rw-r--r-- | cpan/Scalar-List-Utils/t/uniq.t | 25 |
8 files changed, 87 insertions, 24 deletions
diff --git a/cpan/Scalar-List-Utils/ListUtil.xs b/cpan/Scalar-List-Utils/ListUtil.xs index 12f98cde19..d275df9c57 100644 --- a/cpan/Scalar-List-Utils/ListUtil.xs +++ b/cpan/Scalar-List-Utils/ListUtil.xs @@ -1177,12 +1177,15 @@ CODE: /* clone the value so we don't invoke magic again */ arg = sv_mortalcopy(arg); - if(SvUOK(arg)) + if(SvOK(arg) && !(SvUOK(arg) || SvIOK(arg) || SvNOK(arg))) + SvNV(arg); /* sets SVf_IOK/SVf_UOK if it's an integer */ + + if(!SvOK(arg) || SvUOK(arg)) sv_setpvf(keysv, "%" UVuf, SvUV(arg)); else if(SvIOK(arg)) sv_setpvf(keysv, "%" IVdf, SvIV(arg)); else - sv_setpvf(keysv, "%" NVgf, SvNV(arg)); + sv_setpvf(keysv, "%.15" NVgf, SvNV(arg)); #ifdef HV_FETCH_EMPTY_HE he = (HE*) hv_common(seen, NULL, SvPVX(keysv), SvCUR(keysv), 0, HV_FETCH_LVALUE | HV_FETCH_EMPTY_HE, NULL, 0); if (HeVAL(he)) @@ -1601,15 +1604,18 @@ PPCODE: /* under debugger, provide information about sub location */ if (PL_DBsub && CvGV(cv)) { HV* DBsub = GvHV(PL_DBsub); - HE* old_data; + HE* old_data = NULL; GV* oldgv = CvGV(cv); HV* oldhv = GvSTASH(oldgv); - SV* old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), HvNAMEUTF8(oldhv) ? SVf_UTF8 : 0)); - sv_catpvn(old_full_name, "::", 2); - sv_catpvn_flags(old_full_name, GvNAME(oldgv), GvNAMELEN(oldgv), GvNAMEUTF8(oldgv) ? SV_CATUTF8 : SV_CATBYTES); - old_data = hv_fetch_ent(DBsub, old_full_name, 0, 0); + if (oldhv) { + SV* old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), HvNAMEUTF8(oldhv) ? SVf_UTF8 : 0)); + sv_catpvn(old_full_name, "::", 2); + sv_catpvn_flags(old_full_name, GvNAME(oldgv), GvNAMELEN(oldgv), GvNAMEUTF8(oldgv) ? SV_CATUTF8 : SV_CATBYTES); + + old_data = hv_fetch_ent(DBsub, old_full_name, 0, 0); + } if (old_data && HeVAL(old_data)) { SV* new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), HvNAMELEN_get(stash), HvNAMEUTF8(stash) ? SVf_UTF8 : 0)); @@ -1660,6 +1666,7 @@ subname(code) PREINIT: CV *cv; GV *gv; + const char *stashname; PPCODE: if (!SvROK(code) && SvGMAGICAL(code)) mg_get(code); @@ -1670,7 +1677,12 @@ PPCODE: if(!(gv = CvGV(cv))) XSRETURN(0); - mPUSHs(newSVpvf("%s::%s", HvNAME(GvSTASH(gv)), GvNAME(gv))); + if(GvSTASH(gv)) + stashname = HvNAME(GvSTASH(gv)); + else + stashname = "__ANON__"; + + mPUSHs(newSVpvf("%s::%s", stashname, GvNAME(gv))); XSRETURN(1); BOOT: diff --git a/cpan/Scalar-List-Utils/lib/List/Util.pm b/cpan/Scalar-List-Utils/lib/List/Util.pm index b650d3585a..678e024f8a 100644 --- a/cpan/Scalar-List-Utils/lib/List/Util.pm +++ b/cpan/Scalar-List-Utils/lib/List/Util.pm @@ -15,9 +15,9 @@ our @EXPORT_OK = qw( all any first min max minstr maxstr none notall product reduce sum sum0 shuffle uniq uniqnum uniqstr head tail pairs unpairs pairkeys pairvalues pairmap pairgrep pairfirst ); -our $VERSION = "1.50"; +our $VERSION = "1.51"; our $XS_VERSION = $VERSION; -$VERSION = eval $VERSION; +$VERSION =~ tr/_//d; require XSLoader; XSLoader::load('List::Util', $XS_VERSION); @@ -38,6 +38,7 @@ sub import # For objects returned by pairs() sub List::Util::_Pair::key { shift->[0] } sub List::Util::_Pair::value { shift->[1] } +sub List::Util::_Pair::TO_JSON { [ @{+shift} ] } =head1 NAME @@ -341,6 +342,9 @@ equivalent: ... } +Since version C<1.51> they also have a C<TO_JSON> method to ease +serialisation. + =head2 unpairs my @kvlist = unpairs @pairs @@ -557,6 +561,8 @@ entire list of values returned by C<uniqstr> are well-behaved as strings. my @values = head $size, @list; +I<Since version 1.50.> + Returns the first C<$size> elements from C<@list>. If C<$size> is negative, returns all but the last C<$size> elements from C<@list>. @@ -570,6 +576,8 @@ all but the last C<$size> elements from C<@list>. my @values = tail $size, @list; +I<Since version 1.50.> + Returns the last C<$size> elements from C<@list>. If C<$size> is negative, returns all but the first C<$size> elements from C<@list>. diff --git a/cpan/Scalar-List-Utils/lib/List/Util/XS.pm b/cpan/Scalar-List-Utils/lib/List/Util/XS.pm index c8c066f825..35f03b3219 100644 --- a/cpan/Scalar-List-Utils/lib/List/Util/XS.pm +++ b/cpan/Scalar-List-Utils/lib/List/Util/XS.pm @@ -3,8 +3,8 @@ use strict; use warnings; use List::Util; -our $VERSION = "1.50"; # FIXUP -$VERSION = eval $VERSION; # FIXUP +our $VERSION = "1.51"; # FIXUP +$VERSION =~ tr/_//d; # FIXUP 1; __END__ diff --git a/cpan/Scalar-List-Utils/lib/Scalar/Util.pm b/cpan/Scalar-List-Utils/lib/Scalar/Util.pm index 6982158705..14ae8c979b 100644 --- a/cpan/Scalar-List-Utils/lib/Scalar/Util.pm +++ b/cpan/Scalar-List-Utils/lib/Scalar/Util.pm @@ -17,8 +17,8 @@ our @EXPORT_OK = qw( dualvar isdual isvstring looks_like_number openhandle readonly set_prototype tainted ); -our $VERSION = "1.50"; -$VERSION = eval $VERSION; +our $VERSION = "1.51"; +$VERSION =~ tr/_//d; require List::Util; # List::Util loads the XS List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863) @@ -276,8 +276,8 @@ L<perlapi/looks_like_number>. my $fh = openhandle( $fh ); -Returns C<$fh> itself if C<$fh> may be used as a filehandle and is open, or is -is a tied handle. Otherwise C<undef> is returned. +Returns C<$fh> itself, if C<$fh> may be used as a filehandle and is open, or if +it is a tied handle. Otherwise C<undef> is returned. $fh = openhandle(*STDIN); # \*STDIN $fh = openhandle(\*STDIN); # \*STDIN diff --git a/cpan/Scalar-List-Utils/lib/Sub/Util.pm b/cpan/Scalar-List-Utils/lib/Sub/Util.pm index edcc6544f6..91be87e24e 100644 --- a/cpan/Scalar-List-Utils/lib/Sub/Util.pm +++ b/cpan/Scalar-List-Utils/lib/Sub/Util.pm @@ -15,8 +15,8 @@ our @EXPORT_OK = qw( subname set_subname ); -our $VERSION = "1.50"; -$VERSION = eval $VERSION; +our $VERSION = "1.51"; +$VERSION =~ tr/_//d; require List::Util; # as it has the XS List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863) @@ -95,8 +95,10 @@ I<Since version 1.40.> Returns the name of the given C<$code> reference, if it has one. Normal named subs will give a fully-qualified name consisting of the package and the localname separated by C<::>. Anonymous code references will give C<__ANON__> -as the localname. If a name has been set using L</set_subname>, this name will -be returned instead. +as the localname. If the package the code was compiled in has been deleted +(e.g. using C<delete_package> from L<Symbol>), C<__ANON__> will be returned as +the package name. If a name has been set using L</set_subname>, this name will be +returned instead. This function was inspired by C<sub_fullname> from L<Sub::Identify>. The remaining functions that C<Sub::Identify> implements can easily be emulated diff --git a/cpan/Scalar-List-Utils/t/pair.t b/cpan/Scalar-List-Utils/t/pair.t index e65123cc2c..7d7a6a9bb5 100644 --- a/cpan/Scalar-List-Utils/t/pair.t +++ b/cpan/Scalar-List-Utils/t/pair.t @@ -3,8 +3,9 @@ use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 29; use List::Util qw(pairgrep pairfirst pairmap pairs unpairs pairkeys pairvalues); +use Scalar::Util qw(blessed); no warnings 'misc'; # avoid "Odd number of elements" warnings most of the time @@ -104,6 +105,10 @@ is_deeply( [ pairs one => 1, two => ], my @p = pairs one => 1, two => 2; is( $p[0]->key, "one", 'pairs ->key' ); is( $p[0]->value, 1, 'pairs ->value' ); + is_deeply( $p[0]->TO_JSON, + [ one => 1 ], + 'pairs ->TO_JSON' ); + ok( !blessed($p[0]->TO_JSON) , 'pairs ->TO_JSON is not blessed' ); } is_deeply( [ unpairs [ four => 4 ], [ five => 5 ], [ six => 6 ] ], diff --git a/cpan/Scalar-List-Utils/t/subname.t b/cpan/Scalar-List-Utils/t/subname.t index 1bf8a9f698..c78a70043f 100644 --- a/cpan/Scalar-List-Utils/t/subname.t +++ b/cpan/Scalar-List-Utils/t/subname.t @@ -3,10 +3,11 @@ use warnings; BEGIN { $^P |= 0x210 } -use Test::More tests => 18; +use Test::More tests => 21; use B::Deparse; use Sub::Util qw( subname set_subname ); +use Symbol qw( delete_package ) ; { sub localfunc {} @@ -78,4 +79,18 @@ is($x->(), "main::foo"); 'subname of set_subname'); } +# this used to segfault + +{ + sub ToDelete::foo {} + + my $foo = \&ToDelete::foo; + + delete_package 'ToDelete'; + + is( subname($foo), "$]" >= 5.010 ? '__ANON__::foo' : 'ToDelete::foo', 'subname in deleted package' ); + ok( set_subname('NewPackage::foo', $foo), 'rename from deleted package' ); + is( subname($foo), 'NewPackage::foo', 'subname after rename' ); +} + # vim: ft=perl diff --git a/cpan/Scalar-List-Utils/t/uniq.t b/cpan/Scalar-List-Utils/t/uniq.t index 8806b8e7d7..8e76f21b9b 100644 --- a/cpan/Scalar-List-Utils/t/uniq.t +++ b/cpan/Scalar-List-Utils/t/uniq.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 30; +use Test::More tests => 33; use List::Util qw( uniqnum uniqstr uniq ); use Tie::Array; @@ -75,6 +75,18 @@ is_deeply( [ uniqnum qw( 1 1.1 1.2 1.3 ) ], [ 1, 1.1, 1.2, 1.3 ], 'uniqnum distinguishes floats' ); +{ + my @nums = map $_+0.1, 1e7..1e7+5; + is_deeply( [ uniqnum @nums ], + [ @nums ], + 'uniqnum distinguishes large floats' ); + + my @strings = map "$_", @nums; + is_deeply( [ uniqnum @strings ], + [ @strings ], + 'uniqnum distinguishes large floats (stringified)' ); +} + # Hard to know for sure what an Inf is going to be. Lets make one my $Inf = 0 + 1E1000; my $NaN; @@ -84,7 +96,7 @@ is_deeply( [ uniqnum 0, 1, 12345, $Inf, -$Inf, $NaN, 0, $Inf, $NaN ], [ 0, 1, 12345, $Inf, -$Inf, $NaN ], 'uniqnum preserves the special values of +-Inf and Nan' ); -{ +SKIP: { my $maxuint = ~0; my $maxint = ~0 >> 1; my $minint = -(~0 >> 1) - 1; @@ -94,6 +106,15 @@ is_deeply( [ uniqnum 0, 1, 12345, $Inf, -$Inf, $NaN, 0, $Inf, $NaN ], is_deeply( [ uniqnum @nums, 1.0 ], [ @nums ], 'uniqnum preserves uniqness of full integer range' ); + + my @strs = map "$_", @nums; + + skip( "Perl $] doesn't stringify UV_MAX right ($maxuint)", 1 ) + if $maxuint !~ /\A[0-9]+\z/; + + is_deeply( [ uniqnum @strs, "1.0" ], + [ @strs ], + 'uniqnum preserves uniqness of full integer range (stringified)' ); } { |