diff -Nru liblist-moreutils-perl-0.416/Changes liblist-moreutils-perl-0.430/Changes --- liblist-moreutils-perl-0.416/Changes 2016-07-06 14:08:59.000000000 +0000 +++ liblist-moreutils-perl-0.430/Changes 2020-10-21 13:42:50.000000000 +0000 @@ -1,5 +1,94 @@ Revision history for Perl extension List-MoreUtils +0.430 2020-10-21 + - bump List::MoreUtils::XS requirement to 0.430 + - release 0.429_001 without any further changes + +0.429_001 2020-10-05 + - fix failing installation in parallel make (Issue#38) + - infrastructure improvements and tooling updates, + lot's of author tests with according fixes added + - added slide and slideatatime functions wished by SCHWERN + - documentation fixes (PR#21, PR#33, PR#34, RT#126029, RT#132043, RT#132940) + +0.428 2017-12-11 + - release 0.427_001 without further changes + +0.427_001 2017-11-06 + - fix Issue#22 (Upgrading from LMU 0.416 to split XS/PP version will fail) + reported by Graham Knop (haarg), this time hopefully the right way, + repeated in RT#123310. + - fix Issue#29 (pairwise() PP implementation add tail undefs if arrays + sizes differs) reported by 0x62ash + +0.426 2017-10-12 + - release 0.425_002 without further changes + +0.425_002 2017-10-05 + - re-introduce Config::AutoConf + (https://rt.cpan.org/Ticket/Display.html?id=122875#txn-1745984) + for final satisfying RT#122875 + - bump required version of List::MoreUtils::XS to 0.426, if XS is available + +0.425_001 2017-09-27 + - fix broken arrayify prototype + - revert removal of old List::MoreUtils::XS parts + +0.425 2017-09-06 + - release 0.424_001 as 0.425 with XS is META.* after 136:0 PASS:FAIL + on CPAN Tester Matrix + +0.424_001 2017-09-05 + - Makefile.PL: modify PREREQ_PM instead of recommend dynamically + +0.423 2017-08-22 + - sync version with List::MoreUtils::XS + - add examples for binsert/bremove (LMU::XS issue #1, Thanks to shawnlaffan) + - update tests to latest List::MoreUtils::XS + - recommend List::MoreUtils::XS 0.423 + +0.420_001 2017-08-15 + - add some new functions: + * qsort (XS only) + * binsert + * bremove + * listcmp + * arrayify (RT#17230) + * samples (RT#77562) + * minmaxstr (RT#106401) + * lower_bound + * upper_bound + * equal_range + * frequencies + * occurrences + * mode (RT#91991) + * zip6 (RT#42921) + * reduce_0 + * reduce_1 + * reduce_u + - improve tests + - make List::MoreUtils::XS independent from List::MoreUtils + Note that List::MoreUtils::XS doesn't guarantee API stability - this + feature is only provided through List::MoreUtils as frontend. + - improve Makefile.PL regarding some build artifacts + +0.419 2017-04-06 + - Fix RT#120799: Makefile.PL fails due to unescaped paths interpolated + in regex pattern (thanks, A. Sinan Unur) + +0.418 2017-03-29 + - Clarify license conditions + - fix Changes version/date of 0.417_001 + +0.417_001 2017-03-21 + - Divorce List::MoreUtils and List::MoreUtils::XS + - Change license to Apache 2.0 to avoid code stealing without credits + - Don't support Perl 5.6 out of the box anymore + - fix RT#120235 - uniq examples are incorrect + - remove things which will be never done from TODO list as suggested + by Mark Aufflick in PR#18 + - Apply patch from Yanick Champoux to avoid spelling checker complains + 0.416 2016-07-06 - Change the way how the XS part is loaded as a result of RT#115808 - Fix some spelling errors (fix RT#115807), thanks Salvatore Bonaccorso diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/41097.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/41097.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/41097.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/41097.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -# use Carp; - -use List::MoreUtils qw(part); -while(1) { - my $i = 0; - # returns [1,3,5,7], [2,4,6,8] - my @part = part { $i++ % 2 } 1..8; -} diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/41494.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/41494.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/41494.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/41494.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -# use Carp; - -use List::MoreUtils; - -my @a = (10,11,12,13,14,15); -print "odd numbers: ", (List::MoreUtils::indexes {$_&1} @a), "\n"; - -for (;;) { - List::MoreUtils::indexes {$_&1} @a; -} diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/48669.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/48669.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/48669.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/48669.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use List::MoreUtils; -print List::MoreUtils->VERSION, "\n"; - -for (;;) { - eval { List::MoreUtils::any {die} 1 }; -} diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/49796.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/49796.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/49796.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/49796.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use List::MoreUtils; -print List::MoreUtils->VERSION, "\n"; - -my $obj = MyObj->new; -for (;;) { - eval { List::MoreUtils::uniq ($obj, $obj) }; -} - - -package MyObj; -use overload '""' => \&stringize; -sub new { - my ($class) = @_; - return bless {}, $class; -} -sub stringize { - die "MyObj stringize error"; -} diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/57499.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/57499.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/57499.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/57499.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use List::MoreUtils qw(pairwise); -my @left = (1..100); -my @right = (101..200); -pairwise { $a+ $b} @left, @right while 1; - diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/58325.pl liblist-moreutils-perl-0.430/debian/bug_report_demos/58325.pl --- liblist-moreutils-perl-0.416/debian/bug_report_demos/58325.pl 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/58325.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -#!/usr/bin/perl -#!/usr/bin/perl -use strict; -use warnings; - -# use Carp; - -use List::MoreUtils qw(apply); -while(1) { - apply {} (1); -} diff -Nru liblist-moreutils-perl-0.416/debian/bug_report_demos/README liblist-moreutils-perl-0.430/debian/bug_report_demos/README --- liblist-moreutils-perl-0.416/debian/bug_report_demos/README 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/bug_report_demos/README 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -This scripts were submitted to #rt as examples of -memory leaks. All these memory leaks appear now to be fixed. -The name of the script corresponds to the #rt bug number. diff -Nru liblist-moreutils-perl-0.416/debian/changelog liblist-moreutils-perl-0.430/debian/changelog --- liblist-moreutils-perl-0.416/debian/changelog 2020-11-09 11:44:08.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/changelog 2020-12-17 18:12:33.000000000 +0000 @@ -1,38 +1,55 @@ -liblist-moreutils-perl (0.416-1build6) hirsute; urgency=medium +liblist-moreutils-perl (0.430-2) unstable; urgency=medium - * No-change rebuild for the perl update. + * Add hard runtime dependency on liblist-moreutils-xs-perl. + Remove it from Recommends, add it to Depends. + (Closes: #977594) - -- Matthias Klose Mon, 09 Nov 2020 12:44:08 +0100 + -- gregor herrmann Thu, 17 Dec 2020 19:12:33 +0100 -liblist-moreutils-perl (0.416-1build5) focal; urgency=medium +liblist-moreutils-perl (0.430-1) unstable; urgency=medium - * No-change rebuild for the perl update. + [ Alex Muntada ] + * Remove inactive pkg-perl members from Uploaders. - -- Matthias Klose Fri, 18 Oct 2019 19:32:46 +0000 - -liblist-moreutils-perl (0.416-1build4) disco; urgency=medium - - * No-change rebuild for the perl 5.28 transition. - - -- Adam Conrad Fri, 02 Nov 2018 14:45:00 -0600 - -liblist-moreutils-perl (0.416-1build3) artful; urgency=medium - - * No-change rebuild for perl 5.26.0. - - -- Matthias Klose Wed, 26 Jul 2017 20:07:28 +0000 - -liblist-moreutils-perl (0.416-1build2) zesty; urgency=medium - - * No-change rebuild for perl 5.24 transition + [ Damyan Ivanov ] + * New upstream version 0.426 + * copyright: update for the new release + * add build dependency on libtest-leaktrace-perl - -- Iain Lane Mon, 24 Oct 2016 10:22:59 +0100 + [ Salvatore Bonaccorso ] + * Update Vcs-* headers for switch to salsa.debian.org -liblist-moreutils-perl (0.416-1build1) zesty; urgency=medium + [ Clément Hermann ] + * New upstream version 0.428 + * d/copyright: + - upstream licence change + refactoring + - use https url for apache license + * d/control: + - add Build-Depends / Recommends liblist-moreutils-xs-perl + - add explicit, versioned Build-Depends to avoid using embedded copies + - switch to Arch:all (no more compiled code) + * d/changelog: remove last line (containing single space) + * Declare compliance with policy 4.1.5 + * Bump compat level to 11 + * install Contributing.pod as documentation + * add patch to fix spelling in POD doc (forwarded upstream) - * No-change rebuild for perl 5.24 + [ gregor herrmann ] + * debian/watch: use uscan version 4. + * Import upstream version 0.430. + * Update years of packaging copyright. + * Update Upstream-Contact and add Upstream-Name. + * Update debian/upstream/metadata. + * Drop patch 001-spelling-errors.diff, applied upstream. + * Remove old debian/bug_report_demos. + * Declare compliance with Debian Policy 4.5.1. + * Set Rules-Requires-Root: no. + * Drop unneeded version constraints from (build) dependencies. + * Bump debhelper-compat to 13. + * Update build dependencies. + Add and bump versions. - -- Iain Lane Sun, 23 Oct 2016 14:10:20 +0100 + -- gregor herrmann Mon, 14 Dec 2020 17:19:18 +0100 liblist-moreutils-perl (0.416-1) unstable; urgency=medium @@ -276,4 +293,3 @@ * Initial Release. -- Chip Salzenberg Thu, 7 Apr 2005 19:27:38 -0400 - diff -Nru liblist-moreutils-perl-0.416/debian/compat liblist-moreutils-perl-0.430/debian/compat --- liblist-moreutils-perl-0.416/debian/compat 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -9 diff -Nru liblist-moreutils-perl-0.416/debian/control liblist-moreutils-perl-0.430/debian/control --- liblist-moreutils-perl-0.416/debian/control 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/control 2020-12-17 18:12:33.000000000 +0000 @@ -1,28 +1,32 @@ Source: liblist-moreutils-perl Maintainer: Debian Perl Group -Uploaders: Krzysztof Krzyzaniak (eloy) , - Damyan Ivanov , +Uploaders: Damyan Ivanov , Ansgar Burchardt , - gregor herrmann , - Alessandro Ghedini + gregor herrmann Section: perl Testsuite: autopkgtest-pkg-perl Priority: optional -Build-Depends: debhelper (>= 9.20120312~), - libexporter-tiny-perl, +Build-Depends: debhelper-compat (= 13), +# make sure those are more recent than the ones embedded in inc/ + libcapture-tiny-perl (>= 0.48), + libconfig-autoconf-perl (>= 0.319), + libexporter-tiny-perl , + liblist-moreutils-xs-perl , + libtest-leaktrace-perl , # Dependency on perl 5.22.2-2~ which contains the fix for CVE-2016-6185 perl (>= 5.22.2-2~) -Standards-Version: 3.9.8 -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/liblist-moreutils-perl.git -Vcs-Git: https://anonscm.debian.org/git/pkg-perl/packages/liblist-moreutils-perl.git +Standards-Version: 4.5.1 +Vcs-Browser: https://salsa.debian.org/perl-team/modules/packages/liblist-moreutils-perl +Vcs-Git: https://salsa.debian.org/perl-team/modules/packages/liblist-moreutils-perl.git Homepage: https://metacpan.org/release/List-MoreUtils +Rules-Requires-Root: no Package: liblist-moreutils-perl -Architecture: any +Architecture: all Depends: ${misc:Depends}, ${perl:Depends}, - ${shlibs:Depends}, libexporter-tiny-perl, + liblist-moreutils-xs-perl, # Dependency on perl 5.22.2-2~ which contains the fix for CVE-2016-6185 perl (>= 5.22.2-2~) Description: Perl module with additional list functions not found in List::Util diff -Nru liblist-moreutils-perl-0.416/debian/copyright liblist-moreutils-perl-0.430/debian/copyright --- liblist-moreutils-perl-0.416/debian/copyright 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/copyright 2020-12-17 18:12:33.000000000 +0000 @@ -1,28 +1,32 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Contact: Tassilo von Parseval Source: https://metacpan.org/release/List-MoreUtils +Upstream-Contact: Jens Rehsack +Upstream-Name: List-MoreUtils Files: * Copyright: 2004-2010, Tassilo von Parseval 2011, Aaron Crane - 2013-2016, Jens Rehsack -License: Artistic or GPL-1+ + 2013-2017, Jens Rehsack +License: Artistic or GPL-1+, and Apache-2.0 +Comment: Upstream decided to change the license without getting consent from + all past contributors. So in practice, code added from 0.417 onward is under + Apache-2.0 while the previous remain in under Artistic or GPL-1+. + . + New files are using Apache-2.0 only and should be in the relevant paragraph + below. + . + Refer to README.md and https://github.com/perl5-utils/List-MoreUtils/issues/24 + for more detail. Files: debian/* Copyright: 2005-2006, Krzysztof Krzyzaniak (eloy) 2005, Chip Salzenberg 2008, Damyan Ivanov 2009, Ansgar Burchardt - 2009-2015, gregor herrmann + 2009-2020, gregor herrmann 2011, Nicholas Bamber -License: Artistic or GPL-1+ - -Files: ppport.h -Copyright: 2004-2013, Marcus Holland-Moritz - 2001, Paul Marquess (Version 2.x) - 1999, Kenneth Albanowski (Version 1.x) -License: Artistic or GPL-1+ +License: Artistic or GPL-1+ or Apache-2.0 Files: inc/latest/private.pm inc/inc_Capture-Tiny/Capture/Tiny.pm @@ -30,9 +34,13 @@ License: Apache-2.0 Files: inc/inc_Config-AutoConf/Config/AutoConf.pm -Copyright: 2004-2016, Alberto Simões and Jens Rehsack +Copyright: 2004-2020, Alberto Simões and Jens Rehsack License: Artistic or GPL-1+ +Files: t/* +Copyright: 2013-2017, Jens Rehsack +License: Apache-2.0 + License: Artistic This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License, which comes with Perl. @@ -52,7 +60,7 @@ License: Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may - obtain a copy of the License at http://apache.org/licenses/LICENSE-2.0 + obtain a copy of the License at https://apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff -Nru liblist-moreutils-perl-0.416/debian/liblist-moreutils-perl.docs liblist-moreutils-perl-0.430/debian/liblist-moreutils-perl.docs --- liblist-moreutils-perl-0.416/debian/liblist-moreutils-perl.docs 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/liblist-moreutils-perl.docs 2020-12-17 18:12:33.000000000 +0000 @@ -0,0 +1 @@ +lib/List/MoreUtils/Contributing.pod diff -Nru liblist-moreutils-perl-0.416/debian/liblist-moreutils-perl.examples liblist-moreutils-perl-0.430/debian/liblist-moreutils-perl.examples --- liblist-moreutils-perl-0.416/debian/liblist-moreutils-perl.examples 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/liblist-moreutils-perl.examples 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -debian/bug_report_demos/* diff -Nru liblist-moreutils-perl-0.416/debian/rules liblist-moreutils-perl-0.430/debian/rules --- liblist-moreutils-perl-0.416/debian/rules 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/rules 2020-12-17 18:12:33.000000000 +0000 @@ -1,7 +1,9 @@ #!/usr/bin/make -f -export DEB_BUILD_MAINT_OPTIONS = hardening=+all +PACKAGE = $(shell dh_listpackages) +TMP = $(CURDIR)/debian/$(PACKAGE) +export DEB_BUILD_MAINT_OPTIONS = hardening=+all %: dh $@ @@ -14,3 +16,9 @@ [ ! -e $(CURDIR)/inc/latest.pm ] || cp -v $(CURDIR)/inc/latest.pm $(CURDIR)/inc/latest.pm.save [ ! -e $(CURDIR)/inc/latest/private.pm ] || cp -v $(CURDIR)/inc/latest/private.pm $(CURDIR)/inc/latest/private.pm.save dh_auto_configure + +# installed by upstream make install +override_dh_auto_install: + dh_auto_install + $(RM) --verbose $(TMP)/usr/share/perl5/List/MoreUtils/Contributing.pod \ + $(TMP)/usr/share/man/man3/List::MoreUtils::Contributing.3pm diff -Nru liblist-moreutils-perl-0.416/debian/upstream/metadata liblist-moreutils-perl-0.430/debian/upstream/metadata --- liblist-moreutils-perl-0.416/debian/upstream/metadata 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/upstream/metadata 2020-12-17 18:12:33.000000000 +0000 @@ -1,9 +1,6 @@ --- Archive: CPAN -Bug-Database: https://rt.cpan.org/Public/Dist/Display.html?Name=List-MoreUtils +Bug-Database: https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils Bug-Submit: bug-List-MoreUtils@rt.cpan.org -Contact: Tassilo von Parseval , Adam Kennedy - , Jens Rehsack -Name: List-MoreUtils Repository: https://github.com/perl5-utils/List-MoreUtils.git Repository-Browse: https://github.com/perl5-utils/List-MoreUtils diff -Nru liblist-moreutils-perl-0.416/debian/watch liblist-moreutils-perl-0.430/debian/watch --- liblist-moreutils-perl-0.416/debian/watch 2016-07-12 06:57:14.000000000 +0000 +++ liblist-moreutils-perl-0.430/debian/watch 2020-12-17 18:12:33.000000000 +0000 @@ -1,2 +1,2 @@ -version=3 -https://metacpan.org/release/List-MoreUtils .*/List-MoreUtils-v?(\d[\d.]*)\.tar\.gz +version=4 +https://metacpan.org/release/List-MoreUtils .*/List-MoreUtils-v?@ANY_VERSION@@ARCHIVE_EXT@$ diff -Nru liblist-moreutils-perl-0.416/dhash.h liblist-moreutils-perl-0.430/dhash.h --- liblist-moreutils-perl-0.416/dhash.h 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/dhash.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,137 +0,0 @@ -#ifndef __DHASH_H__ -#define __DHASH_H__ - -/* A special hash-type for use in part(). It is a store-only - * hash in that all key/value pairs are put into the hash. Then it is sorted by - * keys ascending with dhash_sort_final where the empty elements come at the end - * of the internal array. This need for sorting is actually what prevents us from - * using a dhash-based implementaion right now as it is the bottleneck for cases - * with many very small partitions. - * - * It doesn't use a linked list for collision recovery. Instead, on collision it will - * walk right in the array to find the first free spot. This search should never take - * too long as it uses a fairly good integer-hash function. - * - * The 'step' parameter isn't currently used. - */ - -#include /* for qsort() */ - -#define INITIAL_SIZE 4 - -typedef unsigned int hash_t; - -typedef struct { - int key; - AV *val; -} dhash_val_t; - -typedef struct { - int max; - int size; - int count; - int step; - dhash_val_t *ary; -} dhash_t; - -void dhash_dump(dhash_t *h); - -int cmp (dhash_val_t *a, dhash_val_t *b) { - /* all empty buckets should be at the end of the array */ - if (!a->val) - return 1; - if (!b->val) - return -1; - return a->key - b->key; -} - -dhash_t * dhash_init() { - dhash_t *h; - New(0, h, 1, dhash_t); - Newz(0, h->ary, INITIAL_SIZE, dhash_val_t); - h->max = 0; - h->size = INITIAL_SIZE; - h->count = 0; - return h; -} - -void dhash_destroy(dhash_t *h) { - Safefree(h->ary); - Safefree(h); -} - -inline hash_t HASH(register hash_t k) { - k += (k << 12); - k ^= (k >> 22); - k += (k << 4); - k ^= (k >> 9); - k += (k << 10); - k ^= (k >> 2); - k += (k << 7); - k ^= (k >> 12); - return k; -} - -void dhash_insert(dhash_t *h, int key, SV *sv, register hash_t hash) { - - while (h->ary[hash].val && h->ary[hash].key != key) - hash = (hash + 1) % h->size; - - if (!h->ary[hash].val) { - h->ary[hash].val = newAV(); - h->ary[hash].key = key; - h->count++; - } - - av_push(h->ary[hash].val, sv); - SvREFCNT_inc(sv); -} - -void dhash_resize(dhash_t *h) { - - register int i; - register hash_t hash; - dhash_val_t *old = h->ary; - - h->size <<= 1; - h->count = 0; - Newz(0, h->ary, h->size, dhash_val_t); - - for (i = 0; i < h->size>>1; ++i) { - if (!old[i].val) - continue; - hash = HASH(old[i].key) % h->size; - while (h->ary[hash].val) - hash = (hash + 1) % h->size; - h->ary[hash] = old[i]; - ++h->count; - } - Safefree(old); -} - -void dhash_store(dhash_t *h, int key, SV *val) { - hash_t hash; - if ((double)h->count / (double)h->size > 0.75) - dhash_resize(h); - hash = HASH(key) % h->size; - dhash_insert(h, key, val, hash); - if (key > h->max) - h->max = key; -} - -/* Once this is called, the hash is no longer useable. The only thing - * that may be done with it is iterate over h->ary to get the values - * sorted by keys */ -void dhash_sort_final(dhash_t *h) { - qsort(h->ary, h->size, sizeof(dhash_val_t), (int(*)(const void*,const void*))cmp); -} - -void dhash_dump(dhash_t *h) { - int i; - fprintf(stderr, "max=%i, size=%i, count=%i, ary=%p\n", h->max, h->size, h->count, h->ary); - for (i = 0; i < h->size; i++) { - fprintf(stderr, "%2i: key=%-5i => val=(AV*)%p\n", i, h->ary[i].key, h->ary[i].val); - } -} - -#endif diff -Nru liblist-moreutils-perl-0.416/inc/Config/AutoConf/LMU.pm liblist-moreutils-perl-0.430/inc/Config/AutoConf/LMU.pm --- liblist-moreutils-perl-0.416/inc/Config/AutoConf/LMU.pm 2015-05-08 17:33:58.000000000 +0000 +++ liblist-moreutils-perl-0.430/inc/Config/AutoConf/LMU.pm 2020-10-05 09:16:39.000000000 +0000 @@ -3,17 +3,17 @@ use strict; use warnings; -use Config::AutoConf '0.306'; +use Config::AutoConf '0.315'; use base qw(Config::AutoConf); sub _check_pureperl_required { my $self = shift->_get_instance; - foreach ( @{ $self->{_argv} } ) + foreach (@{$self->{_argv}}) { - /^-pm/ and warn "-pm is depreciated, please use PUREPERL_ONLY=1" and return 0; - /^-xs/ and warn "-xs is depreciated, building XS is default anyway" and return $self->{_force_xs} = 1; + /^-pm/ and warn "-pm is depreciated, please use PUREPERL_ONLY=1" and return 1; + /^-xs/ and warn "-xs is depreciated, building XS is default anyway" and return !($self->{_force_xs} = 1); } return $self->SUPER::_check_pureperl_required(@_); } @@ -21,7 +21,7 @@ sub check_produce_xs_build { my $self = shift->_get_instance; - my $xs = $self->SUPER::check_produce_xs_build(@_); + my $xs = $self->SUPER::check_produce_xs_build(@_); $self->{_force_xs} and !$xs and $self->msg_error("XS forced but can't compile - giving up"); return $xs; } diff -Nru liblist-moreutils-perl-0.416/inc/inc_Capture-Tiny/Capture/Tiny.pm liblist-moreutils-perl-0.430/inc/inc_Capture-Tiny/Capture/Tiny.pm --- liblist-moreutils-perl-0.416/inc/inc_Capture-Tiny/Capture/Tiny.pm 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/inc/inc_Capture-Tiny/Capture/Tiny.pm 2020-10-02 06:23:35.000000000 +0000 @@ -3,7 +3,7 @@ use warnings; package Capture::Tiny; # ABSTRACT: Capture STDOUT and STDERR from Perl, XS or external programs -our $VERSION = '0.36'; +our $VERSION = '0.48'; use Carp (); use Exporter (); use IO::Handle (); @@ -81,7 +81,7 @@ #--------------------------------------------------------------------------# sub _relayer { - my ($fh, $layers) = @_; + my ($fh, $apply_layers) = @_; # _debug("# requested layers (@{$layers}) for @{[fileno $fh]}\n"); # eliminate pseudo-layers @@ -91,7 +91,7 @@ binmode( $fh, ":pop" ); } # apply other layers - my @to_apply = @$layers; + my @to_apply = @$apply_layers; shift @to_apply; # eliminate initial :unix # _debug("# applying layers (unix @to_apply) to @{[fileno $fh]}\n"); binmode($fh, ":" . join(":",@to_apply)); @@ -214,7 +214,7 @@ stderr => $stash->{capture}{$which}, }; # flag file is used to signal the child is ready - $stash->{flag_files}{$which} = scalar tmpnam(); + $stash->{flag_files}{$which} = scalar( tmpnam() ) . $$; # execute @cmd as a separate process if ( $IS_WIN32 ) { my $old_eval_err=$@; @@ -436,7 +436,7 @@ =head1 VERSION -version 0.36 +version 0.48 =head1 SYNOPSIS @@ -705,6 +705,17 @@ captures. Other problems may occur in the child or parent, as well. Forking in a capture block is not recommended. +=head3 Using threads + +Filehandles are global. Mixing up I/O and captures in different threads +without coordination is going to cause problems. Besides, threads are +officially discouraged. + +=head3 Dropping privileges during a capture + +If you drop privileges during a capture, temporary files created to +facilitate the capture may not be cleaned up afterwards. + =head2 No support for Perl 5.8.0 It's just too buggy when it comes to layers and UTF-8. Perl 5.8.1 or later @@ -853,7 +864,7 @@ =head1 CONTRIBUTORS -=for stopwords Dagfinn Ilmari Mannsåker David E. Wheeler fecundf +=for stopwords Dagfinn Ilmari Mannsåker David E. Wheeler fecundf Graham Knop Peter Rabbitson =over 4 @@ -869,6 +880,14 @@ fecundf +=item * + +Graham Knop + +=item * + +Peter Rabbitson + =back =head1 COPYRIGHT AND LICENSE diff -Nru liblist-moreutils-perl-0.416/inc/inc_Config-AutoConf/Config/AutoConf.pm liblist-moreutils-perl-0.430/inc/inc_Config-AutoConf/Config/AutoConf.pm --- liblist-moreutils-perl-0.416/inc/inc_Config-AutoConf/Config/AutoConf.pm 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/inc/inc_Config-AutoConf/Config/AutoConf.pm 2020-10-02 06:23:36.000000000 +0000 @@ -5,7 +5,7 @@ use base 'Exporter'; -our @EXPORT = ( '$LIBEXT', '$EXEEXT' ); +our @EXPORT = ('$LIBEXT', '$EXEEXT'); use constant QUOTE => do { $^O eq "MSWin32" ? q["] : q['] }; @@ -47,8 +47,8 @@ } EOP -eval "use File::Slurp::Tiny qw/read_file/;"; -__PACKAGE__->can("read_file") or eval <<'EOP'; +eval "use File::Slurper qw/read_binary/;"; +__PACKAGE__->can("read_binary") or eval <<'EOP'; =begin private =head2 read_file @@ -57,7 +57,7 @@ =cut -sub read_file { +sub read_binary { my $fn = shift; local $@ = ""; open( my $fh, "<", $fn ) or croak "Error opening $fn: $!"; @@ -71,10 +71,10 @@ my %special_dlext = ( darwin => ".dylib", MSWin32 => ".dll", - ( $Config{archname} =~ m/PA-RISC/i ? ( "hpux" => ".sl" ) : () ), + ($Config{archname} =~ m/PA-RISC/i ? ("hpux" => ".sl") : ()), ); -our ( $LIBEXT, $EXEEXT ); +our ($LIBEXT, $EXEEXT); defined $LIBEXT or $LIBEXT = @@ -82,7 +82,7 @@ : defined $special_dlext{$^O} ? $special_dlext{$^O} : ".so"; defined $EXEEXT - or $EXEEXT = ( $^O eq "MSWin32" ) ? ".exe" : ""; + or $EXEEXT = ($^O eq "MSWin32") ? ".exe" : ""; =encoding UTF-8 @@ -92,7 +92,7 @@ =cut -our $VERSION = '0.313'; +our $VERSION = '0.319'; $VERSION = eval $VERSION; =head1 ABSTRACT @@ -142,7 +142,7 @@ =head2 new -This function instantiates a new instance of Config::AutoConf, eg. to +This function instantiates a new instance of Config::AutoConf, e.g. to configure child components. The constructor adds also values set via environment variable C. @@ -155,10 +155,10 @@ my %args = @_; my %flags = map { - my ( $k, $v ) = split( "=", $_, 2 ); + my ($k, $v) = split("=", $_, 2); defined $v or $v = 1; - ( $k, $v ) - } split( ":", $ENV{PERL5_AC_OPTS} ) if ( $ENV{PERL5_AC_OPTS} ); + ($k, $v) + } split(":", $ENV{PERL5_AC_OPTS}) if ($ENV{PERL5_AC_OPTS}); my %instance = ( msg_prefix => 'configure: ', @@ -181,7 +181,7 @@ c_ac_flags => {%flags}, %args ); - bless( \%instance, $class ); + bless(\%instance, $class); } =head1 METHODS @@ -196,8 +196,17 @@ sub check_file { - my ( $self, $file ) = @_; - -f $file && -r $file; + my $self = shift->_get_instance(); + my $file = shift; + + my $cache_name = $self->_cache_name("file", $file); + $self->check_cached( + $cache_name, + "for $file", + sub { + -f $file && -r $file; + } + ); } =head2 check_files @@ -209,7 +218,7 @@ sub check_files { - my $self = shift; + my $self = shift->_get_instance(); for (@_) { @@ -219,14 +228,17 @@ 1; } -sub _sanitize_prog +sub _quote_shell_arg { scalar Text::ParseWords::shellwords($_[0]) > 1 ? QUOTE . $_[0] . QUOTE : $_[0] } + +sub _sanitize_prog { shift; _quote_shell_arg shift } + +sub _append_prog_args { - my ( $self, $prog ) = @_; - ( scalar Text::ParseWords::shellwords $prog) > 1 and $prog = QUOTE . $prog . QUOTE; - $prog; + shift; + join " ", map { _quote_shell_arg $_ } @_; } -my @exe_exts = ( $^O eq "MSWin32" ? qw(.exe .com .bat .cmd) : ("") ); +my @exe_exts = ($^O eq "MSWin32" ? qw(.exe .com .bat .cmd) : ("")); =head2 check_prog( $prog, \@dirlist?, \%options? ) @@ -243,28 +255,29 @@ sub check_prog { - my $self = shift; + my $self = shift->_get_instance(); # sanitize ac_prog - my $ac_prog = _sanitize( shift @_ ); + my $ac_prog = _sanitize(shift @_); my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my @dirlist; @_ and scalar @_ > 1 and @dirlist = @_; - @_ and scalar @_ == 1 and ref $_[0] eq "ARRAY" and @dirlist = @{ $_[0] }; - @dirlist or @dirlist = split( /$Config{path_sep}/, $ENV{PATH} ); + @_ and scalar @_ == 1 and ref $_[0] eq "ARRAY" and @dirlist = @{$_[0]}; + @dirlist or @dirlist = split(/$Config{path_sep}/, $ENV{PATH}); for my $p (@dirlist) { for my $e (@exe_exts) { - my $cmd = $self->_sanitize_prog( File::Spec->catfile( $p, $ac_prog . $e ) ); - -x $cmd + my $cmd = $self->_sanitize_prog(File::Spec->catfile($p, $ac_prog . $e)); + my $is_executable = -x $cmd and -f $cmd; + $is_executable and $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $options->{action_on_true}->(); - -x $cmd and return $cmd; + $is_executable and return $cmd; } } @@ -292,25 +305,25 @@ sub check_progs { - my $self = shift; + my $self = shift->_get_instance(); my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my @dirlist; - scalar @_ > 1 and ref $_[-1] eq "ARRAY" and @dirlist = @{ pop @_ }; - @dirlist or @dirlist = split( /$Config{path_sep}/, $ENV{PATH} ); + scalar @_ > 1 and ref $_[-1] eq "ARRAY" and @dirlist = @{pop @_}; + @dirlist or @dirlist = split(/$Config{path_sep}/, $ENV{PATH}); my @progs = @_; foreach my $prog (@progs) { defined $prog or next; - my $ans = $self->check_prog( $prog, \@dirlist ); + my $ans = $self->check_prog($prog, \@dirlist); $ans and $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" - and $options->{action_if_true}->( $prog, $ans ); + and $options->{action_if_true}->($prog, $ans); $ans and return $ans; } @@ -322,15 +335,9 @@ return; } -sub _append_prog_args -{ - my ( $self, $prog ) = @_; - join( " ", $self->_sanitize_prog($prog), @_ ); -} - =head2 check_prog_yacc -From the autoconf documentation, +From the L documentation, If `bison' is found, set [...] `bison -y'. Otherwise, if `byacc' is found, set [...] `byacc'. @@ -343,11 +350,11 @@ sub check_prog_yacc { - my $self = shift; + my $self = shift->_get_instance(); # my ($self, $cache_name, $message, $check_sub) = @_; - my $cache_name = $self->_cache_name( "prog", "YACC" ); + my $cache_name = $self->_cache_name("prog", "YACC"); $self->check_cached( $cache_name, "for yacc", @@ -356,7 +363,7 @@ my $binary = $self->check_progs(qw/bison byacc yacc/); defined $binary and $binary =~ /bison(?:\.(?:exe|com|bat|cmd))?$/ - and $binary = $self->_append_prog_args( $binary, "-y" ); + and $binary = $self->_append_prog_args($binary, "-y"); return $binary; } ); @@ -364,7 +371,7 @@ =head2 check_prog_awk -From the autoconf documentation, +From the L documentation, Check for `gawk', `mawk', `nawk', and `awk', in that order, and set output [...] to the first one that is found. It tries @@ -378,14 +385,14 @@ sub check_prog_awk { - my $self = shift; - my $cache_name = $self->_cache_name( "prog", "AWK" ); - $self->check_cached( $cache_name, "for awk", sub { $ENV{AWK} || $self->check_progs(qw/gawk mawk nawk awk/) } ); + my $self = shift->_get_instance(); + my $cache_name = $self->_cache_name("prog", "AWK"); + $self->check_cached($cache_name, "for awk", sub { $ENV{AWK} || $self->check_progs(qw/gawk mawk nawk awk/) }); } =head2 check_prog_egrep -From the autoconf documentation, +From the L documentation, Check for `grep -E' and `egrep', in that order, and [...] output [...] the first one that is found. The result can be overridden by @@ -398,9 +405,9 @@ sub check_prog_egrep { - my $self = shift; + my $self = shift->_get_instance(); - my $cache_name = $self->_cache_name( "prog", "EGREP" ); + my $cache_name = $self->_cache_name("prog", "EGREP"); $self->check_cached( $cache_name, "for egrep", @@ -409,12 +416,12 @@ my $grep; $grep = $self->check_progs("egrep") and return $grep; - if ( $grep = $self->check_prog("grep") ) + if ($grep = $self->check_prog("grep")) { # check_run - Capture::Tiny, Open3 ... ftw! my $ans = `echo a | ($grep -E '(a|b)') 2>/dev/null`; chomp $ans; - $ans eq "a" and return $self->_append_prog_args( $grep, "-E" ); + $ans eq "a" and return $self->_append_prog_args($grep, "-E"); } } ); @@ -422,7 +429,7 @@ =head2 check_prog_lex -From the autoconf documentation, +From the L documentation, If flex is found, set output [...] to ‘flex’ and [...] to -lfl, if that library is in a standard place. Otherwise set output [...] to ‘lex’ and @@ -444,8 +451,8 @@ sub check_prog_lex { my $self = shift->_get_instance; - my $cache_name = $self->_cache_name( "prog", "LEX" ); - my $lex = $self->check_cached( $cache_name, "for lex", sub { $ENV{LEX} || $self->check_progs(qw/flex lex/) } ); + my $cache_name = $self->_cache_name("prog", "LEX"); + my $lex = $self->check_cached($cache_name, "for lex", sub { $ENV{LEX} || $self->check_progs(qw/flex lex/) }); if ($lex) { defined $self->{lex}->{prog} or $self->{lex}->{prog} = $lex; @@ -453,7 +460,7 @@ "ac_cv_prog_lex_root", "for lex output file root", sub { - my ( $fh, $filename ) = tempfile( + my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.l', UNLINK => 0 @@ -482,8 +489,8 @@ print {$fh} $src; close $fh; - my ( $stdout, $stderr, $exit ) = - capture { system( $lex, $filename ); }; + my ($stdout, $stderr, $exit) = + capture { system($lex, $filename); }; chomp $stdout; unlink $filename; -f "lex.yy.c" and return "lex.yy"; @@ -493,36 +500,36 @@ ); defined $self->{lex}->{root} or $self->{lex}->{root} = $lex_root_var; - my $conftest = read_file( $lex_root_var . ".c" ); + my $conftest = read_binary($lex_root_var . ".c"); unlink $lex_root_var . ".c"; - $cache_name = $self->_cache_name( "lib", "lex" ); + $cache_name = $self->_cache_name("lib", "lex"); my $check_sub = sub { - my @save_libs = @{ $self->{extra_libs} }; + my @save_libs = @{$self->{extra_libs}}; my $have_lib = 0; - foreach my $libstest ( undef, qw(-lfl -ll) ) + foreach my $libstest (undef, qw(-lfl -ll)) { # XXX would local work on array refs? can we omit @save_libs? $self->{extra_libs} = [@save_libs]; - defined($libstest) and unshift( @{ $self->{extra_libs} }, $libstest ); + defined($libstest) and unshift(@{$self->{extra_libs}}, $libstest); $self->link_if_else($conftest) - and ( $have_lib = defined($libstest) ? $libstest : "none required" ) + and ($have_lib = defined($libstest) ? $libstest : "none required") and last; } $self->{extra_libs} = [@save_libs]; if ($have_lib) { - $self->define_var( _have_lib_define_name("lex"), $have_lib, "defined when lex library is available" ); + $self->define_var(_have_lib_define_name("lex"), $have_lib, "defined when lex library is available"); } else { - $self->define_var( _have_lib_define_name("lex"), undef, "defined when lex library is available" ); + $self->define_var(_have_lib_define_name("lex"), undef, "defined when lex library is available"); } return $have_lib; }; - my $lex_lib = $self->check_cached( $cache_name, "lex library", $check_sub ); + my $lex_lib = $self->check_cached($cache_name, "lex library", $check_sub); defined $self->{lex}->{lib} or $self->{lex}->{lib} = $lex_lib; } @@ -531,7 +538,7 @@ =head2 check_prog_sed -From the autoconf documentation, +From the L documentation, Set output variable [...] to a Sed implementation that conforms to Posix and does not have arbitrary length limits. Report an error if no @@ -547,9 +554,9 @@ sub check_prog_sed { - my $self = shift; - my $cache_name = $self->_cache_name( "prog", "SED" ); - $self->check_cached( $cache_name, "for sed", sub { $ENV{SED} || $self->check_progs(qw/gsed sed/) } ); + my $self = shift->_get_instance(); + my $cache_name = $self->_cache_name("prog", "SED"); + $self->check_cached($cache_name, "for sed", sub { $ENV{SED} || $self->check_progs(qw/gsed sed/) }); } =head2 check_prog_pkg_config @@ -560,9 +567,9 @@ sub check_prog_pkg_config { - my $self = shift->_get_instance(); - my $cache_name = $self->_cache_name( "prog", "PKG_CONFIG" ); - $self->check_cached( $cache_name, "for pkg-config", sub { $self->check_prog("pkg-config") } ); + my $self = shift->_get_instance(); + my $cache_name = $self->_cache_name("prog", "PKG_CONFIG"); + $self->check_cached($cache_name, "for pkg-config", sub { $self->check_prog("pkg-config") }); } =head2 check_prog_cc @@ -573,8 +580,8 @@ sub check_prog_cc { - my $self = shift; - my $cache_name = $self->_cache_name( "prog", "CC" ); + my $self = shift->_get_instance(); + my $cache_name = $self->_cache_name("prog", "CC"); $self->check_cached( $cache_name, @@ -583,7 +590,7 @@ $self->{lang_supported}->{C} = undef; eval "use ExtUtils::CBuilder;"; $@ and return; - my $cb = ExtUtils::CBuilder->new( quiet => 1 ); + my $cb = ExtUtils::CBuilder->new(quiet => 1); $cb->have_compiler or return; $self->{lang_supported}->{C} = "ExtUtils::CBuilder"; $cb->{config}->{cc}; @@ -625,7 +632,7 @@ sub check_valid_compilers { my $self = shift; - for my $lang ( @{ $_[0] } ) + for my $lang (@{$_[0]}) { $self->push_lang($lang); my $supp = $self->check_valid_compiler; @@ -646,8 +653,8 @@ { my $self = shift->_get_instance(); $self->{quiet} - or print "Checking " . join( " ", @_ ) . "... "; - $self->_add_log_entry( "Checking " . join( " ", @_, "..." ) ); + or print "Checking " . join(" ", @_) . "... "; + $self->_add_log_entry("Checking " . join(" ", @_, "...")); return; } @@ -662,7 +669,7 @@ sub _neat { defined $_[0] or return ""; - looks_like_number( $_[0] ) and defined $_num_to_msg[ $_[0] ] and return $_num_to_msg[ $_[0] ]; + looks_like_number($_[0]) and defined $_num_to_msg[$_[0]] and return $_num_to_msg[$_[0]]; $_[0]; } @@ -670,8 +677,8 @@ { my $self = shift->_get_instance(); $self->{quiet} - or print join( " ", map { _neat $_ } @_ ), "\n"; - $self->_add_log_entry( join( " ", map { _neat $_ } @_ ), "\n" ); + or print join(" ", map { _neat $_ } @_), "\n"; + $self->_add_log_entry(join(" ", map { _neat $_ } @_), "\n"); return; } @@ -685,8 +692,8 @@ { my $self = shift->_get_instance(); $self->{quiet} - or print $self->{msg_prefix} . join( " ", @_ ) . "\n"; - $self->_add_log_entry( $self->{msg_prefix} . join( " ", @_ ) . "\n" ); + or print $self->{msg_prefix} . join(" ", @_) . "\n"; + $self->_add_log_entry($self->{msg_prefix} . join(" ", @_) . "\n"); return; } @@ -699,8 +706,8 @@ sub msg_warn { my $self = shift->_get_instance(); - print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; - $self->_add_log_entry( "WARNING: " . $self->{msg_prefix} . join( " ", @_ ) . "\n" ); + print STDERR $self->{msg_prefix} . join(" ", @_) . "\n"; + $self->_add_log_entry("WARNING: " . $self->{msg_prefix} . join(" ", @_) . "\n"); return; } @@ -714,8 +721,8 @@ sub msg_error { my $self = shift->_get_instance(); - print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; - $self->_add_log_entry( "ERROR: " . $self->{msg_prefix} . join( " ", @_ ) . "\n" ); + print STDERR $self->{msg_prefix} . join(" ", @_) . "\n"; + $self->_add_log_entry("ERROR: " . $self->{msg_prefix} . join(" ", @_) . "\n"); exit(0); # #toolchain agreement: prevents configure stage to finish } @@ -731,8 +738,8 @@ sub msg_failure { my $self = shift->_get_instance(); - print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; - $self->_add_log_entry( "FAILURE: " . $self->{msg_prefix} . join( " ", @_ ) . "\n" ); + print STDERR $self->{msg_prefix} . join(" ", @_) . "\n"; + $self->_add_log_entry("FAILURE: " . $self->{msg_prefix} . join(" ", @_) . "\n"); exit(0); # #toolchain agreement: prevents configure stage to finish } @@ -746,10 +753,10 @@ sub define_var { my $self = shift->_get_instance(); - my ( $name, $value, $comment ) = @_; + my ($name, $value, $comment) = @_; defined($name) or croak("Need a name to add a define"); - $self->{defines}->{$name} = [ $value, $comment ]; + $self->{defines}->{$name} = [$value, $comment]; $value; } @@ -766,13 +773,13 @@ my $self = shift->_get_instance(); my $tgt; - defined( $_[0] ) + defined($_[0]) ? ( - ref( $_[0] ) + ref($_[0]) ? $tgt = $_[0] - : open( $tgt, ">", $_[0] ) + : open($tgt, ">", $_[0]) ) - : open( $tgt, ">", "config.h" ); + : open($tgt, ">", "config.h"); my $conf_h = <<'EOC'; /** @@ -789,17 +796,17 @@ EOC - while ( my ( $defname, $defcnt ) = each( %{ $self->{defines} } ) ) + while (my ($defname, $defcnt) = each(%{$self->{defines}})) { - if ( $defcnt->[0] ) + if ($defcnt->[0]) { defined $defcnt->[1] and $conf_h .= "/* " . $defcnt->[1] . " */\n"; - $conf_h .= join( " ", "#define", $defname, $defcnt->[0] ) . "\n"; + $conf_h .= join(" ", "#define", $defname, $defcnt->[0]) . "\n"; } else { defined $defcnt->[1] and $conf_h .= "/* " . $defcnt->[1] . " */\n"; - $conf_h .= "/* " . join( " ", "#undef", $defname ) . " */\n\n"; + $conf_h .= "/* " . join(" ", "#undef", $defname) . " */\n\n"; } } $conf_h .= "#endif /* ?__CONFIG_H__ */\n"; @@ -820,7 +827,7 @@ { my $self = shift->_get_instance(); - push @{ $self->{lang_stack} }, [ $self->{lang} ]; + push @{$self->{lang_stack}}, [$self->{lang}]; $self->_set_language(@_); } @@ -837,44 +844,12 @@ { my $self = shift->_get_instance(); - scalar( @{ $self->{lang_stack} } ) > 0 or croak("Language stack empty"); - defined( $_[0] ) + scalar(@{$self->{lang_stack}}) > 0 or croak("Language stack empty"); + defined($_[0]) and $self->{lang} ne $_[0] - and croak( "pop_lang( $_[0] ) doesn't match language in use (" . $self->{lang} . ")" ); + and croak("pop_lang( $_[0] ) doesn't match language in use (" . $self->{lang} . ")"); - $self->_set_language( @{ pop @{ $self->{lang_stack} } } ); -} - -=head2 lang_call( [prologue], function ) - -Builds program which simply calls given function. -When given, prologue is prepended otherwise, the default -includes are used. - -=cut - -sub lang_call -{ - my ( $self, $prologue, $function ) = @_; - ref $self or $self = $self->_get_instance(); - - defined($prologue) or $prologue = $self->_default_includes(); - $prologue .= <<"_ACEOF"; -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" { -#endif -char $function (); -#ifdef __cplusplus -} -#endif -_ACEOF - my $body = "return $function ();"; - $body = $self->_build_main($body); - - $self->_fill_defines() . "\n$prologue\n\n$body\n"; + $self->_set_language(@{pop @{$self->{lang_stack}}}); } =head2 lang_build_program( prologue, body ) @@ -914,7 +889,7 @@ sub lang_build_program { - my ( $self, $prologue, $body ) = @_; + my ($self, $prologue, $body) = @_; ref $self or $self = $self->_get_instance(); defined($prologue) or $prologue = $self->_default_includes(); @@ -924,6 +899,100 @@ $self->_fill_defines() . "\n$prologue\n\n$body\n"; } +sub _lang_prologue_func +{ + my ($self, $prologue, $function) = @_; + ref $self or $self = $self->_get_instance(); + + defined($prologue) or $prologue = $self->_default_includes(); + $prologue .= <<"_ACEOF"; +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" { +#endif +char $function (); +#ifdef __cplusplus +} +#endif +_ACEOF + + return $prologue; +} + +sub _lang_body_func +{ + my ($self, $function) = @_; + ref $self or $self = $self->_get_instance(); + + my $func_call = "return $function ();"; + return $func_call; +} + +=head2 lang_call( [prologue], function ) + +Builds program which simply calls given function. +When given, prologue is prepended otherwise, the default +includes are used. + +=cut + +sub lang_call +{ + my ($self, $prologue, $function) = @_; + ref $self or $self = $self->_get_instance(); + + return $self->lang_build_program($self->_lang_prologue_func($prologue, $function), $self->_lang_body_func($function),); +} + +sub _lang_prologue_builtin +{ + my ($self, $prologue, $builtin) = @_; + ref $self or $self = $self->_get_instance(); + + defined($prologue) or $prologue = $self->_default_includes(); + $prologue .= <<"_ACEOF"; +#if !defined(__has_builtin) +#undef $builtin +/* Declare this builtin with the same prototype as __builtin_$builtin. + This removes a warning about conflicting types for built-in builtin $builtin */ +__typeof__(__builtin_$builtin) $builtin; +__typeof__(__builtin_$builtin) *f = $builtin; +#endif +_ACEOF +} + +sub _lang_body_builtin +{ + my ($self, $builtin) = @_; + ref $self or $self = $self->_get_instance(); + + my $body = <<"_ACEOF"; +#if !defined(__has_builtin) +return f != $builtin; +#else +return __has_builtin($builtin); +#endif +_ACEOF + return $body; +} + +=head2 lang_builtin( [prologue], builtin ) + +Builds program which simply proves whether a builtin is known to +language compiler. + +=cut + +sub lang_builtin +{ + my ($self, $prologue, $builtin) = @_; + ref $self or $self = $self->_get_instance(); + + return $self->lang_build_program($self->_lang_prologue_func($prologue, $builtin), $self->_lang_body_builtin($builtin),); +} + =head2 lang_build_bool_test (prologue, test, [@decls]) Builds a static test which will fail to compile when test @@ -934,7 +1003,7 @@ sub lang_build_bool_test { - my ( $self, $prologue, $test, @decls ) = @_; + my ($self, $prologue, $test, @decls) = @_; ref $self or $self = $self->_get_instance(); defined($test) or $test = "1"; @@ -944,9 +1013,9 @@ ACEOF if (@decls) { - $test_code = join( "\n", @decls, $test_code ); + $test_code = join("\n", @decls, $test_code); } - $self->lang_build_program( $prologue, $test_code ); + $self->lang_build_program($prologue, $test_code); } =head2 push_includes @@ -959,10 +1028,10 @@ sub push_includes { - my ( $self, @includes ) = @_; + my ($self, @includes) = @_; ref $self or $self = $self->_get_instance(); - push( @{ $self->{extra_include_dirs} }, @includes ); + push(@{$self->{extra_include_dirs}}, @includes); return; } @@ -975,10 +1044,10 @@ sub push_preprocess_flags { - my ( $self, @cpp_flags ) = @_; + my ($self, @cpp_flags) = @_; ref $self or $self = $self->_get_instance(); - push( @{ $self->{extra_preprocess_flags} }, @cpp_flags ); + push(@{$self->{extra_preprocess_flags}}, @cpp_flags); return; } @@ -991,19 +1060,19 @@ sub push_compiler_flags { - my ( $self, @compiler_flags ) = @_; + my ($self, @compiler_flags) = @_; ref $self or $self = $self->_get_instance(); my $lang = $self->{lang}; - if ( scalar(@compiler_flags) && ( ref( $compiler_flags[-1] ) eq "HASH" ) ) + if (scalar(@compiler_flags) && (ref($compiler_flags[-1]) eq "HASH")) { my $lang_opt = pop(@compiler_flags); - defined( $lang_opt->{lang} ) or croak("Missing lang attribute in language options"); + defined($lang_opt->{lang}) or croak("Missing lang attribute in language options"); $lang = $lang_opt->{lang}; - defined( $self->{lang_supported}->{$lang} ) or croak("Unsupported language '$lang'"); + defined($self->{lang_supported}->{$lang}) or croak("Unsupported language '$lang'"); } - push( @{ $self->{extra_compile_flags}->{$lang} }, @compiler_flags ); + push(@{$self->{extra_compile_flags}->{$lang}}, @compiler_flags); return; } @@ -1016,10 +1085,10 @@ sub push_libraries { - my ( $self, @libs ) = @_; + my ($self, @libs) = @_; ref $self or $self = $self->_get_instance(); - push( @{ $self->{extra_libs} }, @libs ); + push(@{$self->{extra_libs}}, @libs); return; } @@ -1032,10 +1101,10 @@ sub push_library_paths { - my ( $self, @libdirs ) = @_; + my ($self, @libdirs) = @_; ref $self or $self = $self->_get_instance(); - push( @{ $self->{extra_lib_dirs} }, @libdirs ); + push(@{$self->{extra_lib_dirs}}, @libdirs); return; } @@ -1048,10 +1117,10 @@ sub push_link_flags { - my ( $self, @link_flags ) = @_; + my ($self, @link_flags) = @_; ref $self or $self = $self->_get_instance(); - push( @{ $self->{extra_link_flags} }, @link_flags ); + push(@{$self->{extra_link_flags}}, @link_flags); return; } @@ -1068,7 +1137,7 @@ sub compile_if_else { - my ( $self, $src ) = @_; + my ($self, $src) = @_; ref $self or $self = $self->_get_instance(); my $options = {}; @@ -1076,7 +1145,7 @@ my $builder = $self->_get_builder(); - my ( $fh, $filename ) = tempfile( + my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c', UNLINK => 0 @@ -1085,8 +1154,8 @@ print {$fh} $src; close $fh; - my ( $obj_file, $outbuf, $errbuf, $exception ); - ( $outbuf, $errbuf ) = capture + my ($obj_file, $outbuf, $errbuf, $exception); + ($outbuf, $errbuf) = capture { eval { $obj_file = $builder->compile( @@ -1103,14 +1172,14 @@ $obj_file and !-f $obj_file and undef $obj_file; unlink $obj_file if $obj_file; - if ( $exception || !$obj_file ) + if ($exception || !$obj_file) { - $self->_add_log_lines( "compile stage failed" . ( $exception ? " - " . $exception : "" ) ); + $self->_add_log_lines("compile stage failed" . ($exception ? " - " . $exception : "")); $errbuf and $self->_add_log_lines($errbuf); - $self->_add_log_lines( "failing program is:\n" . $src ); + $self->_add_log_lines("failing program is:\n" . $src); $outbuf - and $self->_add_log_lines( "stdout was :\n" . $outbuf ); + and $self->_add_log_lines("stdout was :\n" . $outbuf); $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" @@ -1138,14 +1207,14 @@ sub link_if_else { - my ( $self, $src ) = @_; + my ($self, $src) = @_; ref $self or $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my $builder = $self->_get_builder(); - my ( $fh, $filename ) = tempfile( + my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c', UNLINK => 0 @@ -1154,8 +1223,8 @@ print {$fh} $src; close $fh; - my ( $obj_file, $outbuf, $errbuf, $exception ); - ( $outbuf, $errbuf ) = capture + my ($obj_file, $outbuf, $errbuf, $exception); + ($outbuf, $errbuf) = capture { eval { $obj_file = $builder->compile( @@ -1170,14 +1239,14 @@ $obj_file and !-f $obj_file and undef $obj_file; - if ( $exception || !$obj_file ) + if ($exception || !$obj_file) { - $self->_add_log_lines( "compile stage failed" . ( $exception ? " - " . $exception : "" ) ); + $self->_add_log_lines("compile stage failed" . ($exception ? " - " . $exception : "")); $errbuf and $self->_add_log_lines($errbuf); - $self->_add_log_lines( "failing program is:\n" . $src ); + $self->_add_log_lines("failing program is:\n" . $src); $outbuf - and $self->_add_log_lines( "stdout was :\n" . $outbuf ); + and $self->_add_log_lines("stdout was :\n" . $outbuf); unlink $filename; unlink $obj_file if $obj_file; @@ -1190,7 +1259,7 @@ } my $exe_file; - ( $outbuf, $errbuf ) = capture + ($outbuf, $errbuf) = capture { eval { $exe_file = $builder->link_executable( @@ -1208,14 +1277,14 @@ unlink $obj_file if $obj_file; unlink $exe_file if $exe_file; - if ( $exception || !$exe_file ) + if ($exception || !$exe_file) { - $self->_add_log_lines( "link stage failed" . ( $exception ? " - " . $exception : "" ) ); + $self->_add_log_lines("link stage failed" . ($exception ? " - " . $exception : "")); $errbuf and $self->_add_log_lines($errbuf); - $self->_add_log_lines( "failing program is:\n" . $src ); + $self->_add_log_lines("failing program is:\n" . $src); $outbuf - and $self->_add_log_lines( "stdout was :\n" . $outbuf ); + and $self->_add_log_lines("stdout was :\n" . $outbuf); $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" @@ -1245,7 +1314,7 @@ sub check_cached { - my ( $self, $cache_name, $message, $check_sub ) = @_; + my ($self, $cache_name, $message, $check_sub) = @_; ref $self or $self = $self->_get_instance(); my $options = {}; scalar @_ > 4 and ref $_[-1] eq "HASH" and $options = pop @_; @@ -1257,10 +1326,10 @@ and $self->{cache}->{$cache_name} = $ENV{$cache_name}; my @cached_result; - defined( $self->{cache}->{$cache_name} ) and push @cached_result, "(cached)"; - defined( $self->{cache}->{$cache_name} ) or $self->{cache}->{$cache_name} = $check_sub->(); + defined($self->{cache}->{$cache_name}) and push @cached_result, "(cached)"; + defined($self->{cache}->{$cache_name}) or $self->{cache}->{$cache_name} = $check_sub->(); - $self->msg_result( @cached_result, $self->{cache}->{$cache_name} ); + $self->msg_result(@cached_result, $self->{cache}->{$cache_name}); $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" @@ -1283,7 +1352,7 @@ sub cache_val { - my ( $self, $cache_name ) = @_; + my ($self, $cache_name) = @_; ref $self or $self = $self->_get_instance(); defined $self->{cache}->{$cache_name} or return; $self->{cache}->{$cache_name}; @@ -1305,7 +1374,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1315,34 +1384,34 @@ sub check_decl { - my ( $self, $symbol ) = @_; + my ($self, $symbol) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; defined($symbol) or return croak("No symbol to check for"); ref($symbol) eq "" or return croak("No symbol to check for"); - ( my $sym_plain = $symbol ) =~ s/ *\(.*//; + (my $sym_plain = $symbol) =~ s/ *\(.*//; my $sym_call = $symbol; $sym_call =~ s/\(/((/; $sym_call =~ s/\)/) 0)/; $sym_call =~ s/,/) 0, (/g; - my $cache_name = $self->_cache_name( "decl", $self->{lang}, $symbol ); - my $check_sub = sub { + my $cache_name = $self->_cache_name("decl", $self->{lang}, $symbol); + my $check_sub = sub { my $body = <lang_build_program( $options->{prologue}, $body ); + my $conftest = $self->lang_build_program($options->{prologue}, $body); my $have_decl = $self->compile_if_else( $conftest, { - ( $options->{action_on_true} ? ( action_on_true => $options->{action_on_true} ) : () ), - ( $options->{action_on_false} ? ( action_on_false => $options->{action_on_false} ) : () ) + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); @@ -1354,8 +1423,8 @@ "whether $symbol is declared", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + ($options->{action_on_cache_true} ? (action_on_true => $options->{action_on_cache_true}) : ()), + ($options->{action_on_cache_false} ? (action_on_false => $options->{action_on_cache_false}) : ()) } ); } @@ -1365,13 +1434,13 @@ For each of the symbols (with optional function argument types for C++ overloads), run L. -Contrary to GNU autoconf, this method does not declare HAVE_DECL_symbol +Contrary to B, this method does not declare C macros for the resulting C, because it differs as C between compiling languages. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1384,7 +1453,7 @@ sub check_decls { - my ( $self, $symbols ) = @_; + my ($self, $symbols) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; @@ -1403,12 +1472,12 @@ %pass_options, ( $options->{action_on_symbol_true} && "CODE" eq ref $options->{action_on_symbol_true} - ? ( action_on_true => sub { $options->{action_on_symbol_true}->($symbol) } ) + ? (action_on_true => sub { $options->{action_on_symbol_true}->($symbol) }) : () ), ( $options->{action_on_symbol_false} && "CODE" eq ref $options->{action_on_symbol_false} - ? ( action_on_false => sub { $options->{action_on_symbol_false}->($symbol) } ) + ? (action_on_false => sub { $options->{action_on_symbol_false}->($symbol) }) : () ), } @@ -1454,20 +1523,20 @@ sub check_func { - my ( $self, $function ) = @_; + my ($self, $function) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; # Build the name of the cache variable. - my $cache_name = $self->_cache_name( 'func', $function ); + my $cache_name = $self->_cache_name('func', $function); # Wrap the actual check in a closure so that we can use check_cached. my $check_sub = sub { my $have_func = $self->link_if_else( - $self->lang_call( q{}, $function ), + $self->lang_call(q{}, $function), { - ( $options->{action_on_true} ? ( action_on_true => $options->{action_on_true} ) : () ), - ( $options->{action_on_false} ? ( action_on_false => $options->{action_on_false} ) : () ) + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); $have_func; @@ -1479,8 +1548,22 @@ "for $function", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _have_func_define_name($function), + $self->cache_val($cache_name), + "Defined when $function is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_func_define_name($function), undef, "Defined when $function is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -1504,7 +1587,7 @@ sub check_funcs { - my ( $self, $functions_ref ) = @_; + my ($self, $functions_ref) = @_; $self = $self->_get_instance(); my $options = {}; @@ -1518,16 +1601,12 @@ # generate new closures for the found and not-found functions that pass in # the relevant function name. my $have_funcs = 1; - for my $function ( @{$functions_ref} ) + for my $function (@{$functions_ref}) { - # Build the code reference to run when a function was found. This defines # a HAVE_FUNCTION symbol, plus runs the current $action-if-true if there is # one. $pass_options{action_on_true} = sub { - # XXX think about doing this always (move to check_func) - $self->define_var( _have_func_define_name($function), 1, "Defined when $function is available" ); - # Run the user-provided hook, if there is one. defined $options->{action_on_function_true} and ref $options->{action_on_function_true} eq "CODE" @@ -1538,7 +1617,7 @@ and ref $options->{action_on_function_false} eq "CODE" and $pass_options{action_on_false} = sub { $options->{action_on_function_false}->($function); }; - $have_funcs &= check_func( $self, $function, \%pass_options ); + $have_funcs &= check_func($self, $function, \%pass_options); } $have_funcs @@ -1554,6 +1633,78 @@ return $have_funcs; } +=head2 check_builtin( $builtin, \%options? ) + +This method actually tests whether I<$builtin> is a supported built-in +known by the compiler. Either, by giving us the type of the built-in or +by taking the value from C<__has_builtin>. This method caches its result +in the ac_cv_builtin_FUNCTION variable. + +If the very last parameter contains a hash reference, C references +to I or I are executed, respectively. +If any of I, I is defined, +both callbacks are passed to L as I or +I to C, respectively. + +Returns: True if the function was found, false otherwise + +=cut + +sub _have_builtin_define_name +{ + my $builtin = $_[0]; + my $have_name = "HAVE_BUILTIN_" . uc($builtin); + $have_name =~ tr/_A-Za-z0-9/_/c; + $have_name; +} + +sub check_builtin +{ + my ($self, $builtin) = @_; + $self = $self->_get_instance(); + my $options = {}; + scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; + + # Build the name of the cache variable. + my $cache_name = $self->_cache_name('builtin', $builtin); + # Wrap the actual check in a closure so that we can use check_cached. + my $check_sub = sub { + my $have_builtin = $self->link_if_else( + $self->lang_builtin(q{}, $builtin), + { + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) + } + ); + $have_builtin; + }; + + # Run the check and cache the results. + return $self->check_cached( + $cache_name, + "for builtin $builtin", + $check_sub, + { + action_on_true => sub { + $self->define_var( + _have_builtin_define_name($builtin), + $self->cache_val($cache_name), + "Defined when builtin $builtin is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_builtin_define_name($builtin), undef, "Defined when builtin $builtin is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, + } + ); +} + sub _have_type_define_name { my $type = $_[0]; @@ -1577,7 +1728,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1587,7 +1738,7 @@ sub check_type { - my ( $self, $type ) = @_; + my ($self, $type) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; @@ -1595,23 +1746,22 @@ defined($type) or return croak("No type to check for"); ref($type) eq "" or return croak("No type to check for"); - my $cache_name = $self->_cache_type_name( "type", $type ); - my $check_sub = sub { + my $cache_name = $self->_cache_type_name("type", $type); + my $check_sub = sub { my $body = <lang_build_program( $options->{prologue}, $body ); + my $conftest = $self->lang_build_program($options->{prologue}, $body); my $have_type = $self->compile_if_else( $conftest, { - ( $options->{action_on_true} ? ( action_on_true => $options->{action_on_true} ) : () ), - ( $options->{action_on_false} ? ( action_on_false => $options->{action_on_false} ) : () ) + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); - $self->define_var( _have_type_define_name($type), $have_type ? $have_type : undef, "defined when $type is available" ); $have_type; }; @@ -1620,8 +1770,19 @@ "for $type", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var(_have_type_define_name($type), $self->cache_val($cache_name), + "defined when $type is available"); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_type_define_name($type), undef, "defined when $type is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -1633,7 +1794,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1646,7 +1807,7 @@ sub check_types { - my ( $self, $types ) = @_; + my ($self, $types) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; @@ -1665,12 +1826,12 @@ %pass_options, ( $options->{action_on_type_true} && "CODE" eq ref $options->{action_on_type_true} - ? ( action_on_true => sub { $options->{action_on_type_true}->($type) } ) + ? (action_on_true => sub { $options->{action_on_type_true}->($type) }) : () ), ( $options->{action_on_type_false} && "CODE" eq ref $options->{action_on_type_false} - ? ( action_on_false => sub { $options->{action_on_type_false}->($type) } ) + ? (action_on_false => sub { $options->{action_on_type_false}->($type) }) : () ), } @@ -1692,25 +1853,25 @@ sub _compute_int_compile { - my ( $self, $expr, $prologue, @decls ) = @_; + my ($self, $expr, $prologue, @decls) = @_; $self = $self->_get_instance(); - my ( $body, $conftest, $compile_result ); + my ($body, $conftest, $compile_result); - my ( $low, $mid, $high ) = ( 0, 0, 0 ); - if ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) >= 0", @decls ) ) ) + my ($low, $mid, $high) = (0, 0, 0); + if ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) >= 0", @decls))) { $low = $mid = 0; while (1) { - if ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) <= $mid", @decls ) ) ) + if ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) <= $mid", @decls))) { $high = $mid; last; } $low = $mid + 1; # avoid overflow - if ( $low <= $mid ) + if ($low <= $mid) { $low = 0; last; @@ -1718,19 +1879,19 @@ $mid = $low * 2; } } - elsif ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) < 0", @decls ) ) ) + elsif ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) < 0", @decls))) { $high = $mid = -1; while (1) { - if ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) >= $mid", @decls ) ) ) + if ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) >= $mid", @decls))) { $low = $mid; last; } $high = $mid - 1; # avoid overflow - if ( $mid < $high ) + if ($mid < $high) { $high = 0; last; @@ -1740,14 +1901,14 @@ } # perform binary search between $low and $high - while ( $low <= $high ) + while ($low <= $high) { - $mid = int( ( $high - $low ) / 2 + $low ); - if ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) < $mid", @decls ) ) ) + $mid = int(($high - $low) / 2 + $low); + if ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) < $mid", @decls))) { $high = $mid - 1; } - elsif ( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) > $mid", @decls ) ) ) + elsif ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) > $mid", @decls))) { $low = $mid + 1; } @@ -1769,7 +1930,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1777,16 +1938,25 @@ =cut +sub _expr_value_define_name +{ + my $expr = $_[0]; + my $have_name = "EXPR_" . uc($expr); + $have_name =~ tr/*/P/; + $have_name =~ tr/_A-Za-z0-9/_/c; + $have_name; +} + sub compute_int { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $expr, @decls ) = @_; + my ($self, $expr, @decls) = @_; $self = $self->_get_instance(); - my $cache_name = $self->_cache_type_name( "compute_int", $self->{lang}, $expr ); - my $check_sub = sub { - my $val = $self->_compute_int_compile( $expr, $options->{prologue}, @decls ); + my $cache_name = $self->_cache_type_name("compute_int", $self->{lang}, $expr); + my $check_sub = sub { + my $val = $self->_compute_int_compile($expr, $options->{prologue}, @decls); defined $val and $options->{action_on_true} @@ -1806,28 +1976,33 @@ "for compute result of ($expr)", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _expr_value_define_name($expr), + $self->cache_val($cache_name), + "defined when ($expr) could computed" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_expr_value_define_name($expr), undef, "defined when ($expr) could computed"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } -sub _sizeof_type_define_name -{ - my $type = $_[0]; - my $have_name = "SIZEOF_" . uc($type); - $have_name =~ tr/*/P/; - $have_name =~ tr/_A-Za-z0-9/_/c; - $have_name; -} - =head2 check_sizeof_type( $type, \%options? ) Checks for the size of the specified type by compiling and define C using the determined size. In opposition to GNU AutoConf, this method can determine size of structure -members, eg. +members, e.g. $ac->check_sizeof_type( "SV.sv_refcnt", { prologue => $include_perl } ); # or @@ -1837,7 +2012,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1845,32 +2020,36 @@ =cut +sub _sizeof_type_define_name +{ + my $type = $_[0]; + my $have_name = "SIZEOF_" . uc($type); + $have_name =~ tr/*/P/; + $have_name =~ tr/_A-Za-z0-9/_/c; + $have_name; +} + sub check_sizeof_type { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $type ) = @_; + my ($self, $type) = @_; $self = $self->_get_instance(); defined($type) or return croak("No type to check for"); ref($type) eq "" or return croak("No type to check for"); - my $cache_name = $self->_cache_type_name( "sizeof", $self->{lang}, $type ); - my $check_sub = sub { + my $cache_name = $self->_cache_type_name("sizeof", $self->{lang}, $type); + my $check_sub = sub { my @decls; - if ( $type =~ m/^([^.]+)\.([^.]+)$/ ) + if ($type =~ m/^([^.]+)\.([^.]+)$/) { my $struct = $1; $type = "_ac_test_aggr.$2"; my $decl = "static $struct _ac_test_aggr;"; - push( @decls, $decl ); + push(@decls, $decl); } - my $typesize = $self->_compute_int_compile( "sizeof($type)", $options->{prologue}, @decls ); - $self->define_var( - _sizeof_type_define_name($type), - $typesize ? $typesize : undef, - "defined when sizeof($type) is available" - ); + my $typesize = $self->_compute_int_compile("sizeof($type)", $options->{prologue}, @decls); $typesize and $options->{action_on_true} @@ -1890,8 +2069,22 @@ "for size of $type", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _sizeof_type_define_name($type), + $self->cache_val($cache_name), + "defined when sizeof($type) is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_sizeof_type_define_name($type), undef, "defined when sizeof($type) is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -1906,7 +2099,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1921,7 +2114,7 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $types ) = @_; + my ($self, $types) = @_; $self = $self->_get_instance(); my %pass_options; @@ -1939,12 +2132,12 @@ %pass_options, ( $options->{action_on_size_true} && "CODE" eq ref $options->{action_on_size_true} - ? ( action_on_true => sub { $options->{action_on_size_true}->($type) } ) + ? (action_on_true => sub { $options->{action_on_size_true}->($type) }) : () ), ( $options->{action_on_size_false} && "CODE" eq ref $options->{action_on_size_false} - ? ( action_on_false => sub { $options->{action_on_size_false}->($type) } ) + ? (action_on_false => sub { $options->{action_on_size_false}->($type) }) : () ), } @@ -1986,7 +2179,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -1998,40 +2191,35 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $type ) = @_; + my ($self, $type) = @_; $self = $self->_get_instance(); defined($type) or return croak("No type to check for"); ref($type) eq "" or return croak("No type to check for"); - my $cache_name = $self->_cache_type_name( "alignof", $self->{lang}, $type ); - my $check_sub = sub { + my $cache_name = $self->_cache_type_name("alignof", $self->{lang}, $type); + my $check_sub = sub { my @decls = ( "#ifndef offsetof", "# ifdef __ICC", "# define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))", - "# else", "# define offsetof(type,memb) ((size_t)&((type*)0)->memb)", + "# else", "# define offsetof(type,memb) ((size_t)&((type*)0)->memb)", "# endif", "#endif" ); - my ( $struct, $memb ); - if ( $type =~ m/^([^.]+)\.([^.]+)$/ ) + my ($struct, $memb); + if ($type =~ m/^([^.]+)\.([^.]+)$/) { $struct = $1; $memb = $2; } else { - push( @decls, "typedef struct { char x; $type y; } ac__type_alignof_;" ); + push(@decls, "typedef struct { char x; $type y; } ac__type_alignof_;"); $struct = "ac__type_alignof_"; $memb = "y"; } - my $typealign = $self->_compute_int_compile( "offsetof($struct, $memb)", $options->{prologue}, @decls ); - $self->define_var( - _alignof_type_define_name($type), - $typealign ? $typealign : undef, - "defined when alignof($type) is available" - ); + my $typealign = $self->_compute_int_compile("offsetof($struct, $memb)", $options->{prologue}, @decls); $typealign and $options->{action_on_true} @@ -2051,8 +2239,22 @@ "for align of $type", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _alignof_type_define_name($type), + $self->cache_val($cache_name), + "defined when alignof($type) is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_alignof_type_define_name($type), undef, "defined when alignof($type) is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -2067,7 +2269,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -2082,7 +2284,7 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $types ) = @_; + my ($self, $types) = @_; $self = $self->_get_instance(); my %pass_options; @@ -2100,12 +2302,12 @@ %pass_options, ( $options->{action_on_align_true} && "CODE" eq ref $options->{action_on_align_true} - ? ( action_on_true => sub { $options->{action_on_align_true}->($type) } ) + ? (action_on_true => sub { $options->{action_on_align_true}->($type) }) : () ), ( $options->{action_on_align_false} && "CODE" eq ref $options->{action_on_align_false} - ? ( action_on_false => sub { $options->{action_on_align_false}->($type) } ) + ? (action_on_false => sub { $options->{action_on_align_false}->($type) }) : () ), } @@ -2159,7 +2361,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -2171,7 +2373,7 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $member ) = @_; + my ($self, $member) = @_; $self = $self->_get_instance(); defined($member) or return croak("No type to check for"); ref($member) eq "" or return croak("No type to check for"); @@ -2188,7 +2390,7 @@ if( check_aggr.$member ) return 0; ACEOF - my $conftest = $self->lang_build_program( $options->{prologue}, $body ); + my $conftest = $self->lang_build_program($options->{prologue}, $body); my $have_member = $self->compile_if_else($conftest); unless ($have_member) @@ -2198,7 +2400,7 @@ if( sizeof check_aggr.$member ) return 0; ACEOF - $conftest = $self->lang_build_program( $options->{prologue}, $body ); + $conftest = $self->lang_build_program($options->{prologue}, $body); $have_member = $self->compile_if_else($conftest); } @@ -2212,11 +2414,6 @@ and $options->{action_on_false}->() unless $have_member; - $self->define_var( - _have_member_define_name("$type.$member"), - $have_member ? $have_member : undef, - "defined when $type.$member is available" - ); $have_member; }; @@ -2225,8 +2422,22 @@ "for $type.$member", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _have_member_define_name("$type.$member"), + $self->cache_val($cache_name), + "defined when $type.$member is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_member_define_name("$type.$member"), undef, "defined when $type.$member is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -2239,7 +2450,7 @@ If the very last parameter contains a hash reference, C references to I or I are executed, respectively. -When a I exists in the optional hash at end, it will be favoured +When a I exists in the optional hash at end, it will be favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to @@ -2254,7 +2465,7 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $members ) = @_; + my ($self, $members) = @_; $self = $self->_get_instance(); my %pass_options; @@ -2272,12 +2483,12 @@ %pass_options, ( $options->{action_on_member_true} && "CODE" eq ref $options->{action_on_member_true} - ? ( action_on_true => sub { $options->{action_on_member_true}->($member) } ) + ? (action_on_true => sub { $options->{action_on_member_true}->($member) }) : () ), ( $options->{action_on_member_false} && "CODE" eq ref $options->{action_on_member_false} - ? ( action_on_false => sub { $options->{action_on_member_false}->($member) } ) + ? (action_on_false => sub { $options->{action_on_member_false}->($member) }) : () ), } @@ -2310,14 +2521,14 @@ { my $options = {}; scalar @_ > 4 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $header, $prologue, $body ) = @_; + my ($self, $header, $prologue, $body) = @_; $prologue .= <<"_ACEOF"; #include <$header> _ACEOF - my $conftest = $self->lang_build_program( $prologue, $body ); + my $conftest = $self->lang_build_program($prologue, $body); - $self->compile_if_else( $conftest, $options ); + $self->compile_if_else($conftest, $options); } =head2 check_header( $header, \%options? ) @@ -2348,7 +2559,7 @@ { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $header ) = @_; + my ($self, $header) = @_; $self = $self->_get_instance(); defined($header) or return croak("No type to check for"); ref($header) eq "" or return croak("No type to check for"); @@ -2363,15 +2574,10 @@ $prologue, "", { - ( $options->{action_on_true} ? ( action_on_true => $options->{action_on_true} ) : () ), - ( $options->{action_on_false} ? ( action_on_false => $options->{action_on_false} ) : () ) + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); - $self->define_var( - _have_header_define_name($header), - $have_header ? $have_header : undef, - "defined when $header is available" - ); $have_header; }; @@ -2381,8 +2587,22 @@ "for $header", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _have_header_define_name($header), + $self->cache_val($cache_name), + "defined when $header is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_header_define_name($header), undef, "defined when $header is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } @@ -2402,7 +2622,7 @@ my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); - $self->check_header( $_, $options ) and return $_ for (@_); + $self->check_header($_, $options) and return $_ for (@_); return; } @@ -2443,12 +2663,12 @@ %pass_options, ( $options->{action_on_header_true} && "CODE" eq ref $options->{action_on_header_true} - ? ( action_on_true => sub { $options->{action_on_header_true}->($header) } ) + ? (action_on_true => sub { $options->{action_on_header_true}->($header) }) : () ), ( $options->{action_on_header_false} && "CODE" eq ref $options->{action_on_header_false} - ? ( action_on_false => sub { $options->{action_on_header_false}->($header) } ) + ? (action_on_false => sub { $options->{action_on_header_false}->($header) }) : () ), } @@ -2491,8 +2711,8 @@ # XXX for C++ the map should look like "c${_}" ... my @c_ansi_c_headers = map { "${_}.h" } @ansi_c_headers; - my $rc = $self->check_all_headers( @c_ansi_c_headers, $options ); - $rc and $self->define_var( "STDC_HEADERS", 1, "Define to 1 if you have the ANSI C header files." ); + my $rc = $self->check_all_headers(@c_ansi_c_headers, $options); + $rc and $self->define_var("STDC_HEADERS", 1, "Define to 1 if you have the ANSI C header files."); $rc; } @@ -2511,7 +2731,7 @@ scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); $self->check_stdc_headers($options) - and $self->check_all_headers( qw(sys/types.h sys/stat.h memory.h strings.h inttypes.h stdint.h unistd.h), $options ); + and $self->check_all_headers(qw(sys/types.h sys/stat.h memory.h strings.h inttypes.h stdint.h unistd.h), $options); } =head2 check_dirent_header @@ -2519,10 +2739,10 @@ Check for the following header files. For the first one that is found and defines 'DIR', define the listed C preprocessor macro: - dirent.h HAVE_DIRENT_H - sys/ndir.h HAVE_SYS_NDIR_H - sys/dir.h HAVE_SYS_DIR_H - ndir.h HAVE_NDIR_H + dirent.h HAVE_DIRENT_H + sys/ndir.h HAVE_SYS_NDIR_H + sys/dir.h HAVE_SYS_DIR_H + ndir.h HAVE_NDIR_H The directory-library declarations in your source code should look something like the following: @@ -2550,8 +2770,10 @@ of a directory entry name by passing a pointer to a C to the C macro. +For the found header, the macro HAVE_DIRENT_IN_${header} is defined. + This method might be obsolescent, as all current systems with directory -libraries have C<dirent.hE>>. Programs supporting only newer OS +libraries have C<< Edirent.hE >>. Programs supporting only newer OS might not need to use this method. If the very last parameter contains a hash reference, C references @@ -2566,6 +2788,14 @@ =cut +sub _have_dirent_header_define_name +{ + my $header = $_[0]; + my $have_name = "HAVE_DIRENT_IN_" . uc($header); + $have_name =~ tr/_A-Za-z0-9/_/c; + return $have_name; +} + sub check_dirent_header { my $options = {}; @@ -2575,61 +2805,73 @@ my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; - my $cache_name = $self->_cache_name("header_dirent"); - my $check_sub = sub { - my $have_dirent; - foreach my $header (qw(dirent.h sys/ndir.h sys/dir.h ndir.h)) + my $have_dirent; + foreach my $header (qw(dirent.h sys/ndir.h sys/dir.h ndir.h)) + { + if ($self->check_header($header)) { - $have_dirent = $self->_check_header( - $header, - "#include \n", - "if ((DIR *) 0) { return 0; }", + my $cache_name = $self->_cache_name("dirent", $header); + my $check_sub = sub { + my $have_dirent; + $have_dirent = $self->_check_header( + $header, + "#include \n", + "if ((DIR *) 0) { return 0; }", + { + %pass_options, + ( + $options->{action_on_header_true} && "CODE" eq ref $options->{action_on_header_true} + ? (action_on_true => sub { $options->{action_on_header_true}->($header) }) + : () + ), + ( + $options->{action_on_header_false} && "CODE" eq ref $options->{action_on_header_false} + ? (action_on_false => sub { $options->{action_on_header_false}->($header) }) + : () + ), + } + ); + }; + + $have_dirent = $self->check_cached( + $cache_name, + "for header defining DIR *", + $check_sub, { - %pass_options, - ( - $options->{action_on_header_true} && "CODE" eq ref $options->{action_on_header_true} - ? ( action_on_true => sub { $options->{action_on_header_true}->($header) } ) - : () - ), - ( - $options->{action_on_header_false} && "CODE" eq ref $options->{action_on_header_false} - ? ( action_on_false => sub { $options->{action_on_header_false}->($header) } ) - : () - ), + action_on_true => sub { + $self->define_var( + _have_dirent_header_define_name($header), + $self->cache_val($cache_name), + "defined when $header is available" + ); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_dirent_header_define_name($header), undef, "defined when $header is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); - $self->define_var( - _have_header_define_name($header), - $have_dirent ? $have_dirent : undef, - "defined when $header is available" - ); + $have_dirent and $have_dirent = $header and last; } + } - $have_dirent - and $options->{action_on_true} - and ref $options->{action_on_true} eq "CODE" - and $options->{action_on_true}->(); - - $options->{action_on_false} - and ref $options->{action_on_false} eq "CODE" - and !$have_dirent - and $options->{action_on_false}->(); - - $have_dirent; - }; + $have_dirent + and $options->{action_on_true} + and ref $options->{action_on_true} eq "CODE" + and $options->{action_on_true}->(); - my $dirent_header = $self->check_cached( - $cache_name, - "for header defining DIR *", - $check_sub, - { - ( $options->{action_on_cache_true} ? ( action_on__true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on__false => $options->{action_on_cache_false} ) : () ), - } - ); + $options->{action_on_false} + and ref $options->{action_on_false} eq "CODE" + and !$have_dirent + and $options->{action_on_false}->(); - $dirent_header; + $have_dirent; } =head2 _check_perlapi_program @@ -2649,7 +2891,7 @@ SV *foo = newSVpv("Perl rocks", 11); rc = SvCUR(foo); EOB - $self->lang_build_program( $includes, $perl_check_body ); + $self->lang_build_program($includes, $perl_check_body); } =head2 _check_compile_perlapi @@ -2679,7 +2921,7 @@ my $self = shift->_get_instance; my $cache_name = $self->_cache_name(qw(compile perlapi)); - $self->check_cached( $cache_name, "whether perlapi is accessible", sub { $self->_check_compile_perlapi } ); + $self->check_cached($cache_name, "whether perlapi is accessible", sub { $self->_check_compile_perlapi }); } =head2 check_compile_perlapi_or_die @@ -2754,21 +2996,21 @@ my $self = shift; my $conftest = $self->_check_perlapi_program(); - my @save_libs = @{ $self->{extra_libs} }; - my @save_extra_link_flags = @{ $self->{extra_link_flags} }; + my @save_libs = @{$self->{extra_libs}}; + my @save_extra_link_flags = @{$self->{extra_link_flags}}; my $libperl = $Config{libperl}; $libperl =~ s/^lib//; $libperl =~ s/\.[^\.]*$//; - push @{ $self->{extra_link_flags} }, "-L" . File::Spec->catdir( $Config{installarchlib}, "CORE" ); - push @{ $self->{extra_libs} }, "$libperl"; - if ( $Config{perllibs} ) + push @{$self->{extra_link_flags}}, "-L" . File::Spec->catdir($Config{installarchlib}, "CORE"); + push @{$self->{extra_libs}}, "$libperl"; + if ($Config{perllibs}) { - foreach my $perllib ( split( " ", $Config{perllibs} ) ) + foreach my $perllib (split(" ", $Config{perllibs})) { - $perllib =~ m/^\-l(\w+)$/ and push @{ $self->{extra_libs} }, "$1" and next; - push @{ $self->{extra_link_flags} }, $perllib; + $perllib =~ m/^\-l(\w+)$/ and push @{$self->{extra_libs}}, "$1" and next; + push @{$self->{extra_link_flags}}, $perllib; } } @@ -2793,7 +3035,7 @@ my $self = shift->_get_instance; my $cache_name = $self->_cache_name(qw(link perlapi)); - $self->check_cached( $cache_name, "whether perlapi is linkable", sub { $self->_check_link_perlapi } ); + $self->check_cached($cache_name, "whether perlapi is linkable", sub { $self->_check_link_perlapi }); } sub _have_lib_define_name @@ -2844,34 +3086,29 @@ my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); - my ( $lib, $func, @other_libs ) = @_; + my ($lib, $func, @other_libs) = @_; return 0 unless $lib and $func; scalar(@other_libs) == 1 - and ref( $other_libs[0] ) eq "ARRAY" - and @other_libs = @{ $other_libs[0] }; + and ref($other_libs[0]) eq "ARRAY" + and @other_libs = @{$other_libs[0]}; - my $cache_name = $self->_cache_name( "lib", $lib, $func ); - my $check_sub = sub { - my $conftest = $self->lang_call( "", $func ); + my $cache_name = $self->_cache_name("lib", $lib, $func); + my $check_sub = sub { + my $conftest = $self->lang_call("", $func); - my @save_libs = @{ $self->{extra_libs} }; - push( @{ $self->{extra_libs} }, $lib, @other_libs ); + my @save_libs = @{$self->{extra_libs}}; + push(@{$self->{extra_libs}}, $lib, @other_libs); my $have_lib = $self->link_if_else( $conftest, { - ( $options->{action_on_true} ? ( action_on_true => $options->{action_on_true} ) : () ), - ( $options->{action_on_false} ? ( action_on_false => $options->{action_on_false} ) : () ) + ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), + ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); $self->{extra_libs} = [@save_libs]; - $have_lib - and $self->define_var( _have_lib_define_name($lib), $have_lib, "defined when library $lib is available" ) - and push( @{ $self->{extra_libs} }, $lib, @other_libs ); - $have_lib - or $self->define_var( _have_lib_define_name($lib), undef, "defined when library $lib is available" ); $have_lib; }; @@ -2880,13 +3117,36 @@ "for $func in -l$lib", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->define_var( + _have_lib_define_name($lib), + $self->cache_val($cache_name), + "defined when library $lib is available" + ); + push(@{$self->{extra_libs}}, $lib, @other_libs); + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + action_on_false => sub { + $self->define_var(_have_lib_define_name($lib), undef, "defined when library $lib is available"); + $options->{action_on_cache_false} + and ref $options->{action_on_cache_false} eq "CODE" + and $options->{action_on_cache_false}->(); + }, } ); } -=head2 search_libs( function, search-libs, @other-libs?, \%options? ) +=head2 search_libs( function, search-libs, @other-libs?, @extra_link_flags?, \%options? ) + + Config::AutoConf->search_libs("gethostent", "nsl", [qw(socket net)], { + action_on_true => sub { ... } + }); + Config::AutoConf->search_libs("log4cplus_initialize", ["log4cplus"], + [[qw(stdc++)], [qw(stdc++ unwind)]], + [qw(-pthread -thread)] + ); Search for a library defining function if it's not already available. This equates to calling @@ -2902,9 +3162,10 @@ If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as -the I argument: e.g., C<[qw(Xt X11)]>. Otherwise, this -method fails to detect that function is present, because linking the -test program always fails with unresolved symbols. +the I argument: e.g., C<[qw(Xt X11)]> or C<[qw(intl), +qw(intl iconv)]>. Otherwise, this method fails to detect that function +is present, because linking the test program always fails with unresolved +symbols. The result of this test is cached in the ac_cv_search_function variable as "none required" if function is already available, as C<0> if no @@ -2927,48 +3188,71 @@ my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); - my ( $func, $libs, @other_libs ) = @_; + my ($func, $libs, @other_libs, @other_link_flags) = @_; - ( defined($libs) and "ARRAY" eq ref($libs) and scalar( @{$libs} ) > 0 ) + (defined($libs) and "ARRAY" eq ref($libs) and scalar(@{$libs}) > 0) or return 0; # XXX would prefer croak return 0 unless $func; scalar(@other_libs) == 1 - and ref( $other_libs[0] ) eq "ARRAY" - and @other_libs = @{ $other_libs[0] }; + and ref($other_libs[0]) eq "ARRAY" + and @other_libs = @{$other_libs[0]}; - my $cache_name = $self->_cache_name( "search", $func ); - my $check_sub = sub { - my $conftest = $self->lang_call( "", $func ); + scalar(@other_link_flags) == 1 + and ref($other_link_flags[0]) eq "ARRAY" + and @other_link_flags = @{$other_link_flags[0]}; - my @save_libs = @{ $self->{extra_libs} }; - my $have_lib = 0; - foreach my $libstest ( undef, @$libs ) - { - # XXX would local work on array refs? can we omit @save_libs? - $self->{extra_libs} = [@save_libs]; - defined($libstest) and unshift( @{ $self->{extra_libs} }, $libstest, @other_libs ); + my $cache_name = $self->_cache_name("search", $func); + my $check_sub = sub { + my $conftest = $self->lang_call("", $func); + + my @save_libs = @{$self->{extra_libs}}; + my @save_extra = @{$self->{extra_link_flags}}; + my $have_lib = 0; + + my $if_else_sub = sub { + my ($libstest, @other) = @_; + defined($libstest) and unshift(@{$self->{extra_libs}}, $libstest, @other); $self->link_if_else( $conftest, { ( $options->{action_on_lib_true} && "CODE" eq ref $options->{action_on_lib_true} - ? ( action_on_true => sub { $options->{action_on_lib_true}->( $libstest, @other_libs, @_ ) } ) + ? (action_on_true => sub { $options->{action_on_lib_true}->($libstest, @other, @_) }) : () ), ( $options->{action_on_lib_false} && "CODE" eq ref $options->{action_on_lib_false} - ? ( action_on_false => sub { $options->{action_on_lib_false}->( $libstest, @other_libs, @_ ) } ) + ? (action_on_false => sub { $options->{action_on_lib_false}->($libstest, @other, @_) }) : () ), } - ) - and ( $have_lib = defined($libstest) ? $libstest : "none required" ) - and last; + ) and ($have_lib = defined($libstest) ? $libstest : "none required"); + }; + + LIBTEST: + foreach my $libstest (undef, @$libs) + { + foreach my $linkextra (undef, @other_link_flags) + { + # XXX would local work on array refs? can we omit @save_libs? + $self->{extra_libs} = [@save_libs]; + $self->{extra_link_flags} = [@save_extra]; + if (defined $libstest and scalar(@other_libs) > 1 and ref($other_libs[0]) eq "ARRAY") + { + foreach my $ol (@other_libs) + { + $if_else_sub->($libstest, @{$ol}) and last LIBTEST; + } + } + else + { + $if_else_sub->($libstest, @other_libs) and last LIBTEST; + } + } } - $self->{extra_libs} = [@save_libs]; - $have_lib eq "none required" or unshift( @{ $self->{extra_libs} }, $have_lib ); + $self->{extra_libs} = [@save_libs]; $have_lib and $options->{action_on_true} @@ -2988,8 +3272,15 @@ "for library containing $func", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + action_on_true => sub { + $self->cache_val($cache_name) eq "none required" + or unshift(@{$self->{extra_libs}}, $self->cache_val($cache_name)); + + $options->{action_on_cache_true} + and ref $options->{action_on_cache_true} eq "CODE" + and $options->{action_on_cache_true}->(); + }, + ($options->{action_on_cache_false} ? (action_on_false => $options->{action_on_cache_false}) : ()) } ); } @@ -3053,22 +3344,22 @@ %pass_options, ( $options->{action_on_func_true} && "CODE" eq ref $options->{action_on_func_true} - ? ( action_on_true => sub { $options->{action_on_func_true}->( $func, @_ ) } ) + ? (action_on_true => sub { $options->{action_on_func_true}->($func, @_) }) : () ), ( $options->{action_on_func_false} && "CODE" eq ref $options->{action_on_func_false} - ? ( action_on_false => sub { $options->{action_on_func_false}->( $func, @_ ) } ) + ? (action_on_false => sub { $options->{action_on_func_false}->($func, @_) }) : () ), ( $options->{action_on_func_lib_true} && "CODE" eq ref $options->{action_on_func_lib_true} - ? ( action_on_lib_true => sub { $options->{action_on_func_lib_true}->( $func, @_ ) } ) + ? (action_on_lib_true => sub { $options->{action_on_func_lib_true}->($func, @_) }) : () ), ( $options->{action_on_func_lib_false} && "CODE" eq ref $options->{action_on_func_lib_false} - ? ( action_on_lib_false => sub { $options->{action_on_func_lib_false}->( $func, @_ ) } ) + ? (action_on_lib_false => sub { $options->{action_on_func_lib_false}->($func, @_) }) : () ), }, @@ -3093,12 +3384,42 @@ =head2 pkg_config_package_flags($package, \%options?) -Search for pkg-config flags for package as specified. The flags which are -extracted are C<--cflags> and C<--libs>. The extracted flags are appended -to the global C and C, respectively. + use Config::AutoConf + + my $c = Config::AutoConf->new; + $c->pkg_config_package_flags('log4cplus'); + WriteMakefile( + ... + INC => $c->_get_extra_compiler_flags, + LIBS => $c->_get_extra_linker_flags, + ); -Call it with the package you're looking for and optional callback whether -found or not. +Search for C flags for package as specified. The flags which are +extracted are C<--cflags> and C<--libs>. The extracted flags are appended +to the global C, C or C, +respectively. Distinguishing between C and C +is essential to avoid conflicts with L +and family. In case, no I matching given criteria +could be found, return a C value (C<0>). + +The C flags are taken from I +C<< ${package}_CFLAGS >> or C<< ${package}_LIBS >> when defined, respectively. +It will be a nice touch to document the particular environment variables +for your build procedure - as for above example it should be + + $ env log4cplus_CFLAGS="-I/opt/coolapp/include" \ + log4cplus_LIBS="-L/opt/coolapp/lib -Wl,-R/opt/coolapp/lib -llog4cplus" \ + perl Makefile.PL + +Call C with the package you're looking for and +optional callback whether found or not. + +To support stage compiling properly (C vs. library file location), +the internal representation is a moving target. Do not use the result +directly - the getters L<_get_extra_compiler_flags|/_get_extra_compiler_flags> +and L<_get_extra_linker_flags|/_get_extra_linker_flags> are strongly +encouraged. In case this is not possible, please open a ticket to get +informed on invasive changes. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. @@ -3114,49 +3435,60 @@ { defined $_pkg_config_prog or croak("pkg_config_prog required"); my @pkg_config_args = @_; - my ( $stdout, $stderr, $exit ) = - capture { system( $_pkg_config_prog, @pkg_config_args ); }; + my ($stdout, $stderr, $exit) = + capture { system($_pkg_config_prog, @pkg_config_args); }; chomp $stdout; 0 == $exit and return $stdout; - return; + return $exit; } sub pkg_config_package_flags { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; - my ( $self, $package ) = @_; + my ($self, $package) = @_; $self = $self->_get_instance(); - ( my $pkgpfx = $package ) =~ s/^(\w+).*?$/$1/; - my $cache_name = $self->_cache_name( "pkg", $pkgpfx ); + (my $pkgpfx = $package) =~ s/^(\w+).*?$/$1/; + my $cache_name = $self->_cache_name("pkg", $pkgpfx); + defined $_pkg_config_prog or $_pkg_config_prog = $self->{cache}->{$self->_cache_name("prog", "PKG_CONFIG")}; defined $_pkg_config_prog or $_pkg_config_prog = $self->check_prog_pkg_config; my $check_sub = sub { - my ( @pkg_cflags, @pkg_libs ); + my (@pkg_cflags, @pkg_libs); + + (my $ENV_CFLAGS = $package) =~ s/^(\w+).*?$/$1_CFLAGS/; + (my $ENV_LIBS = $package) =~ s/^(\w+).*?$/$1_LIBS/; + + my $pkg_exists = 0 + ( + defined $ENV{$ENV_CFLAGS} + or defined $ENV{$ENV_LIBS} + or _pkg_config_flag($package, "--exists") eq "" + ); + looks_like_number($pkg_exists) and $pkg_exists == 0 and return 0; - ( my $ENV_CFLAGS = $package ) =~ s/^(\w+).*?$/$1_CFLAGS/; my $CFLAGS = defined $ENV{$ENV_CFLAGS} ? $ENV{$ENV_CFLAGS} - : _pkg_config_flag( $package, "--cflags" ); - $CFLAGS and @pkg_cflags = ( + : _pkg_config_flag($package, "--cflags"); + $CFLAGS and not looks_like_number($CFLAGS) and @pkg_cflags = ( map { $_ =~ s/^\s+//; $_ =~ s/\s+$//; Text::ParseWords::shellwords $_; } - split( m/\n/, $CFLAGS ) - ) and push @{ $self->{extra_preprocess_flags} }, @pkg_cflags; + split(m/\n/, $CFLAGS) + ) and push @{$self->{extra_preprocess_flags}}, @pkg_cflags; - ( my $ENV_LIBS = $package ) =~ s/^(\w+).*?$/$1_LIBS/; # do not separate between libs and extra (for now) - they come with -l prepended my $LIBS = defined $ENV{$ENV_LIBS} ? $ENV{$ENV_LIBS} - : _pkg_config_flag( $package, "--libs" ); - $LIBS and @pkg_libs = ( + : _pkg_config_flag($package, "--libs"); + $LIBS and not looks_like_number($LIBS) and @pkg_libs = ( map { $_ =~ s/^\s+//; $_ =~ s/\s+$//; Text::ParseWords::shellwords $_; } - split( m/\n/, $LIBS ) - ) and push @{ $self->{extra_link_flags} }, @pkg_libs; + split(m/\n/, $LIBS) + ); + @pkg_libs and push @{$self->{extra_link_flags}}, grep { $_ !~ m/^-l/ } @pkg_libs; + @pkg_libs and push @{$self->{extra_libs}}, map { (my $l = $_) =~ s/^-l//; $l } grep { $_ =~ m/^-l/ } @pkg_libs; - my $pkg_config_flags = join( " ", @pkg_cflags, @pkg_libs ); + my $pkg_config_flags = join(" ", @pkg_cflags, @pkg_libs); $pkg_config_flags and $options->{action_on_true} @@ -3176,8 +3508,8 @@ "for pkg-config package of $package", $check_sub, { - ( $options->{action_on_cache_true} ? ( action_on_true => $options->{action_on_cache_true} ) : () ), - ( $options->{action_on_cache_false} ? ( action_on_false => $options->{action_on_cache_false} ) : () ) + ($options->{action_on_cache_true} ? (action_on_true => $options->{action_on_cache_true}) : ()), + ($options->{action_on_cache_false} ? (action_on_false => $options->{action_on_cache_false}) : ()) } ); } @@ -3197,7 +3529,7 @@ defined $ENV{PERL_MM_OPT} and my @env_args = split " ", $ENV{PERL_MM_OPT}; - foreach my $arg ( @{ $self->{_argv} }, @env_args ) + foreach my $arg (@{$self->{_argv}}, @env_args) { $arg =~ m/^PUREPERL_ONLY=(.*)$/ and return int($1); } @@ -3218,7 +3550,7 @@ defined $ENV{PERL_MB_OPT} and my @env_args = split " ", $ENV{PERL_MB_OPT}; - foreach my $arg ( @{ $self->{_argv} }, @env_args ) + foreach my $arg (@{$self->{_argv}}, @env_args) { $arg eq "--pureperl-only" and return 1; } @@ -3257,7 +3589,7 @@ { my $self = shift->_get_instance; my $cache_name = $self->_cache_name(qw(pureperl required)); - $self->check_cached( $cache_name, "whether pureperl is required", sub { $self->_check_pureperl_required } ); + $self->check_cached($cache_name, "whether pureperl is required", sub { $self->_check_pureperl_required }); } =head2 check_produce_xs_build @@ -3296,10 +3628,10 @@ my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance; - $self->check_pureperl_required() and return _on_return_callback_helper( 0, $options, "action_on_false" ); - eval { $self->check_valid_compilers( $_[0] || [qw(C)] ) } - or return _on_return_callback_helper( 0, $options, "action_on_false" ); - # XXX necessary check for $Config{useshrlib}? (need to dicuss with eg. TuX, 99% likely return 0) + $self->check_pureperl_required() and return _on_return_callback_helper(0, $options, "action_on_false"); + eval { $self->check_valid_compilers($_[0] || [qw(C)]) } + or return _on_return_callback_helper(0, $options, "action_on_false"); + # XXX necessary check for $Config{useshrlib}? (need to dicuss with e.g. TuX, 99% likely return 0) $self->check_compile_perlapi_or_die(); $options->{action_on_true} @@ -3349,7 +3681,7 @@ sub _set_argv { - my ( $self, @argv ) = @_; + my ($self, @argv) = @_; $self = $self->_get_instance; $self->{_argv} = \@argv; return; @@ -3376,32 +3708,32 @@ { my $self = $_[0]->_get_instance(); - ref $self->{lang_supported}->{ $self->{lang} } eq "CODE" and $self->{lang_supported}->{ $self->{lang} }->($self); - defined( $self->{lang_supported}->{ $self->{lang} } ) or croak( "Unsupported compile language \"" . $self->{lang} . "\"" ); + ref $self->{lang_supported}->{$self->{lang}} eq "CODE" and $self->{lang_supported}->{$self->{lang}}->($self); + defined($self->{lang_supported}->{$self->{lang}}) or croak("Unsupported compile language \"" . $self->{lang} . "\""); - $self->{lang_supported}->{ $self->{lang} }->new(); + $self->{lang_supported}->{$self->{lang}}->new(); } sub _set_language { my $self = shift->_get_instance(); - my ( $lang, $impl ) = @_; + my ($lang, $impl) = @_; defined($lang) or croak("Missing language"); defined($impl) - and defined( $self->{lang_supported}->{$lang} ) + and defined($self->{lang_supported}->{$lang}) and $impl ne $self->{lang_supported}->{$lang} - and croak( "Language implementor ($impl) doesn't match exisiting one (" . $self->{lang_supported}->{$lang} . ")" ); + and croak("Language implementor ($impl) doesn't match exisiting one (" . $self->{lang_supported}->{$lang} . ")"); defined($impl) - and !defined( $self->{lang_supported}->{$lang} ) + and !defined($self->{lang_supported}->{$lang}) and $self->{lang_supported}->{$lang} = $impl; ref $self->{lang_supported}->{$lang} eq "CODE" and $self->{lang_supported}->{$lang}->($self); - defined( $self->{lang_supported}->{$lang} ) or croak("Unsupported language \"$lang\""); + defined($self->{lang_supported}->{$lang}) or croak("Unsupported language \"$lang\""); - defined( $self->{extra_compile_flags}->{$lang} ) or $self->{extra_compile_flags}->{$lang} = []; + defined($self->{extra_compile_flags}->{$lang}) or $self->{extra_compile_flags}->{$lang} = []; $self->{lang} = $lang; @@ -3422,15 +3754,15 @@ sub _fill_defines { - my ( $self, $src, $action_if_true, $action_if_false ) = @_; + my ($self, $src, $action_if_true, $action_if_false) = @_; ref $self or $self = $self->_get_instance(); my $conftest = ""; - while ( my ( $defname, $defcnt ) = each( %{ $self->{defines} } ) ) + while (my ($defname, $defcnt) = each(%{$self->{defines}})) { $defcnt->[0] or next; defined $defcnt->[1] and $conftest .= "/* " . $defcnt->[1] . " */\n"; - $conftest .= join( " ", "#define", $defname, $defcnt->[0] ) . "\n"; + $conftest .= join(" ", "#define", $defname, $defcnt->[0]) . "\n"; } $conftest .= "/* end of conftest.h */\n"; @@ -3444,7 +3776,7 @@ =head2 _default_includes returns a string containing default includes for program prologue taken -from autoconf/headers.m4: +from C: #include #ifdef HAVE_SYS_TYPES_H @@ -3535,7 +3867,7 @@ { my $self = shift->_get_instance(); my $body = shift || ""; - sprintf( $_main_tpl, $body ); + sprintf($_main_tpl, $body); } =head2 _default_includes_with_perl @@ -3556,15 +3888,15 @@ sub _default_includes_with_perl { - join( "\n", $_[0]->_default_includes, $_include_perl ); + join("\n", $_[0]->_default_includes, $_include_perl); } sub _cache_prefix { "ac" } sub _cache_name { - my ( $self, @names ) = @_; - my $cache_name = join( "_", $self->_cache_prefix(), "cv", @names ); + my ($self, @names) = @_; + my $cache_name = join("_", $self->_cache_prefix(), "cv", @names); $cache_name =~ tr/_A-Za-z0-9/_/c; $cache_name; } @@ -3572,10 +3904,10 @@ sub _get_log_fh { my $self = $_[0]->_get_instance(); - unless ( defined( $self->{logfh} ) ) + unless (defined($self->{logfh})) { my $open_mode = defined $self->{logfile_mode} ? $self->{logfile_mode} : ">"; - open( my $fh, $open_mode, $self->{logfile} ) or croak "Could not open file $self->{logfile}: $!"; + open(my $fh, $open_mode, $self->{logfile}) or croak "Could not open file $self->{logfile}: $!"; $self->{logfh} = [$fh]; } @@ -3584,12 +3916,12 @@ sub _add_log_entry { - my ( $self, @logentries ) = @_; + my ($self, @logentries) = @_; ref($self) or $self = $self->_get_instance(); $self->_get_log_fh(); foreach my $logentry (@logentries) { - foreach my $fh ( @{ $self->{logfh} } ) + foreach my $fh (@{$self->{logfh}}) { print {$fh} "$logentry"; } @@ -3600,11 +3932,11 @@ sub _add_log_lines { - my ( $self, @logentries ) = @_; + my ($self, @logentries) = @_; ref($self) or $self = $self->_get_instance(); $self->_get_log_fh(); - my $logmsg = join( "\n", @logentries ) . "\n"; - foreach my $fh ( @{ $self->{logfh} } ) + my $logmsg = join("\n", @logentries) . "\n"; + foreach my $fh (@{$self->{logfh}}) { print {$fh} $logmsg; } @@ -3614,22 +3946,22 @@ =head2 add_log_fh -Push new file handles at end of log-handles to allow tee-ing log-output +Push new file handles at end of log-handles to allow tee'ing log-output =cut sub add_log_fh { - my ( $self, @newh ) = @_; + my ($self, @newh) = @_; $self->_get_log_fh(); SKIP_DUP: foreach my $fh (@newh) { - foreach my $eh ( @{ $self->{logfh} } ) + foreach my $eh (@{$self->{logfh}}) { $fh == $eh and next SKIP_DUP; } - push @{ $self->{logfh} }, $fh; + push @{$self->{logfh}}, $fh; } return; } @@ -3644,15 +3976,15 @@ sub delete_log_fh { - my ( $self, @xh ) = @_; + my ($self, @xh) = @_; $self->_get_log_fh(); SKIP_DUP: foreach my $fh (@xh) { - foreach my $ih ( 0 .. $#{ $self->{logfh} } ) + foreach my $ih (0 .. $#{$self->{logfh}}) { $fh == $self->{logfh}->[$ih] or next; - splice @{ $self->{logfh} }, $ih, 1; + splice @{$self->{logfh}}, $ih, 1; last; } } @@ -3661,24 +3993,37 @@ sub _cache_type_name { - my ( $self, @names ) = @_; - $self->_cache_name( map { $_ =~ tr/*/p/; $_ } @names ); + my ($self, @names) = @_; + $self->_cache_name(map { $_ =~ tr/*/p/; $_ } @names); } +=head2 _get_extra_compiler_flags + +Returns the determined flags required to run the compile stage as string + +=cut + sub _get_extra_compiler_flags { my $self = shift->_get_instance(); - my @ppflags = @{ $self->{extra_preprocess_flags} }; - my @cflags = @{ $self->{extra_compile_flags}->{ $self->{lang} } }; - join( " ", @ppflags, @cflags ); + my @ppflags = @{$self->{extra_preprocess_flags}}; + my @cflags = @{$self->{extra_compile_flags}->{$self->{lang}}}; + join(" ", map { _quote_shell_arg $_ } (@ppflags, @cflags)); } +=head2 _get_extra_linker_flags + +Returns the determined flags required to run the link stage as string + +=cut + sub _get_extra_linker_flags { - my $self = shift->_get_instance(); - my @libs = @{ $self->{extra_libs} }; - my @ldflags = @{ $self->{extra_link_flags} }; - join( " ", @ldflags, map { "-l$_" } @libs ); + my $self = shift->_get_instance(); + my @libs = @{$self->{extra_libs}}; + my @lib_dirs = @{$self->{extra_lib_dirs}}; + my @ldflags = @{$self->{extra_link_flags}}; + join(" ", map { _quote_shell_arg $_ } (@ldflags, map("-L" . $self->_sanitize_prog($_), @lib_dirs), map("-l$_", @libs))); } =head1 AUTHOR @@ -3751,7 +4096,7 @@ =head1 COPYRIGHT & LICENSE -Copyright 2004-2016 by the Authors +Copyright 2004-2020 by the Authors This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff -Nru liblist-moreutils-perl-0.416/lib/List/MoreUtils/Contributing.pod liblist-moreutils-perl-0.430/lib/List/MoreUtils/Contributing.pod --- liblist-moreutils-perl-0.416/lib/List/MoreUtils/Contributing.pod 2016-07-06 14:00:37.000000000 +0000 +++ liblist-moreutils-perl-0.430/lib/List/MoreUtils/Contributing.pod 2020-10-02 06:22:44.000000000 +0000 @@ -37,7 +37,7 @@ One example of removing unnecessary infrastructure could be to move L and L into authoring mode, when -imrpoved test for RT#93207 could be reasonably done by a module which +improved test for RT#93207 could be reasonably done by a module which is recommended for test. The recommendation of L in L a desirable @@ -53,7 +53,7 @@ The reason for L is quite simple - the opportunities for checking the environment cover a much wider range than a simple test whether there is a working compiler. It requires a lot of improvements -since it's fundament L was never designed to support +since its base L was never designed to support that kind of solutions - but there is I. To finally solve issues as RT#75672 even in cross-compile environments - there is no way around such a checking tool. @@ -79,10 +79,22 @@ =head1 COPYRIGHT AND LICENSE -Copyright 2015,2016 by Jens Rehsack +Copyright 2015-2017 by Jens Rehsack -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.4 or, -at your option, any later version of Perl 5 you may have available. +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. =cut diff -Nru liblist-moreutils-perl-0.416/lib/List/MoreUtils/PP.pm liblist-moreutils-perl-0.430/lib/List/MoreUtils/PP.pm --- liblist-moreutils-perl-0.416/lib/List/MoreUtils/PP.pm 2016-07-06 14:21:27.000000000 +0000 +++ liblist-moreutils-perl-0.430/lib/List/MoreUtils/PP.pm 2020-10-21 13:41:05.000000000 +0000 @@ -1,10 +1,10 @@ package List::MoreUtils::PP; -use 5.006; +use 5.008_001; use strict; use warnings; -our $VERSION = '0.416'; +our $VERSION = '0.430'; =pod @@ -19,6 +19,9 @@ =cut +## no critic (Subroutines::ProhibitSubroutinePrototypes, Subroutines::RequireArgUnpacking) +## no critic (Subroutines::ProhibitManyArgs) + sub any (&@) { my $f = shift; @@ -67,7 +70,7 @@ { $f->() and $found++ and return 0; } - $found; + return $found; } sub any_u (&@) @@ -111,7 +114,82 @@ { $f->() and $found++ and return 0; } - $found; + return $found; +} + +sub reduce_u(&@) +{ + my $code = shift; + + # Localise $a, $b + my ($caller_a, $caller_b) = do + { + my $pkg = caller(); + ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements) + no strict 'refs'; + \*{$pkg . '::a'}, \*{$pkg . '::b'}; + }; + + ## no critic (Variables::RequireInitializationForLocalVars) + local (*$caller_a, *$caller_b); + *$caller_a = \(); + for (0 .. $#_) + { + *$caller_b = \$_[$_]; + *$caller_a = \($code->()); + } + + return ${*$caller_a}; +} + +sub reduce_0(&@) +{ + my $code = shift; + + # Localise $a, $b + my ($caller_a, $caller_b) = do + { + my $pkg = caller(); + ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements) + no strict 'refs'; + \*{$pkg . '::a'}, \*{$pkg . '::b'}; + }; + + ## no critic (Variables::RequireInitializationForLocalVars) + local (*$caller_a, *$caller_b); + *$caller_a = \0; + for (0 .. $#_) + { + *$caller_b = \$_[$_]; + *$caller_a = \($code->()); + } + + return ${*$caller_a}; +} + +sub reduce_1(&@) +{ + my $code = shift; + + # Localise $a, $b + my ($caller_a, $caller_b) = do + { + my $pkg = caller(); + ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements) + no strict 'refs'; + \*{$pkg . '::a'}, \*{$pkg . '::b'}; + }; + + ## no critic (Variables::RequireInitializationForLocalVars) + local (*$caller_a, *$caller_b); + *$caller_a = \1; + for (0 .. $#_) + { + *$caller_b = \$_[$_]; + *$caller_a = \($code->()); + } + + return ${*$caller_a}; } sub true (&@) @@ -133,7 +211,7 @@ sub firstidx (&@) { my $f = shift; - foreach my $i ( 0 .. $#_ ) + foreach my $i (0 .. $#_) { local *_ = \$_[$i]; return $i if $f->(); @@ -148,6 +226,7 @@ { return $_ if $test->(); } + ## no critic (Subroutines::ProhibitExplicitReturnUndef) return undef; } @@ -159,6 +238,7 @@ my $testval = $test->(); $testval and return $testval; } + ## no critic (Subroutines::ProhibitExplicitReturnUndef) return undef; } @@ -166,7 +246,7 @@ { my $f = shift; my $found; - foreach my $i ( 0 .. $#_ ) + foreach my $i (0 .. $#_) { local *_ = \$_[$i]; $f->() or next; @@ -185,6 +265,7 @@ { $test->() or next; $result = $_; + ## no critic (Subroutines::ProhibitExplicitReturnUndef) $found++ and return undef; } return $result; @@ -199,6 +280,7 @@ { my $rv = $test->() or next; $result = $rv; + ## no critic (Subroutines::ProhibitExplicitReturnUndef) $found++ and return undef; } return $found ? $result : undef; @@ -207,7 +289,7 @@ sub lastidx (&@) { my $f = shift; - foreach my $i ( reverse 0 .. $#_ ) + foreach my $i (reverse 0 .. $#_) { local *_ = \$_[$i]; return $i if $f->(); @@ -219,7 +301,7 @@ { my $test = shift; my $ix; - for ( $ix = $#_; $ix >= 0; $ix-- ) + for ($ix = $#_; $ix >= 0; $ix--) { local *_ = \$_[$ix]; my $testval = $test->(); @@ -228,6 +310,7 @@ $_[$ix] = $_; return $_ if $testval; } + ## no critic (Subroutines::ProhibitExplicitReturnUndef) return undef; } @@ -235,7 +318,7 @@ { my $test = shift; my $ix; - for ( $ix = $#_; $ix >= 0; $ix-- ) + for ($ix = $#_; $ix >= 0; $ix--) { local *_ = \$_[$ix]; my $testval = $test->(); @@ -244,22 +327,23 @@ $_[$ix] = $_; return $testval if $testval; } + ## no critic (Subroutines::ProhibitExplicitReturnUndef) return undef; } sub insert_after (&$\@) { - my ( $f, $val, $list ) = @_; - my $c = &firstidx( $f, @$list ); - @$list = ( @{$list}[ 0 .. $c ], $val, @{$list}[ $c + 1 .. $#$list ], ) and return 1 if $c != -1; + my ($f, $val, $list) = @_; + my $c = &firstidx($f, @$list); + @$list = (@{$list}[0 .. $c], $val, @{$list}[$c + 1 .. $#$list],) and return 1 if $c != -1; return 0; } sub insert_after_string ($$\@) { - my ( $string, $val, $list ) = @_; + my ($string, $val, $list) = @_; my $c = firstidx { defined $_ and $string eq $_ } @$list; - @$list = ( @{$list}[ 0 .. $c ], $val, @{$list}[ $c + 1 .. $#$list ], ) and return 1 if $c != -1; + @$list = (@{$list}[0 .. $c], $val, @{$list}[$c + 1 .. $#$list],) and return 1 if $c != -1; return 0; } @@ -267,7 +351,7 @@ { my $action = shift; &$action foreach my @values = @_; - wantarray ? @values : $values[-1]; + return wantarray ? @values : $values[-1]; } sub after (&@) @@ -275,7 +359,8 @@ my $test = shift; my $started; my $lag; - grep $started ||= do + ## no critic (BuiltinFunctions::RequireBlockGrep) + return grep $started ||= do { my $x = $lag; $lag = $test->(); @@ -287,14 +372,14 @@ { my $test = shift; my $started; - grep $started ||= $test->(), @_; + return grep { $started ||= $test->() } @_; } sub before (&@) { my $test = shift; my $more = 1; - grep $more &&= !$test->(), @_; + return grep { $more &&= !$test->() } @_; } sub before_incl (&@) @@ -302,7 +387,8 @@ my $test = shift; my $more = 1; my $lag = 1; - grep $more &&= do + ## no critic (BuiltinFunctions::RequireBlockGrep) + return grep $more &&= do { my $x = $lag; $lag = !$test->(); @@ -313,7 +399,7 @@ sub indexes (&@) { my $test = shift; - grep { + return grep { local *_ = \$_[$_]; $test->() } 0 .. $#_; @@ -325,24 +411,27 @@ # Symbols for caller's input arrays use vars qw{ @A @B }; - local ( *A, *B ) = @_; + local (*A, *B) = @_; # Localise $a, $b - my ( $caller_a, $caller_b ) = do + my ($caller_a, $caller_b) = do { my $pkg = caller(); + ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements) no strict 'refs'; - \*{ $pkg . '::a' }, \*{ $pkg . '::b' }; + \*{$pkg . '::a'}, \*{$pkg . '::b'}; }; # Loop iteration limit my $limit = $#A > $#B ? $#A : $#B; + ## no critic (Variables::RequireInitializationForLocalVars) # This map expression is also the return value - local ( *$caller_a, *$caller_b ); - map { + local (*$caller_a, *$caller_b); + ## no critic (BuiltinFunctions::ProhibitComplexMappings) + return map { # Assign to $a, $b as refs to caller's array elements - ( *$caller_a, *$caller_b ) = \( $A[$_], $B[$_] ); + (*$caller_a, *$caller_b) = \($#A < $_ ? undef : $A[$_], $#B < $_ ? undef : $B[$_]); # Perform the transformation $op->(); @@ -363,7 +452,7 @@ # Get the length of the longest input array foreach (@list) { - unless ( ref $_ eq 'ARRAY' ) + unless (ref $_ eq 'ARRAY') { require Carp; Carp::croak("each_arrayref: argument is not an array reference\n"); @@ -376,14 +465,15 @@ if (@_) { my $method = shift; - unless ( $method eq 'index' ) + unless ($method eq 'index') { require Carp; Carp::croak("each_array: unknown argument '$method' passed to iterator."); } - # Return current (last fetched) index + ## no critic (Subroutines::ProhibitExplicitReturnUndef) return undef if $index == 0 || $index > $max; + # Return current (last fetched) index return $index - 1; } @@ -392,35 +482,75 @@ my $i = $index++; # Return ith elements + ## no critic (BuiltinFunctions::RequireBlockMap) return map $_->[$i], @list; - } + } } sub natatime ($@) { my $n = shift; my @list = @_; - return sub { - return splice @list, 0, $n; - } + return sub { return splice @list, 0, $n; } +} + +# "leaks" when lexically hidden in arrayify +my $flatten; +$flatten = sub { + return map { (ref $_ and ("ARRAY" eq ref $_ or overload::Method($_, '@{}'))) ? ($flatten->(@{$_})) : ($_) } @_; +}; + +sub arrayify +{ + return map { $flatten->($_) } @_; } sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) { my $max = -1; - $max < $#$_ && ( $max = $#$_ ) foreach @_; - map { + $max < $#$_ && ($max = $#$_) foreach @_; + ## no critic (BuiltinFunctions::ProhibitComplexMappings) + return map { my $ix = $_; + ## no critic (BuiltinFunctions::RequireBlockMap) map $_->[$ix], @_; } 0 .. $max; } +sub zip6 (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) +{ + my $max = -1; + $max < $#$_ && ($max = $#$_) foreach @_; + ## no critic (BuiltinFunctions::ProhibitComplexMappings) + return map { + my $ix = $_; + ## no critic (BuiltinFunctions::RequireBlockMap) + [map $_->[$ix], @_]; + } 0 .. $max; +} + +sub listcmp (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) +{ + my %ret; + for (my $i = 0; $i < scalar @_; ++$i) + { + my %seen; + my $k; + foreach my $w (grep { defined $_ and not $seen{$k = $_}++ } @{$_[$i]}) + { + $ret{$w} ||= []; + push @{$ret{$w}}, $i; + } + } + return %ret; +} + sub uniq (@) { my %seen = (); my $k; my $seen_undef; - grep { defined $_ ? not $seen{ $k = $_ }++ : not $seen_undef++ } @_; + return grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_; } sub singleton (@) @@ -428,8 +558,82 @@ my %seen = (); my $k; my $seen_undef; - grep { 1 == ( defined $_ ? $seen{ $k = $_ } : $seen_undef ) } - grep { defined $_ ? not $seen{ $k = $_ }++ : not $seen_undef++ } @_; + return grep { 1 == (defined $_ ? $seen{$k = $_} : $seen_undef) } + grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_; +} + +sub duplicates (@) +{ + my %seen = (); + my $k; + my $seen_undef; + return grep { 1 < (defined $_ ? $seen{$k = $_} : $seen_undef) } + grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_; +} + +sub frequency (@) +{ + my %seen = (); + my $k; + my $seen_undef; + my %h = map { defined $_ ? ($_ => $seen{$k = $_}) : () } + grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_; + wantarray or return (scalar keys %h) + ($seen_undef ? 1 : 0); + undef $k; + return (%h, $seen_undef ? (\$k => $seen_undef) : ()); +} + +sub occurrences (@) +{ + my %seen = (); + my $k; + my $seen_undef; + my @ret; + foreach my $l (map { $_ } grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_) + { + my $n = defined $l ? $seen{$l} : $seen_undef; + defined $ret[$n] or $ret[$n] = []; + push @{$ret[$n]}, $l; + } + return @ret; +} + +sub mode (@) +{ + my %seen = (); + my ($max, $k, $seen_undef) = (1); + + foreach (@_) { defined $_ ? ($max < ++$seen{$k = $_} and ++$max) : ($max < ++$seen_undef and ++$max) } + wantarray or return $max; + + my @ret = ($max); + foreach my $l (grep { $seen{$_} == $max } keys %seen) + { + push @ret, $l; + } + $seen_undef and $seen_undef == $max and push @ret, undef; + return @ret; +} + +sub samples ($@) +{ + my $n = shift; + if ($n > @_) + { + require Carp; + Carp::croak(sprintf("Cannot get %d samples from %d elements", $n, scalar @_)); + } + + for (my $i = @_; @_ - $i > $n;) + { + my $idx = @_ - $i; + my $swp = $idx + int(rand(--$i)); + my $xchg = $_[$swp]; + $_[$swp] = $_[$idx]; + $_[$idx] = $xchg; + } + + return splice @_, 0, $n; } sub minmax (@) @@ -437,43 +641,80 @@ return unless @_; my $min = my $max = $_[0]; - for ( my $i = 1; $i < @_; $i += 2 ) + for (my $i = 1; $i < @_; $i += 2) + { + if ($_[$i - 1] <= $_[$i]) + { + $min = $_[$i - 1] if $min > $_[$i - 1]; + $max = $_[$i] if $max < $_[$i]; + } + else + { + $min = $_[$i] if $min > $_[$i]; + $max = $_[$i - 1] if $max < $_[$i - 1]; + } + } + + if (@_ & 1) + { + my $i = $#_; + if ($_[$i - 1] <= $_[$i]) + { + $min = $_[$i - 1] if $min > $_[$i - 1]; + $max = $_[$i] if $max < $_[$i]; + } + else + { + $min = $_[$i] if $min > $_[$i]; + $max = $_[$i - 1] if $max < $_[$i - 1]; + } + } + + return ($min, $max); +} + +sub minmaxstr (@) +{ + return unless @_; + my $min = my $max = $_[0]; + + for (my $i = 1; $i < @_; $i += 2) { - if ( $_[ $i - 1 ] <= $_[$i] ) + if ($_[$i - 1] le $_[$i]) { - $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ]; - $max = $_[$i] if $max < $_[$i]; + $min = $_[$i - 1] if $min gt $_[$i - 1]; + $max = $_[$i] if $max lt $_[$i]; } else { - $min = $_[$i] if $min > $_[$i]; - $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ]; + $min = $_[$i] if $min gt $_[$i]; + $max = $_[$i - 1] if $max lt $_[$i - 1]; } } - if ( @_ & 1 ) + if (@_ & 1) { my $i = $#_; - if ( $_[ $i - 1 ] <= $_[$i] ) + if ($_[$i - 1] le $_[$i]) { - $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ]; - $max = $_[$i] if $max < $_[$i]; + $min = $_[$i - 1] if $min gt $_[$i - 1]; + $max = $_[$i] if $max lt $_[$i]; } else { - $min = $_[$i] if $min > $_[$i]; - $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ]; + $min = $_[$i] if $min gt $_[$i]; + $max = $_[$i - 1] if $max lt $_[$i - 1]; } } - return ( $min, $max ); + return ($min, $max); } sub part (&@) { - my ( $code, @list ) = @_; + my ($code, @list) = @_; my @parts; - push @{ $parts[ $code->($_) ] }, $_ foreach @list; + push @{$parts[$code->($_)]}, $_ foreach @list; return @parts; } @@ -484,9 +725,10 @@ my $rc; my $i = 0; my $j = @_; + ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions) do { - my $k = int( ( $i + $j ) / 2 ); + my $k = int(($i + $j) / 2); $k >= @_ and return; @@ -496,7 +738,7 @@ $rc == 0 and return wantarray ? $_ : 1; - if ( $rc < 0 ) + if ($rc < 0) { $i = $k + 1; } @@ -516,9 +758,10 @@ my $rc; my $i = 0; my $j = @_; + ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions) do { - my $k = int( ( $i + $j ) / 2 ); + my $k = int(($i + $j) / 2); $k >= @_ and return -1; @@ -527,7 +770,7 @@ $rc == 0 and return $k; - if ( $rc < 0 ) + if ($rc < 0) { $i = $k + 1; } @@ -540,23 +783,134 @@ return -1; } +sub lower_bound(&@) +{ + my $code = shift; + my $count = @_; + my $first = 0; + while ($count > 0) + { + my $step = $count >> 1; + my $it = $first + $step; + local *_ = \$_[$it]; + if ($code->() < 0) + { + $first = ++$it; + $count -= $step + 1; + } + else + { + $count = $step; + } + } + + return $first; +} + +sub upper_bound(&@) +{ + my $code = shift; + my $count = @_; + my $first = 0; + while ($count > 0) + { + my $step = $count >> 1; + my $it = $first + $step; + local *_ = \$_[$it]; + if ($code->() <= 0) + { + $first = ++$it; + $count -= $step + 1; + } + else + { + $count = $step; + } + } + + return $first; +} + +sub equal_range(&@) +{ + my $lb = &lower_bound(@_); + my $ub = &upper_bound(@_); + return ($lb, $ub); +} + +sub binsert (&$\@) +{ + my $lb = &lower_bound($_[0], @{$_[2]}); + splice @{$_[2]}, $lb, 0, $_[1]; + return $lb; +} + +sub bremove (&\@) +{ + my $lb = &lower_bound($_[0], @{$_[1]}); + return splice @{$_[1]}, $lb, 1; +} + +sub qsort(&\@) +{ + require Carp; + Carp::croak("It's insane to use a pure-perl qsort"); +} + +sub slide(&@) +{ + my $op = shift; + my @l = @_; + + ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements) + # Localise $a, $b + my ($caller_a, $caller_b) = do + { + my $pkg = caller(); + no strict 'refs'; + \*{$pkg . '::a'}, \*{$pkg . '::b'}; + }; + + ## no critic (Variables::RequireInitializationForLocalVars) + # This map expression is also the return value + local (*$caller_a, *$caller_b); + ## no critic (BuiltinFunctions::ProhibitComplexMappings) + return map { + # Assign to $a, $b as refs to caller's array elements + (*$caller_a, *$caller_b) = \($l[$_], $l[$_ + 1]); + + # Perform the transformation + $op->(); + } 0 .. ($#l - 1); +} + +sub slideatatime ($$@) +{ + my ($m, $w, @list) = @_; + my $n = $w - $m - 1; + return $n >= 0 + ? sub { my @r = splice @list, 0, $m; $#list < $n and $n = $#list; @r and push @r, (@list ? @list[0 .. $n] : ()); return @r; } + : sub { return splice @list, 0, $m; }; +} + sub sort_by(&@) { - my ( $code, @list ) = @_; + my ($code, @list) = @_; return map { $_->[0] } sort { $a->[1] cmp $b->[1] } - map { [ $_, scalar( $code->() ) ] } @list; + map { [$_, scalar($code->())] } @list; } sub nsort_by(&@) { - my ( $code, @list ) = @_; + my ($code, @list) = @_; return map { $_->[0] } sort { $a->[1] <=> $b->[1] } - map { [ $_, scalar( $code->() ) ] } @list; + map { [$_, scalar($code->())] } @list; } -sub _XScompiled { 0 } +## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) +sub _XScompiled { return 0 } =head1 SEE ALSO @@ -576,11 +930,23 @@ Copyright 2004 - 2010 by Tassilo von Parseval -Copyright 2013 - 2016 by Jens Rehsack +Copyright 2013 - 2017 by Jens Rehsack -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.4 or, -at your option, any later version of Perl 5 you may have available. +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. =cut diff -Nru liblist-moreutils-perl-0.416/lib/List/MoreUtils/XS.pm liblist-moreutils-perl-0.430/lib/List/MoreUtils/XS.pm --- liblist-moreutils-perl-0.416/lib/List/MoreUtils/XS.pm 2016-07-06 14:21:27.000000000 +0000 +++ liblist-moreutils-perl-0.430/lib/List/MoreUtils/XS.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -package List::MoreUtils::XS; - -use 5.006; -use strict; -use warnings; - -use vars qw{$VERSION @ISA}; - -$VERSION = '0.416'; - -# Load the XS at compile-time so that redefinition warnings will be -# thrown correctly if the XS versions of part or indexes loaded - -# PERL_DL_NONLAZY must be false, or any errors in loading will just -# cause the perl code to be tested -local $ENV{PERL_DL_NONLAZY} = 0 if $ENV{PERL_DL_NONLAZY}; - -use XSLoader (); -XSLoader::load("List::MoreUtils", "$VERSION"); - -=pod - -=head1 NAME - -List::MoreUtils::XS - Provide compiled List::MoreUtils functions - -=head1 SYNOPSIS - - BEGIN { delete $ENV{LIST_MOREUTILS_PP}; } - use List::MoreUtils ...; - -=head1 SEE ALSO - -L, L - -=head1 AUTHOR - -Jens Rehsack Erehsack AT cpan.orgE - -Adam Kennedy Eadamk@cpan.orgE - -Tassilo von Parseval Etassilo.von.parseval@rwth-aachen.deE - -=head1 COPYRIGHT AND LICENSE - -Some parts copyright 2011 Aaron Crane. - -Copyright 2004 - 2010 by Tassilo von Parseval - -Copyright 2013 - 2016 by Jens Rehsack - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.4 or, -at your option, any later version of Perl 5 you may have available. - -=cut - -1; diff -Nru liblist-moreutils-perl-0.416/lib/List/MoreUtils.pm liblist-moreutils-perl-0.430/lib/List/MoreUtils.pm --- liblist-moreutils-perl-0.416/lib/List/MoreUtils.pm 2016-07-06 14:21:27.000000000 +0000 +++ liblist-moreutils-perl-0.430/lib/List/MoreUtils.pm 2020-10-21 13:41:05.000000000 +0000 @@ -1,13 +1,22 @@ package List::MoreUtils; -use 5.006; +use 5.008_001; use strict; use warnings; +my $have_xs; +our $VERSION = '0.430'; + BEGIN { - our $VERSION = '0.416'; - eval { require List::MoreUtils::XS; } unless $ENV{LIST_MOREUTILS_PP}; + unless (defined($have_xs)) + { + ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) + eval { require List::MoreUtils::XS; } unless $ENV{LIST_MOREUTILS_PP}; + ## no critic (ErrorHandling::RequireCarping) + die $@ if $@ && defined $ENV{LIST_MOREUTILS_PP} && $ENV{LIST_MOREUTILS_PP} == 0; + $have_xs = 0 + defined($INC{'List/MoreUtils/XS.pm'}); + } use List::MoreUtils::PP qw(); } @@ -34,12 +43,27 @@ firstres onlyidx onlyval onlyres lastres singleton bsearchidx ); +my @v0_420 = qw(arrayify duplicates minmaxstr samples zip6 reduce_0 reduce_1 reduce_u + listcmp frequency occurrences mode + binsert bremove equal_range lower_bound upper_bound qsort + slide slideatatime); -my @all_functions = ( @junctions, @v0_22, @v0_24, @v0_33, @v0_400 ); +my @all_functions = (@junctions, @v0_22, @v0_24, @v0_33, @v0_400, @v0_420); +## no critic (TestingAndDebugging::ProhibitNoStrict) no strict "refs"; -List::MoreUtils->can($_) or *$_ = List::MoreUtils::PP->can($_) for(@all_functions); +if ($have_xs) +{ + my $x; + for (@all_functions) + { + List::MoreUtils->can($_) or *$_ = $x if ($x = List::MoreUtils::XS->can($_)); + } +} +List::MoreUtils->can($_) or *$_ = List::MoreUtils::PP->can($_) for (@all_functions); use strict; +## use critic (TestingAndDebugging::ProhibitNoStrict) +use parent qw(Exporter::Tiny); my %alias_list = ( v0_22 => { @@ -60,47 +84,54 @@ last_result => "lastres", bsearch_index => "bsearchidx", }, + v0_420 => { + bsearch_insert => "binsert", + bsearch_remove => "bremove", + zip_unflatten => "zip6", + }, ); -our @ISA = qw(Exporter::Tiny); -our @EXPORT_OK = ( @all_functions, map { keys %$_ } values %alias_list ); +our @EXPORT_OK = (@all_functions, map { keys %$_ } values %alias_list); our %EXPORT_TAGS = ( all => \@EXPORT_OK, 'like_0.22' => [ - any_u => { -as => 'any' }, - all_u => { -as => 'all' }, - none_u => { -as => 'none' }, - notall_u => { -as => 'notall' }, + any_u => {-as => 'any'}, + all_u => {-as => 'all'}, + none_u => {-as => 'none'}, + notall_u => {-as => 'notall'}, @v0_22, - keys %{ $alias_list{v0_22} }, + keys %{$alias_list{v0_22}}, ], 'like_0.24' => [ - any_u => { -as => 'any' }, - all_u => { -as => 'all' }, - notall_u => { -as => 'notall' }, + any_u => {-as => 'any'}, + all_u => {-as => 'all'}, + notall_u => {-as => 'notall'}, 'none', @v0_22, @v0_24, - keys %{ $alias_list{v0_22} }, + keys %{$alias_list{v0_22}}, ], 'like_0.33' => [ @junctions, @v0_22, # v0_24 functions were omitted @v0_33, - keys %{ $alias_list{v0_22} }, - keys %{ $alias_list{v0_33} }, + keys %{$alias_list{v0_22}}, + keys %{$alias_list{v0_33}}, ], ); -for my $set ( values %alias_list ) +for my $set (values %alias_list) { - for my $alias ( keys %$set ) + for my $alias (keys %$set) { + ## no critic (TestingAndDebugging::ProhibitNoStrict) no strict qw(refs); - *$alias = __PACKAGE__->can( $set->{$alias} ); + *$alias = __PACKAGE__->can($set->{$alias}); + ## use critic (TestingAndDebugging::ProhibitNoStrict) } } +use strict; =pod @@ -392,6 +423,50 @@ C is an alias for C. +=head3 zip6 + +=head3 zip_unflatten + +Returns a list of arrays consisting of the first elements of each array, +then the second, then the third, etc, until all arrays are exhausted. + + @x = qw/a b c d/; + @y = qw/1 2 3 4/; + @z = zip6 @x, @y; # returns [a, 1], [b, 2], [c, 3], [d, 4] + + @a = ('x'); + @b = ('1', '2'); + @c = qw/zip zap zot/; + @d = zip6 @a, @b, @c; # [x, 1, zip], [undef, 2, zap], [undef, undef, zot] + +C is an alias for C. + +=head3 listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ] + +Returns an associative list of elements and every I of the list it +was found in. Allows easy implementation of @a & @b, @a | @b, @a ^ @b and +so on. +Undefined entries in any given array are skipped. + + my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen); + my @b = qw(two three five seven eleven thirteen seventeen); + my @c = qw(one one two three five eight thirteen twentyone); + my %cmp = listcmp @a, @b, @c; # returns (one => [0, 2], two => [0, 1, 2], three => [0, 1, 2], four => [0], ...) + + my @seq = (1, 2, 3); + my @prim = (undef, 2, 3, 5); + my @fib = (1, 1, 2); + my %cmp = listcmp @seq, @prim, @fib; + # returns ( 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] ) + +=head3 arrayify LIST[,LIST[,LIST...]] + +Returns a list consisting of each element of given arrays. Recursive arrays +are flattened, too. + + @a = (1, [[2], 3], 4, [5], 6, [7], 8, 9); + @l = arrayify @a; # returns 1, 2, 3, 4, 5, 6, 7, 8, 9 + =head3 uniq LIST =head3 distinct LIST @@ -405,16 +480,16 @@ my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5 # returns "Mike", "Michael", "Richard", "Rick" my @n = distinct "Mike", "Michael", "Richard", "Rick", "Michael", "Rick" - # returns '', 'S1', A5' and complains about "Use of uninitialized value" - my @s = distinct '', undef, 'S1', 'A5' - # returns undef, 'S1', A5' and complains about "Use of uninitialized value" - my @w = uniq undef, '', 'S1', 'A5' + # returns "A8", "", undef, "A5", "S1" + my @s = distinct "A8", "", undef, "A5", "S1", "A5", "A8" + # returns "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C" + my @w = uniq "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C", "Giulietta", "Giulia" C is an alias for C. B can be used to give feedback about this behavior. -=head3 singleton +=head3 singleton LIST Returns a new list by stripping values in LIST occurring more than once by comparing the values as hash keys, except that undef is considered separate @@ -423,6 +498,51 @@ my @x = singleton 1,1,2,2,3,4,5 # returns 3 4 5 +=head3 duplicates LIST + +Returns a new list by stripping values in LIST occurring less than twice by +comparing the values as hash keys, except that undef is considered separate +from ''. The order of elements in the returned list is the same as in LIST. +In scalar context, returns the number of elements occurring more than once +in LIST. + + my @y = duplicates 1,1,2,4,7,2,3,4,6,9; #returns 1,2,4 + +=head3 frequency LIST + +Returns an associative list of distinct values and the corresponding frequency. + + my @f = frequency values %radio_nrw; # returns ( + # 'Deutschlandfunk (DLF)' => 9, 'WDR 3' => 10, + # 'WDR 4' => 11, 'WDR 5' => 14, 'WDR Eins Live' => 14, + # 'Deutschlandradio Kultur' => 8,...) + +=head3 occurrences LIST + +Returns a new list of frequencies and the corresponding values from LIST. + + my @o = occurrences ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + # @o = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]); + +=head3 mode LIST + +Returns the modal value of LIST. In scalar context, just the modal value +is returned, in list context all probes occurring I times are returned, +too. + + my @m = mode ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + # @m = (7, 4, 8) - bimodal LIST + +=head3 slide BLOCK LIST + +The function C operates on pairs of list elements like: + + my @s = slide { "$a and $b" } (0..3); + # @s = ("0 and 1", "1 and 2", "2 and 3") + +The idea behind this function is a kind of magnifying glass that is moved +along a list and calls C every time the next list item is reached. + =head2 Partitioning =head3 after BLOCK LIST @@ -471,7 +591,15 @@ my @idx = ( 0, 1, -1 ); my $i = 0; - my @part = part { $idx[$++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8] + my @part = part { $idx[$i++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8] + +=head3 samples COUNT LIST + +Returns a new list containing COUNT random samples from LIST. Is similar to +L, but stops after COUNT. + + @r = samples 10, 1..10; # same as shuffle + @r2 = samples 5, 1..10; # gives 5 values from 1..10; =head2 Iteration @@ -518,28 +646,31 @@ d e f g -=head2 Searching +=head3 slideatatime STEP, WINDOW, LIST -=head3 bsearch BLOCK LIST - -Performs a binary search on LIST which must be a sorted list of values. BLOCK -must return a negative value if the current element (stored in C<$_>) is smaller, -a positive value if it is bigger and zero if it matches. +Creates an array iterator, for looping over an array in chunks of +C<$windows-size> items at a time. -Returns a boolean value in scalar context. In list context, it returns the element -if it was found, otherwise the empty list. +The idea behind this function is a kind of magnifying glass (finer +controllable compared to L) that is moved along a list. -=head3 bsearchidx BLOCK LIST +Example: -=head3 bsearch_index BLOCK LIST + my @x = ('a' .. 'g'); + my $it = slideatatime 2, 3, @x; + while (my @vals = $it->()) + { + print "@vals\n"; + } -Performs a binary search on LIST which must be a sorted list of values. BLOCK -must return a negative value if the current element (stored in C<$_>) is smaller, -a positive value if it is bigger and zero if it matches. +This prints -Returns the index of found element, otherwise C<-1>. + a b c + c d e + e f g + g -C is an alias for C. +=head2 Searching =head3 firstval BLOCK LIST @@ -689,6 +820,149 @@ Similar to sort_by but compares its key values numerically. +=head3 qsort BLOCK ARRAY + +This sorts the given array B using the given compare code. Except for +tiny compare code like C<< $a <=> $b >>, qsort is much faster than Perl's C +depending on the version. + +Compared 5.8 and 5.26: + + my @rl; + for(my $i = 0; $i < 1E6; ++$i) { push @rl, rand(1E5) } + my $idx; + + sub ext_cmp { $_[0] <=> $_[1] } + + cmpthese( -60, { + 'qsort' => sub { + my @qrl = @rl; + qsort { ext_cmp($a, $b) } @qrl; + $idx = bsearchidx { ext_cmp($_, $rl[0]) } @qrl + }, + 'reverse qsort' => sub { + my @qrl = @rl; + qsort { ext_cmp($b, $a) } @qrl; + $idx = bsearchidx { ext_cmp($rl[0], $_) } @qrl + }, + 'sort' => sub { + my @srl = @rl; + @srl = sort { ext_cmp($a, $b) } @srl; + $idx = bsearchidx { ext_cmp($_, $rl[0]) } @srl + }, + 'reverse sort' => sub { + my @srl = @rl; + @srl = sort { ext_cmp($b, $a) } @srl; + $idx = bsearchidx { ext_cmp($rl[0], $_) } @srl + }, + }); + +5.8 results + + s/iter reverse sort sort reverse qsort qsort + reverse sort 6.21 -- -0% -8% -10% + sort 6.19 0% -- -7% -10% + reverse qsort 5.73 8% 8% -- -2% + qsort 5.60 11% 11% 2% -- + +5.26 results + + s/iter reverse sort sort reverse qsort qsort + reverse sort 4.54 -- -0% -96% -96% + sort 4.52 0% -- -96% -96% + reverse qsort 0.203 2139% 2131% -- -19% + qsort 0.164 2666% 2656% 24% -- + +Use it where external data sources might have to be compared (think of L +"tables"). + +C is available from List::MoreUtils::XS only. It's insane to maintain +a wrapper around Perl's sort nor having a pure Perl implementation. One could +create a flip-book in same speed as PP runs a qsort. + +=head2 Searching in sorted Lists + +=head3 bsearch BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in C<$_>) is smaller, +a positive value if it is bigger and zero if it matches. + +Returns a boolean value in scalar context. In list context, it returns the element +if it was found, otherwise the empty list. + +=head3 bsearchidx BLOCK LIST + +=head3 bsearch_index BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in C<$_>) is smaller, +a positive value if it is bigger and zero if it matches. + +Returns the index of found element, otherwise C<-1>. + +C is an alias for C. + +=head3 lower_bound BLOCK LIST + +Returns the index of the first element in LIST which does not compare +I. Technically it's the first element in LIST which does +not return a value below zero when passed to BLOCK. + + @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); + $lb = lower_bound { $_ <=> 2 } @ids; # returns 2 + $lb = lower_bound { $_ <=> 4 } @ids; # returns 10 + +lower_bound has a complexity of O(log n). + +=head3 upper_bound BLOCK LIST + +Returns the index of the first element in LIST which does not compare +I. Technically it's the first element in LIST which does +not return a value below or equal to zero when passed to BLOCK. + + @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); + $lb = upper_bound { $_ <=> 2 } @ids; # returns 4 + $lb = upper_bound { $_ <=> 4 } @ids; # returns 14 + +upper_bound has a complexity of O(log n). + +=head3 equal_range BLOCK LIST + +Returns a pair of indices containing the lower_bound and the upper_bound. + +=head2 Operations on sorted Lists + +=head3 binsert BLOCK ITEM LIST + +=head3 bsearch_insert BLOCK ITEM LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in C<$_>) is smaller, +a positive value if it is bigger and zero if it matches. + +ITEM is inserted at the index where the ITEM should be placed (based on above +search). That means, it's inserted before the next bigger element. + + @l = (2,3,5,7); + binsert { $_ <=> 4 } 4, @l; # @l = (2,3,4,5,7) + binsert { $_ <=> 6 } 42, @l; # @l = (2,3,4,42,7) + +You take care that the inserted element matches the compare result. + +=head3 bremove BLOCK LIST + +=head3 bsearch_remove BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in C<$_>) is smaller, +a positive value if it is bigger and zero if it matches. + +The item at the found position is removed and returned. + + @l = (2,3,4,5,7); + bremove { $_ <=> 4 }, @l; # @l = (2,3,5,7); + =head2 Counting and calculation =head3 true BLOCK LIST @@ -705,6 +979,37 @@ printf "%i item(s) are not defined", false { defined($_) } @list; +=head3 reduce_0 BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +C<$a> contains the progressional result and is initialized with 0. +C<$b> contains the current processed element of LIST and C<$_> contains the +index of the element in C<$b>. + +The idea behind reduce_0 is B (addition of a sequence of numbers). + +=head3 reduce_1 BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +C<$a> contains the progressional result and is initialized with 1. +C<$b> contains the current processed element of LIST and C<$_> contains the +index of the element in C<$b>. + +The idea behind reduce_1 is product of a sequence of numbers. + +=head3 reduce_u BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +C<$a> contains the progressional result and is uninitialized. +C<$b> contains the current processed element of LIST and C<$_> contains the +index of the element in C<$b>. + +This function has been added if one might need the extra of the index +value but need an individual initialization. + +B: In most cases L will do the +job better. + =head3 minmax LIST Calculates the minimum and maximum of LIST and returns a two element list with @@ -721,6 +1026,14 @@ fairly big in order for C to win over a naive implementation. This limitation does not apply to the XS version. +=head3 minmaxstr LIST + +Computes the minimum and maximum of LIST using string compare and returns a +two element list with the first element being the minimum and the second the +maximum. Returns the empty list if LIST was empty. + +The implementation is similar to C. + =head1 ENVIRONMENT When C is set, the module will always use the pure-Perl @@ -909,16 +1222,6 @@ =over 4 -=item * List::Util export pass-through - -Allow B to pass-through the regular L -functions to end users only need to C the one module. - -=item * uniq_by(&@) - -Use code-reference to extract a key based on which the uniqueness is -determined. Suggested by Aaron Crane. - =item * delete_index =item * random_item @@ -960,11 +1263,23 @@ Copyright 2004 - 2010 by Tassilo von Parseval -Copyright 2013 - 2016 by Jens Rehsack +Copyright 2013 - 2017 by Jens Rehsack -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.4 or, -at your option, any later version of Perl 5 you may have available. +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. =cut diff -Nru liblist-moreutils-perl-0.416/LICENSE liblist-moreutils-perl-0.430/LICENSE --- liblist-moreutils-perl-0.416/LICENSE 2016-03-07 19:53:22.000000000 +0000 +++ liblist-moreutils-perl-0.430/LICENSE 2020-10-02 06:22:44.000000000 +0000 @@ -1,16 +1,201 @@ -This software is licensed under the same terms as Perl5 itself. -At the time of writing this means, you can redistribute it and/or -modify it under the terms of either: - - a) the GNU General Public License as published by the Free - Software Foundation; either version 1, or (at your option) any - later version, or - - b) the "Artistic License" - -which both comes with this Kit. - -This software is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either -the GNU General Public License or the Artistic License for more details. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff -Nru liblist-moreutils-perl-0.416/Makefile.PL liblist-moreutils-perl-0.430/Makefile.PL --- liblist-moreutils-perl-0.416/Makefile.PL 2016-07-06 14:07:07.000000000 +0000 +++ liblist-moreutils-perl-0.430/Makefile.PL 2020-10-21 13:41:34.000000000 +0000 @@ -3,69 +3,42 @@ use strict; use warnings; -require 5.006; +use 5.008_001; + +use Config; +use ExtUtils::MakeMaker; BEGIN { - # to operate Capture::Tiny under perl 5.6 - eval "use Scalar::Util qw();"; - $@ and eval <<'EOSU'; -$INC{'Scalar/Util.pm'} = 'faked'; -package Scalar::Util; -use base "Exporter"; -# from PP part of Params::Util -our @EXPORT = qw(reftype blessed looks_like_number); -sub reftype { ref $_[0] } -my %types = ( - CODE => 1, - GLOB => 1, - REF => 1, - SCALAR => 1, - HASH => 1, - ARRAY => 1 -); -sub blessed { - my $t = ref $_[0]; - defined $t or return; - defined $types{$t} or return; - $t; -} -# from PP part of Params::Util -sub looks_like_number { - local $_ = shift; - - # checks from perlfaq4 - return 0 if !defined($_); - if (ref($_)) { - return overload::Overloaded($_) ? defined(0 + $_) : 0; + unless (grep { $_ eq "." } @INC) + { + use lib "."; } - return 1 if (/^[+-]?[0-9]+$/); # is a +/- integer - return 1 if (/^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/); # a C float - return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i); - - 0; -} -EOSU } use inc::latest 'Capture::Tiny'; use inc::latest 'Config::AutoConf'; -if ( inc::latest->can("write") ) +if (inc::latest->can("write")) { inc::latest->write("inc"); - for my $mod ( inc::latest->loaded_modules ) + for my $mod (inc::latest->loaded_modules) { - inc::latest->bundle_module( $mod, "inc" ); + inc::latest->bundle_module($mod, "inc"); } } -use ExtUtils::MakeMaker; - use inc::Config::AutoConf::LMU (); -if ( -d "Sandbox" ) +inc::Config::AutoConf::LMU->_set_argv(@ARGV); # XXX hack because we cannot construct for global use +my $loadable_xs = inc::Config::AutoConf::LMU->check_produce_loadable_xs_build(); + +if (-d "Sandbox") { + unless (grep { $_ eq "." } @INC) + { + use lib "."; + } eval "use Sandbox::Tumble ();"; $@ and die $@; eval "use File::Path ();"; @@ -75,39 +48,53 @@ Sandbox::Tumble->tumble(qw(t)); } -inc::Config::AutoConf::LMU->_set_argv(@ARGV); # XXX hack because we cannot construct for global use +my $conflictMsg = <check_produce_loadable_xs_build(); - -# Should we build the XS version? my %RUN_DEPS = ( - 'XSLoader' => "0.22", 'Exporter::Tiny' => '0.038', + ($loadable_xs ? ('List::MoreUtils::XS' => '0.430') : ()) ); my %BUNDLE_CONFIGURE_DEPS = ( 'inc::latest' => '0.500', - 'Config::AutoConf' => '0.308', + 'Config::AutoConf' => '0.315', ); my %CONFIGURE_DEPS = ( - 'Carp' => 0, 'ExtUtils::MakeMaker' => 0, - 'File::Basename' => 0, - 'File::Copy' => 0, - 'File::Path' => 0, - 'File::Spec' => 0, - 'IPC::Cmd' => 0, - 'base' => 0, ); -my %BUILD_DEPS = (); - my %TEST_DEPS = ( + 'Storable' => 0, 'Test::More' => 0.96, ); -my @XS_FILES = qw(MoreUtils.xs); +my %CONFLICTS = ( + 'List::MoreUtils' => '0.416', + 'List::MoreUtils::PP' => '0.416', + 'List::MoreUtils::XS' => '0.416', +); WriteMakefile1( META_MERGE => { - 'meta-spec' => { version => 2 }, + 'meta-spec' => {version => 2}, resources => { homepage => 'https://metacpan.org/release/List-MoreUtils', repository => { @@ -119,36 +106,34 @@ web => 'https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils', mailto => 'bug-List-MoreUtils@rt.cpan.org', }, - license => 'http://dev.perl.org/licenses/', + license => 'apache_2_0', }, prereqs => { develop => { requires => { + %BUNDLE_CONFIGURE_DEPS, 'Test::CPAN::Changes' => 0, 'Test::CheckManifest' => 0, 'Module::CPANTS::Analyse' => '0.96', 'Test::Kwalitee' => 0, + 'Test::Perl::Critic' => 0, + 'Test::PerlTidy' => 0, 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, 'Test::Pod::Spelling::CommonMistakes' => 0, 'Test::Spelling' => 0, - 'JSON::PP' => 0, - 'Test::WriteVariants' => '0.010', - %BUNDLE_CONFIGURE_DEPS, + 'Test::WriteVariants' => '0.014', }, }, configure => { requires => {%CONFIGURE_DEPS}, - recommends => {%BUNDLE_CONFIGURE_DEPS}, - }, - build => { requires => {%BUILD_DEPS} }, - test => { - requires => {%TEST_DEPS}, - recommends => { 'Test::LeakTrace' => 0 } + recommends => {'Config::AutoConf' => '0.315'} }, - runtime => { - requires => { %RUN_DEPS, }, + test => { + requires => {%TEST_DEPS}, + requires => {'Test::LeakTrace' => 0} }, + runtime => {requires => {%RUN_DEPS}}, }, }, NAME => 'List::MoreUtils', @@ -159,63 +144,104 @@ 'Adam Kennedy ', 'Jens Rehsack ' ], - LICENSE => 'perl', + LICENSE => 'apache_2_0', CONFIGURE_REQUIRES => \%CONFIGURE_DEPS, + CONFLICTS => \%CONFLICTS, PREREQ_PM => \%RUN_DEPS, - BUILD_REQUIRES => \%BUILD_DEPS, TEST_REQUIRES => \%TEST_DEPS, - ( - $loadable_xs - ? ( - XS => { map { ( my $tgt = $_ ) =~ s/\.xs$/\.c/; $_ => $tgt; } @XS_FILES }, - MAGICXS => 1, - INC => "-I." - ) - : () - ), - ( -d ".git" ? ( realclean => { FILES => "inc/latest* inc/inc_* t/pureperl t/xs" } ) : () ), - depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }, - test => { TESTS => join( ' ', 't/*.t', 't/pureperl/*.t', ( $loadable_xs ? 't/xs/*.t' : () ), 'xt/*.t' ) }, + (-d "Sandbox" ? (realclean => {FILES => "t/pureperl t/xs M*.bak"}) : ()), + depend => {'$(FIRST_MAKEFILE)' => '$(VERSION_FROM)'}, + test => {TESTS => join(' ', 't/*.t', 't/pureperl/*.t', ($loadable_xs ? 't/xs/*.t' : ()), 'xt/*.t')}, # Otherwise 'cxinc' isn't defined - ( $] < 5.012 ? ( DEFINE => '-DPERL_EXT' ) : (), ), + ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), ); +sub CheckConflicts +{ + my %params = @_; + my %conflicts = %{$params{CONFLICTS}}; + my $found = 0; + my @kill; + + while (my ($module, $version) = each(%conflicts)) + { + undef $@; + eval "require $module"; + next if $@; + my $installed = eval "\$" . $module . "::VERSION"; + if ($installed le $version) + { + ++$found; + if ($module eq "List::MoreUtils" or $module eq "List::MoreUtils::PP") + { + (my $modfile = "${module}.pm") =~ s,::,/,g; + warn sprintf($selfConflictMsg, $params{NAME}, $module, $installed, $INC{$modfile}); + push @kill, $modfile; + } + else + { + warn sprintf($conflictMsg, $params{NAME}, $module, $installed, $params{NAME}); + } + + } + } + + if (@kill) + { + + package MY; + no warnings 'once'; + + *install = sub { + my $self = shift; + (my $targets = $self->SUPER::install) =~ s/^(pure_site_install\s+::?)/$1 delete_conflicting_files/m; + return "\ndelete_conflicting_files :\n" + . join("", + map { "\t\$(NOECHO) \$(RM_F) " . $self->quote_literal($self->catfile('$(DESTINSTALLSITEARCH)', $_)) . "\n" } + @kill) + . $targets; + }; + } + + return !$found; +} + sub WriteMakefile1 { # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params = @_; my $eumm_version = $ExtUtils::MakeMaker::VERSION; $eumm_version = eval $eumm_version; - die "EXTRA_META is deprecated" if ( exists( $params{EXTRA_META} ) ); - die "License not specified" if ( !exists( $params{LICENSE} ) ); + die "EXTRA_META is deprecated" if (exists($params{EXTRA_META})); + die "License not specified" if (!exists($params{LICENSE})); $params{TEST_REQUIRES} and $eumm_version < 6.6303 - and $params{BUILD_REQUIRES} = { %{ $params{BUILD_REQUIRES} || {} }, %{ delete $params{TEST_REQUIRES} } }; + and $params{BUILD_REQUIRES} = {%{$params{BUILD_REQUIRES} || {}}, %{delete $params{TEST_REQUIRES}}}; #EUMM 6.5502 has problems with BUILD_REQUIRES $params{BUILD_REQUIRES} and $eumm_version < 6.5503 - and $params{PREREQ_PM} = { %{ $params{PREREQ_PM} || {} }, %{ delete $params{BUILD_REQUIRES} } }; + and $params{PREREQ_PM} = {%{$params{PREREQ_PM} || {}}, %{delete $params{BUILD_REQUIRES}}}; ref $params{AUTHOR} and "ARRAY" eq ref $params{AUTHOR} and $eumm_version < 6.5702 - and $params{AUTHOR} = join( ", ", @{ $params{AUTHOR} } ); - delete $params{CONFIGURE_REQUIRES} if ( $eumm_version < 6.52 ); - delete $params{MIN_PERL_VERSION} if ( $eumm_version < 6.48 ); - delete $params{META_MERGE} if ( $eumm_version < 6.46 ); - delete $params{META_ADD}{prereqs} if ( $eumm_version < 6.58 ); - delete $params{META_ADD}{'meta-spec'} if ( $eumm_version < 6.58 ); - delete $params{META_ADD} if ( $eumm_version < 6.46 ); - delete $params{LICENSE} if ( $eumm_version < 6.31 ); - delete $params{AUTHOR} if ( $] < 5.005 ); - delete $params{ABSTRACT_FROM} if ( $] < 5.005 ); - delete $params{BINARY_LOCATION} if ( $] < 5.005 ); + and $params{AUTHOR} = join(", ", @{$params{AUTHOR}}); + delete $params{CONFIGURE_REQUIRES} if ($eumm_version < 6.52); + delete $params{MIN_PERL_VERSION} if ($eumm_version < 6.48); + delete $params{META_MERGE} if ($eumm_version < 6.46); + delete $params{META_ADD}{prereqs} if ($eumm_version < 6.58); + delete $params{META_ADD}{'meta-spec'} if ($eumm_version < 6.58); + delete $params{META_ADD} if ($eumm_version < 6.46); + delete $params{LICENSE} if ($eumm_version < 6.31); + delete $params{AUTHOR} if ($] < 5.005); + delete $params{ABSTRACT_FROM} if ($] < 5.005); + delete $params{BINARY_LOCATION} if ($] < 5.005); - # more or less taken from Moose' Makefile.PL - if ( $params{CONFLICTS} ) + # more or less taken from SQL::Statement's Makefile.PL + if ($params{CONFLICTS}) { my $ok = CheckConflicts(%params); - exit(0) if ( $params{PREREQ_FATAL} and not $ok ); + exit(0) if ($params{PREREQ_FATAL} and not $ok); my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV; - unless ( $cpan_smoker || $ENV{PERL_MM_USE_DEFAULT} ) + unless ($cpan_smoker || $ENV{PERL_MM_USE_DEFAULT}) { sleep 4 unless ($ok); } diff -Nru liblist-moreutils-perl-0.416/MANIFEST liblist-moreutils-perl-0.430/MANIFEST --- liblist-moreutils-perl-0.416/MANIFEST 2016-07-06 14:22:45.000000000 +0000 +++ liblist-moreutils-perl-0.430/MANIFEST 2020-10-21 14:47:11.000000000 +0000 @@ -1,6 +1,6 @@ +.perltidyrc ARTISTIC-1.0 Changes -dhash.h GPL-1 inc/Config/AutoConf/LMU.pm inc/inc_Capture-Tiny/Capture/Tiny.pm @@ -10,26 +10,196 @@ lib/List/MoreUtils.pm lib/List/MoreUtils/Contributing.pod lib/List/MoreUtils/PP.pm -lib/List/MoreUtils/XS.pm LICENSE Makefile.PL MANIFEST This list of files -MoreUtils.xs -multicall.h -ppport.h +MANIFEST.SKIP README.md -t/lib/LMU/Test/ab.pm -t/lib/LMU/Test/Functions.pm -t/lib/LMU/Test/Import.pm -t/lib/LMU/Test/XS.pm +t/.perltidyrc +t/inline/after.pm +t/inline/after_incl.pm +t/inline/all.pm +t/inline/all_u.pm +t/inline/any.pm +t/inline/any_u.pm +t/inline/apply.pm +t/inline/arrayify.pm +t/inline/before.pm +t/inline/before_incl.pm +t/inline/binsert.pm +t/inline/bremove.pm +t/inline/bsearch.pm +t/inline/bsearchidx.pm +t/inline/duplicates.pm +t/inline/each_array.pm +t/inline/equal_range.pm +t/inline/false.pm +t/inline/firstidx.pm +t/inline/firstres.pm +t/inline/firstval.pm +t/inline/frequency.pm +t/inline/Import.pm +t/inline/indexes.pm +t/inline/insert_after.pm +t/inline/insert_after_string.pm +t/inline/lastidx.pm +t/inline/lastres.pm +t/inline/lastval.pm +t/inline/listcmp.pm +t/inline/lower_bound.pm +t/inline/mesh.pm +t/inline/minmax.pm +t/inline/minmaxstr.pm +t/inline/mode.pm +t/inline/natatime.pm +t/inline/none.pm +t/inline/none_u.pm +t/inline/notall.pm +t/inline/notall_u.pm +t/inline/occurrences.pm +t/inline/one.pm +t/inline/one_u.pm +t/inline/onlyidx.pm +t/inline/onlyres.pm +t/inline/onlyval.pm +t/inline/pairwise.pm +t/inline/part.pm +t/inline/qsort.pm +t/inline/reduce_0.pm +t/inline/reduce_1.pm +t/inline/reduce_u.pm +t/inline/samples.pm +t/inline/singleton.pm +t/inline/slide.pm +t/inline/slideatatime.pm +t/inline/true.pm +t/inline/uniq.pm +t/inline/upper_bound.pm +t/inline/XS.pm +t/inline/zip6.pm t/lib/Test/LMU.pm -t/pureperl/ab.t -t/pureperl/Functions.t +t/LICENSE +t/pureperl/after.t +t/pureperl/after_incl.t +t/pureperl/all.t +t/pureperl/all_u.t +t/pureperl/any.t +t/pureperl/any_u.t +t/pureperl/apply.t +t/pureperl/arrayify.t +t/pureperl/before.t +t/pureperl/before_incl.t +t/pureperl/binsert.t +t/pureperl/bremove.t +t/pureperl/bsearch.t +t/pureperl/bsearchidx.t +t/pureperl/duplicates.t +t/pureperl/each_array.t +t/pureperl/equal_range.t +t/pureperl/false.t +t/pureperl/firstidx.t +t/pureperl/firstres.t +t/pureperl/firstval.t +t/pureperl/frequency.t t/pureperl/Import.t +t/pureperl/indexes.t +t/pureperl/insert_after.t +t/pureperl/insert_after_string.t +t/pureperl/lastidx.t +t/pureperl/lastres.t +t/pureperl/lastval.t +t/pureperl/listcmp.t +t/pureperl/lower_bound.t +t/pureperl/mesh.t +t/pureperl/minmax.t +t/pureperl/minmaxstr.t +t/pureperl/mode.t +t/pureperl/natatime.t +t/pureperl/none.t +t/pureperl/none_u.t +t/pureperl/notall.t +t/pureperl/notall_u.t +t/pureperl/occurrences.t +t/pureperl/one.t +t/pureperl/one_u.t +t/pureperl/onlyidx.t +t/pureperl/onlyres.t +t/pureperl/onlyval.t +t/pureperl/pairwise.t +t/pureperl/part.t +t/pureperl/qsort.t +t/pureperl/reduce_0.t +t/pureperl/reduce_1.t +t/pureperl/reduce_u.t +t/pureperl/samples.t +t/pureperl/singleton.t +t/pureperl/slide.t +t/pureperl/slideatatime.t +t/pureperl/true.t +t/pureperl/uniq.t +t/pureperl/upper_bound.t t/pureperl/XS.t -t/xs/ab.t -t/xs/Functions.t +t/pureperl/zip6.t +t/xs/after.t +t/xs/after_incl.t +t/xs/all.t +t/xs/all_u.t +t/xs/any.t +t/xs/any_u.t +t/xs/apply.t +t/xs/arrayify.t +t/xs/before.t +t/xs/before_incl.t +t/xs/binsert.t +t/xs/bremove.t +t/xs/bsearch.t +t/xs/bsearchidx.t +t/xs/duplicates.t +t/xs/each_array.t +t/xs/equal_range.t +t/xs/false.t +t/xs/firstidx.t +t/xs/firstres.t +t/xs/firstval.t +t/xs/frequency.t t/xs/Import.t +t/xs/indexes.t +t/xs/insert_after.t +t/xs/insert_after_string.t +t/xs/lastidx.t +t/xs/lastres.t +t/xs/lastval.t +t/xs/listcmp.t +t/xs/lower_bound.t +t/xs/mesh.t +t/xs/minmax.t +t/xs/minmaxstr.t +t/xs/mode.t +t/xs/natatime.t +t/xs/none.t +t/xs/none_u.t +t/xs/notall.t +t/xs/notall_u.t +t/xs/occurrences.t +t/xs/one.t +t/xs/one_u.t +t/xs/onlyidx.t +t/xs/onlyres.t +t/xs/onlyval.t +t/xs/pairwise.t +t/xs/part.t +t/xs/qsort.t +t/xs/reduce_0.t +t/xs/reduce_1.t +t/xs/reduce_u.t +t/xs/samples.t +t/xs/singleton.t +t/xs/slide.t +t/xs/slideatatime.t +t/xs/true.t +t/xs/uniq.t +t/xs/upper_bound.t t/xs/XS.t +t/xs/zip6.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) diff -Nru liblist-moreutils-perl-0.416/MANIFEST.SKIP liblist-moreutils-perl-0.430/MANIFEST.SKIP --- liblist-moreutils-perl-0.416/MANIFEST.SKIP 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/MANIFEST.SKIP 2020-10-05 09:34:29.000000000 +0000 @@ -0,0 +1,42 @@ +\B\.svn\b +\B\.git\b +\.gitignore$ +\.[Bb][Aa][Kk]$ +\.orig$ +\.old$ +\.tdy$ +\.tmp$ +\.log$ +\..*sw. +^Makefile$ +^Build$ +^Build\.bat$ +cover_db/ +\.Inline/.* +_Inline/.* +\.bak$ +\.tar$ +\.tgz$ +\.tar\.gz$ +^mess/ +^tmp/ +^testdata/ +^blib/ +^sandbox/ +^pm_to_blib$ +^cover_db/ +nytprof*/ +nytprof.out +^_build/.* +~$ +.*\.planner +.*\.lock +LMUconfig\.h +\.travis\.yml +\.gitmodules +^List-MoreUtils-.* +\bxt +\.[icos] +\.bs +^MYMETA.* +Sandbox diff -Nru liblist-moreutils-perl-0.416/META.json liblist-moreutils-perl-0.430/META.json --- liblist-moreutils-perl-0.416/META.json 2016-07-06 14:22:45.000000000 +0000 +++ liblist-moreutils-perl-0.430/META.json 2020-10-21 14:47:11.000000000 +0000 @@ -6,13 +6,13 @@ "Jens Rehsack " ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 7.14, CPAN::Meta::Converter version 2.150005", + "generated_by" : "ExtUtils::MakeMaker version 7.46, CPAN::Meta::Converter version 2.150010", "license" : [ - "perl_5" + "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", - "version" : "2" + "version" : 2 }, "name" : "List-MoreUtils", "no_index" : { @@ -23,51 +23,45 @@ }, "prereqs" : { "build" : { - "requires" : {} + "requires" : { + "ExtUtils::MakeMaker" : "0" + } }, "configure" : { "recommends" : { - "Config::AutoConf" : "0.308", - "inc::latest" : "0.500" + "Config::AutoConf" : "0.315" }, "requires" : { - "Carp" : "0", - "ExtUtils::MakeMaker" : "0", - "File::Basename" : "0", - "File::Copy" : "0", - "File::Path" : "0", - "File::Spec" : "0", - "IPC::Cmd" : "0", - "base" : "0" + "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { - "Config::AutoConf" : "0.308", - "JSON::PP" : "0", + "Config::AutoConf" : "0.315", "Module::CPANTS::Analyse" : "0.96", "Test::CPAN::Changes" : "0", "Test::CheckManifest" : "0", "Test::Kwalitee" : "0", + "Test::Perl::Critic" : "0", + "Test::PerlTidy" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0", - "Test::WriteVariants" : "0.010", + "Test::WriteVariants" : "0.014", "inc::latest" : "0.500" } }, "runtime" : { "requires" : { "Exporter::Tiny" : "0.038", - "XSLoader" : "0.22" + "List::MoreUtils::XS" : "0.430" } }, "test" : { - "recommends" : { - "Test::LeakTrace" : "0" - }, "requires" : { + "Storable" : "0", + "Test::LeakTrace" : "0", "Test::More" : "0.96" } } @@ -79,15 +73,12 @@ "web" : "https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils" }, "homepage" : "https://metacpan.org/release/List-MoreUtils", - "license" : [ - "http://dev.perl.org/licenses/" - ], "repository" : { "type" : "git", "url" : "https://github.com/perl5-utils/List-MoreUtils.git", "web" : "https://github.com/perl5-utils/List-MoreUtils" } }, - "version" : "0.416", - "x_serialization_backend" : "JSON::PP version 2.27400" + "version" : "0.430", + "x_serialization_backend" : "JSON::PP version 4.05" } diff -Nru liblist-moreutils-perl-0.416/META.yml liblist-moreutils-perl-0.430/META.yml --- liblist-moreutils-perl-0.416/META.yml 2016-07-06 14:22:45.000000000 +0000 +++ liblist-moreutils-perl-0.430/META.yml 2020-10-21 14:47:11.000000000 +0000 @@ -5,19 +5,15 @@ - 'Adam Kennedy ' - 'Jens Rehsack ' build_requires: + ExtUtils::MakeMaker: '0' + Storable: '0' + Test::LeakTrace: '0' Test::More: '0.96' configure_requires: - Carp: '0' ExtUtils::MakeMaker: '0' - File::Basename: '0' - File::Copy: '0' - File::Path: '0' - File::Spec: '0' - IPC::Cmd: '0' - base: '0' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 7.14, CPAN::Meta::Converter version 2.150005' -license: perl +generated_by: 'ExtUtils::MakeMaker version 7.46, CPAN::Meta::Converter version 2.150010' +license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' @@ -28,11 +24,10 @@ - inc requires: Exporter::Tiny: '0.038' - XSLoader: '0.22' + List::MoreUtils::XS: '0.430' resources: bugtracker: https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils homepage: https://metacpan.org/release/List-MoreUtils - license: http://dev.perl.org/licenses/ repository: https://github.com/perl5-utils/List-MoreUtils.git -version: '0.416' +version: '0.430' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -Nru liblist-moreutils-perl-0.416/MoreUtils.xs liblist-moreutils-perl-0.430/MoreUtils.xs --- liblist-moreutils-perl-0.416/MoreUtils.xs 2016-04-12 13:30:28.000000000 +0000 +++ liblist-moreutils-perl-0.430/MoreUtils.xs 1970-01-01 00:00:00.000000000 +0000 @@ -1,1813 +0,0 @@ -#define PERL_NO_GET_CONTEXT -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" -#include "multicall.h" -#include "ppport.h" - -#ifndef aTHX -# define aTHX -# define pTHX -#endif - -#ifdef SVf_IVisUV -# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv)) -#else -# define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : (SvNV(sv)) -#endif - -/* - * Perl < 5.18 had some kind of different SvIV_please_nomg - */ -#if PERL_VERSION < 18 -#undef SvIV_please_nomg -# define SvIV_please_nomg(sv) \ - (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv)) \ - ? (SvIV_nomg(sv), SvIOK(sv)) \ - : SvIOK(sv)) -#endif - -/* compare left and right SVs. Returns: - * -1: < - * 0: == - * 1: > - * 2: left or right was a NaN - */ -static I32 -LMUncmp(pTHX_ SV* left, SV * right) -{ - /* Fortunately it seems NaN isn't IOK */ - if(SvAMAGIC(left) || SvAMAGIC(right)) - return SvIVX(amagic_call(left, right, ncmp_amg, 0)); - - if (SvIV_please_nomg(right) && SvIV_please_nomg(left)) { - if (!SvUOK(left)) { - const IV leftiv = SvIVX(left); - if (!SvUOK(right)) { - /* ## IV <=> IV ## */ - const IV rightiv = SvIVX(right); - return (leftiv > rightiv) - (leftiv < rightiv); - } - /* ## IV <=> UV ## */ - if (leftiv < 0) - /* As (b) is a UV, it's >=0, so it must be < */ - return -1; - { - const UV rightuv = SvUVX(right); - return ((UV)leftiv > rightuv) - ((UV)leftiv < rightuv); - } - } - - if (SvUOK(right)) { - /* ## UV <=> UV ## */ - const UV leftuv = SvUVX(left); - const UV rightuv = SvUVX(right); - return (leftuv > rightuv) - (leftuv < rightuv); - } - /* ## UV <=> IV ## */ - { - const IV rightiv = SvIVX(right); - if (rightiv < 0) - /* As (a) is a UV, it's >=0, so it cannot be < */ - return 1; - { - const UV leftuv = SvUVX(left); - return (leftuv > (UV)rightiv) - (leftuv < (UV)rightiv); - } - } - assert(0); /* NOTREACHED */ - } - else - { -#ifdef SvNV_nomg - NV const rnv = SvNV_nomg(right); - NV const lnv = SvNV_nomg(left); -#else - NV const rnv = slu_sv_value(right); - NV const lnv = slu_sv_value(left); -#endif - -#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan) - if (Perl_isnan(lnv) || Perl_isnan(rnv)) { - return 2; - } - return (lnv > rnv) - (lnv < rnv); -#else - if (lnv < rnv) - return -1; - if (lnv > rnv) - return 1; - if (lnv == rnv) - return 0; - return 2; -#endif - } -} - -#define ncmp(left,right) LMUncmp(aTHX_ left,right) - -#define FUNC_NAME GvNAME(GvEGV(ST(items))) - -/* shameless stolen from PadWalker */ -#ifndef PadARRAY -typedef AV PADNAMELIST; -typedef SV PADNAME; -# if PERL_VERSION < 8 || (PERL_VERSION == 8 && !PERL_SUBVERSION) -typedef AV PADLIST; -typedef AV PAD; -# endif -# define PadlistARRAY(pl) ((PAD **)AvARRAY(pl)) -# define PadlistMAX(pl) AvFILLp(pl) -# define PadlistNAMES(pl) (*PadlistARRAY(pl)) -# define PadnamelistARRAY(pnl) ((PADNAME **)AvARRAY(pnl)) -# define PadnamelistMAX(pnl) AvFILLp(pnl) -# define PadARRAY AvARRAY -# define PadnameIsOUR(pn) !!(SvFLAGS(pn) & SVpad_OUR) -# define PadnameOURSTASH(pn) SvOURSTASH(pn) -# define PadnameOUTER(pn) !!SvFAKE(pn) -# define PadnamePV(pn) (SvPOKp(pn) ? SvPVX(pn) : NULL) -#endif -#ifndef PadnameSV -# define PadnameSV(pn) pn -#endif -#ifndef PadnameFLAGS -# define PadnameFLAGS(pn) (SvFLAGS(PadnameSV(pn))) -#endif - -static int -in_pad (pTHX_ SV *code) -{ - GV *gv; - HV *stash; - CV *cv = sv_2cv(code, &stash, &gv, 0); - PADLIST *pad_list = (CvPADLIST(cv)); - PADNAMELIST *pad_namelist = PadlistNAMES(pad_list); - PADNAME **pad_names = PadnamelistARRAY(pad_namelist); - int i; - - for (i=PadnamelistMAX(pad_namelist); i>=0; --i) { - PADNAME* name_sv = PadnamelistARRAY(pad_namelist)[i]; - if (name_sv) { - char *name_str = PadnamePV(name_sv); - if (name_str) { - - /* perl < 5.6.0 does not yet have our */ -# ifdef SVpad_OUR - if(PadnameIsOUR(name_sv)) - continue; -# endif - - if (!(PadnameFLAGS(name_sv)) & SVf_OK) - continue; - - if (strEQ(name_str, "$a") || strEQ(name_str, "$b")) - return 1; - } - } - } - return 0; -} - -#define WARN_OFF \ - SV *oldwarn = PL_curcop->cop_warnings; \ - PL_curcop->cop_warnings = pWARN_NONE; - -#define WARN_ON \ - PL_curcop->cop_warnings = oldwarn; - -#define EACH_ARRAY_BODY \ - int i; \ - arrayeach_args * args; \ - HV *stash = gv_stashpv("List::MoreUtils_ea", TRUE); \ - CV *closure = newXS(NULL, XS_List__MoreUtils__array_iterator, __FILE__); \ - \ - /* prototype */ \ - sv_setpv((SV*)closure, ";$"); \ - \ - New(0, args, 1, arrayeach_args); \ - New(0, args->avs, items, AV*); \ - args->navs = items; \ - args->curidx = 0; \ - \ - for (i = 0; i < items; i++) { \ - if(!arraylike(ST(i))) \ - croak_xs_usage(cv, "\\@;\\@\\@..."); \ - args->avs[i] = (AV*)SvRV(ST(i)); \ - SvREFCNT_inc(args->avs[i]); \ - } \ - \ - CvXSUBANY(closure).any_ptr = args; \ - RETVAL = newRV_noinc((SV*)closure); \ - \ - /* in order to allow proper cleanup in DESTROY-handler */ \ - sv_bless(RETVAL, stash) - - -#define FOR_EACH(on_item) \ - if(!codelike(code)) \ - croak_xs_usage(cv, "code, ..."); \ - \ - if (items > 1) { \ - dMULTICALL; \ - int i; \ - HV *stash; \ - GV *gv; \ - CV *_cv; \ - SV **args = &PL_stack_base[ax]; \ - I32 gimme = G_SCALAR; \ - _cv = sv_2cv(code, &stash, &gv, 0); \ - PUSH_MULTICALL(_cv); \ - SAVESPTR(GvSV(PL_defgv)); \ - \ - for(i = 1 ; i < items ; ++i) { \ - GvSV(PL_defgv) = args[i]; \ - MULTICALL; \ - on_item; \ - } \ - POP_MULTICALL; \ - } - -#define TRUE_JUNCTION \ - FOR_EACH(if (SvTRUE(*PL_stack_sp)) ON_TRUE) \ - else ON_EMPTY; - -#define FALSE_JUNCTION \ - FOR_EACH(if (!SvTRUE(*PL_stack_sp)) ON_FALSE) \ - else ON_EMPTY; - -/* #include "dhash.h" */ - -/* need this one for array_each() */ -typedef struct { - AV **avs; /* arrays over which to iterate in parallel */ - int navs; /* number of arrays */ - int curidx; /* the current index of the iterator */ -} arrayeach_args; - -/* used for natatime */ -typedef struct { - SV **svs; - int nsvs; - int curidx; - int natatime; -} natatime_args; - -static void -insert_after (pTHX_ int idx, SV *what, AV *av) { - int i, len; - av_extend(av, (len = av_len(av) + 1)); - - for (i = len; i > idx+1; i--) { - SV **sv = av_fetch(av, i-1, FALSE); - SvREFCNT_inc(*sv); - av_store(av, i, *sv); - } - if (!av_store(av, idx+1, what)) - SvREFCNT_dec(what); -} - -static int -is_like(pTHX_ SV *sv, const char *like) -{ - int likely = 0; - if( sv_isobject( sv ) ) - { - dSP; - int count; - - ENTER; - SAVETMPS; - PUSHMARK(SP); - XPUSHs( sv_2mortal( newSVsv( sv ) ) ); - XPUSHs( sv_2mortal( newSVpv( like, strlen(like) ) ) ); - PUTBACK; - - if( ( count = call_pv("overload::Method", G_SCALAR) ) ) - { - I32 ax; - SPAGAIN; - - SP -= count; - ax = (SP - PL_stack_base) + 1; - if( SvTRUE(ST(0)) ) - ++likely; - } - - PUTBACK; - FREETMPS; - LEAVE; - } - - return likely; -} - -static int -is_array(SV *sv) -{ - return SvROK(sv) && ( SVt_PVAV == SvTYPE(SvRV(sv) ) ); -} - -static int -LMUcodelike(pTHX_ SV *code) -{ - SvGETMAGIC(code); - return SvROK(code) && ( ( SVt_PVCV == SvTYPE(SvRV(code)) ) || ( is_like(aTHX_ code, "&{}" ) ) ); -} - -#define codelike(code) LMUcodelike(aTHX_ code) - -static int -LMUarraylike(pTHX_ SV *array) -{ - SvGETMAGIC(array); - return is_array(array) || is_like(aTHX_ array, "@{}" ); -} - -#define arraylike(array) LMUarraylike(aTHX_ array) - -MODULE = List::MoreUtils_ea PACKAGE = List::MoreUtils_ea - -void -DESTROY(sv) - SV *sv; - CODE: - { - int i; - CV *code = (CV*)SvRV(sv); - arrayeach_args *args = (arrayeach_args *)(CvXSUBANY(code).any_ptr); - if (args) { - for (i = 0; i < args->navs; ++i) - SvREFCNT_dec(args->avs[i]); - Safefree(args->avs); - Safefree(args); - CvXSUBANY(code).any_ptr = NULL; - } - } - - -MODULE = List::MoreUtils_na PACKAGE = List::MoreUtils_na - -void -DESTROY(sv) - SV *sv; - CODE: - { - int i; - CV *code = (CV*)SvRV(sv); - natatime_args *args = (natatime_args *)(CvXSUBANY(code).any_ptr); - if (args) { - for (i = 0; i < args->nsvs; ++i) - SvREFCNT_dec(args->svs[i]); - Safefree(args->svs); - Safefree(args); - CvXSUBANY(code).any_ptr = NULL; - } - } - -MODULE = List::MoreUtils PACKAGE = List::MoreUtils - -void -any (code,...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_TRUE { POP_MULTICALL; XSRETURN_YES; } -#define ON_EMPTY XSRETURN_NO - TRUE_JUNCTION; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_TRUE -} - -void -all (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_FALSE { POP_MULTICALL; XSRETURN_NO; } -#define ON_EMPTY XSRETURN_YES - FALSE_JUNCTION; - XSRETURN_YES; -#undef ON_EMPTY -#undef ON_FALSE -} - - -void -none (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_TRUE { POP_MULTICALL; XSRETURN_NO; } -#define ON_EMPTY XSRETURN_YES - TRUE_JUNCTION; - XSRETURN_YES; -#undef ON_EMPTY -#undef ON_TRUE -} - -void -notall (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_FALSE { POP_MULTICALL; XSRETURN_YES; } -#define ON_EMPTY XSRETURN_NO - FALSE_JUNCTION; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_FALSE -} - -void -one (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - int found = 0; -#define ON_TRUE { if (found++) { POP_MULTICALL; XSRETURN_NO; }; } -#define ON_EMPTY XSRETURN_YES - TRUE_JUNCTION; - if (found) - XSRETURN_YES; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_TRUE -} - -void -any_u (code,...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_TRUE { POP_MULTICALL; XSRETURN_YES; } -#define ON_EMPTY XSRETURN_UNDEF - TRUE_JUNCTION; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_TRUE -} - -void -all_u (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_FALSE { POP_MULTICALL; XSRETURN_NO; } -#define ON_EMPTY XSRETURN_UNDEF - FALSE_JUNCTION; - XSRETURN_YES; -#undef ON_EMPTY -#undef ON_FALSE -} - - -void -none_u (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_TRUE { POP_MULTICALL; XSRETURN_NO; } -#define ON_EMPTY XSRETURN_UNDEF - TRUE_JUNCTION; - XSRETURN_YES; -#undef ON_EMPTY -#undef ON_TRUE -} - -void -notall_u (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ -#define ON_FALSE { POP_MULTICALL; XSRETURN_YES; } -#define ON_EMPTY XSRETURN_UNDEF - FALSE_JUNCTION; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_FALSE -} - -void -one_u (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - int found = 0; -#define ON_TRUE { if (found++) { POP_MULTICALL; XSRETURN_NO; }; } -#define ON_EMPTY XSRETURN_UNDEF - TRUE_JUNCTION; - if (found) - XSRETURN_YES; - XSRETURN_NO; -#undef ON_EMPTY -#undef ON_TRUE -} - -int -true (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - I32 count = 0; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) count++); - RETVAL = count; -} -OUTPUT: - RETVAL - -int -false (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - I32 count = 0; - FOR_EACH(if (!SvTRUE(*PL_stack_sp)) count++); - RETVAL = count; -} -OUTPUT: - RETVAL - -int -firstidx (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - RETVAL = -1; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { RETVAL = i-1; break; }); -} -OUTPUT: - RETVAL - -SV * -firstval (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - RETVAL = &PL_sv_undef; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { SvREFCNT_inc(RETVAL = args[i]); break; }); -} -OUTPUT: - RETVAL - -SV * -firstres (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - RETVAL = &PL_sv_undef; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { SvREFCNT_inc(RETVAL = *PL_stack_sp); break; }); -} -OUTPUT: - RETVAL - -int -onlyidx (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - int found = 0; - RETVAL = -1; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { if (found++) {RETVAL = -1; break;} RETVAL = i-1; }); -} -OUTPUT: - RETVAL - -SV * -onlyval (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - int found = 0; - RETVAL = &PL_sv_undef; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { if (found++) {SvREFCNT_dec(RETVAL); RETVAL = &PL_sv_undef; break;} SvREFCNT_inc(RETVAL = args[i]); }); -} -OUTPUT: - RETVAL - -SV * -onlyres (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - int found = 0; - RETVAL = &PL_sv_undef; - FOR_EACH(if (SvTRUE(*PL_stack_sp)) { if (found++) {SvREFCNT_dec(RETVAL); RETVAL = &PL_sv_undef; break;}SvREFCNT_inc(RETVAL = *PL_stack_sp); }); -} -OUTPUT: - RETVAL - -int -lastidx (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - RETVAL = -1; - - if (items > 1) { - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = items-1 ; i > 0 ; --i) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - RETVAL = i-1; - break; - } - } - POP_MULTICALL; - } -} -OUTPUT: - RETVAL - -SV * -lastval (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - RETVAL = &PL_sv_undef; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items > 1) { - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = items-1 ; i > 0 ; --i) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - /* see comment in indexes() */ - SvREFCNT_inc(RETVAL = args[i]); - break; - } - } - POP_MULTICALL; - } -} -OUTPUT: - RETVAL - -SV * -lastres (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - RETVAL = &PL_sv_undef; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items > 1) { - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = items-1 ; i > 0 ; --i) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - /* see comment in indexes() */ - SvREFCNT_inc(RETVAL = *PL_stack_sp); - break; - } - } - POP_MULTICALL; - } -} -OUTPUT: - RETVAL - -int -insert_after (code, val, avref) - SV *code; - SV *val; - SV *avref; -PROTOTYPE: &$\@ -CODE: -{ - dMULTICALL; - int i; - int len; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - CV *_cv; - AV *av; - - if(!codelike(code)) - croak_xs_usage(cv, "code, val, \\@area_of_operation"); - if(!arraylike(avref)) - croak_xs_usage(cv, "code, val, \\@area_of_operation"); - - av = (AV*)SvRV(avref); - len = av_len(av); - RETVAL = 0; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 0; i <= len ; ++i) { - GvSV(PL_defgv) = *av_fetch(av, i, FALSE); - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - RETVAL = 1; - break; - } - } - - POP_MULTICALL; - - if (RETVAL) { - SvREFCNT_inc(val); - insert_after(aTHX_ i, val, av); - } -} -OUTPUT: - RETVAL - -int -insert_after_string (string, val, avref) - SV *string; - SV *val; - SV *avref; - PROTOTYPE: $$\@ - CODE: - { - int i; - AV *av; - int len; - SV **sv; - STRLEN slen = 0, alen; - char *str; - char *astr; - RETVAL = 0; - - if(!arraylike(avref)) - croak_xs_usage(cv, "string, val, \\@area_of_operation"); - - av = (AV*)SvRV(avref); - len = av_len(av); - - if (SvTRUE(string)) - str = SvPV(string, slen); - else - str = NULL; - - for (i = 0; i <= len ; i++) { - sv = av_fetch(av, i, FALSE); - if (SvTRUE(*sv)) - astr = SvPV(*sv, alen); - else { - astr = NULL; - alen = 0; - } - if (slen == alen && memcmp(astr, str, slen) == 0) { - RETVAL = 1; - break; - } - } - if (RETVAL) { - SvREFCNT_inc(val); - insert_after(aTHX_ i, val, av); - } - - } - OUTPUT: - RETVAL - -void -apply (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - CV *_cv; - SV **args = &PL_stack_base[ax]; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for(i = 1 ; i < items ; ++i) { - GvSV(PL_defgv) = newSVsv(args[i]); - MULTICALL; - args[i-1] = GvSV(PL_defgv); - } - POP_MULTICALL; - - for(i = 1 ; i < items ; ++i) - sv_2mortal(args[i-1]); - - XSRETURN(items-1); -} - -void -after (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i, j; - HV *stash; - CV *_cv; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 1; i < items; i++) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - break; - } - } - - POP_MULTICALL; - - for (j = i + 1; j < items; ++j) - args[j-i-1] = args[j]; - - j = items-i-1; - XSRETURN(j > 0 ? j : 0); -} - -void -after_incl (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i, j; - HV *stash; - CV *_cv; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 1; i < items; i++) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - break; - } - } - - POP_MULTICALL; - - for (j = i; j < items; j++) - args[j-i] = args[j]; - - XSRETURN(items-i); -} - -void -before (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 1; i < items; i++) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) { - break; - } - args[i-1] = args[i]; - } - - POP_MULTICALL; - - XSRETURN(i-1); -} - -void -before_incl (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 1; i < items; ++i) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - args[i-1] = args[i]; - if (SvTRUE(*PL_stack_sp)) { - ++i; - break; - } - } - - POP_MULTICALL; - - XSRETURN(i-1); -} - -void -indexes (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i, j; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items <= 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for (i = 1, j = 0; i < items; i++) { - GvSV(PL_defgv) = args[i]; - MULTICALL; - if (SvTRUE(*PL_stack_sp)) - /* POP_MULTICALL can free mortal temporaries, so we defer - * mortalising the returned values till after that's been - * done */ - args[j++] = newSViv(i-1); - } - - POP_MULTICALL; - - for (i = 0; i < j; i++) - sv_2mortal(args[i]); - - XSRETURN(j); -} - -void -_array_iterator (method = "") - const char *method; - PROTOTYPE: ;$ - CODE: - { - int i; - int exhausted = 1; - - /* 'cv' is the hidden argument with which XS_List__MoreUtils__array_iterator (this XSUB) - * is called. The closure_arg struct is stored in this CV. */ - - arrayeach_args *args = (arrayeach_args *)(CvXSUBANY(cv).any_ptr); - - if (strEQ(method, "index")) { - EXTEND(SP, 1); - ST(0) = args->curidx > 0 ? sv_2mortal(newSViv(args->curidx-1)) : &PL_sv_undef; - XSRETURN(1); - } - - EXTEND(SP, args->navs); - - for (i = 0; i < args->navs; i++) { - AV *av = args->avs[i]; - if (args->curidx <= av_len(av)) { - ST(i) = sv_2mortal(newSVsv(*av_fetch(av, args->curidx, FALSE))); - exhausted = 0; - continue; - } - ST(i) = &PL_sv_undef; - } - - if (exhausted) - XSRETURN_EMPTY; - - args->curidx++; - XSRETURN(args->navs); - } - -SV * -each_array (...) - PROTOTYPE: \@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ - CODE: - { - EACH_ARRAY_BODY; - } - OUTPUT: - RETVAL - -SV * -each_arrayref (...) - CODE: - { - EACH_ARRAY_BODY; - } - OUTPUT: - RETVAL - -#if 0 -void -_pairwise (code, ...) - SV *code; - PROTOTYPE: &\@\@ - PPCODE: - { -#define av_items(a) (av_len(a)+1) - - int i; - AV *avs[2]; - SV **oldsp; - - int nitems = 0, maxitems = 0; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - /* deref AV's for convenience and - * get maximum items */ - avs[0] = (AV*)SvRV(ST(1)); - avs[1] = (AV*)SvRV(ST(2)); - maxitems = av_items(avs[0]); - if (av_items(avs[1]) > maxitems) - maxitems = av_items(avs[1]); - - if (!PL_firstgv || !PL_secondgv) { - SAVESPTR(PL_firstgv); - SAVESPTR(PL_secondgv); - PL_firstgv = gv_fetchpv("a", TRUE, SVt_PV); - PL_secondgv = gv_fetchpv("b", TRUE, SVt_PV); - } - - oldsp = PL_stack_base; - EXTEND(SP, maxitems); - ENTER; - for (i = 0; i < maxitems; i++) { - int nret; - SV **svp = av_fetch(avs[0], i, FALSE); - GvSV(PL_firstgv) = svp ? *svp : &PL_sv_undef; - svp = av_fetch(avs[1], i, FALSE); - GvSV(PL_secondgv) = svp ? *svp : &PL_sv_undef; - PUSHMARK(SP); - PUTBACK; - nret = call_sv(code, G_EVAL|G_ARRAY); - if (SvTRUE(ERRSV)) - croak("%s", SvPV_nolen(ERRSV)); - SPAGAIN; - nitems += nret; - while (nret--) { - SvREFCNT_inc(*PL_stack_sp++); - } - } - PL_stack_base = oldsp; - LEAVE; - XSRETURN(nitems); - } - -#endif - -void -pairwise (code, ...) - SV *code; - PROTOTYPE: &\@\@ - PPCODE: - { -#define av_items(a) (av_len(a)+1) - - /* This function is not quite as efficient as it ought to be: We call - * 'code' multiple times and want to gather its return values all in - * one list. However, each call resets the stack pointer so there is no - * obvious way to get the return values onto the stack without making - * intermediate copies of the pointers. The above disabled solution - * would be more efficient. Unfortunately it doesn't work (and, as of - * now, wouldn't deal with 'code' returning more than one value). - * - * The current solution is a fair trade-off. It only allocates memory - * for a list of SV-pointers, as many as there are return values. It - * temporarily stores 'code's return values in this list and, when - * done, copies them down to SP. */ - - int i, j; - AV *avs[2]; - SV **buf, **p; /* gather return values here and later copy down to SP */ - int alloc; - - int nitems = 0, maxitems = 0; - int d; - - if(!codelike(code)) - croak_xs_usage(cv, "code, list, list"); - if(!arraylike(ST(1))) - croak_xs_usage(cv, "code, list, list"); - if(!arraylike(ST(2))) - croak_xs_usage(cv, "code, list, list"); - - if (in_pad(aTHX_ code)) { - croak("Can't use lexical $a or $b in pairwise code block"); - } - - /* deref AV's for convenience and - * get maximum items */ - avs[0] = (AV*)SvRV(ST(1)); - avs[1] = (AV*)SvRV(ST(2)); - maxitems = av_items(avs[0]); - if (av_items(avs[1]) > maxitems) - maxitems = av_items(avs[1]); - - if (!PL_firstgv || !PL_secondgv) { - SAVESPTR(PL_firstgv); - SAVESPTR(PL_secondgv); - PL_firstgv = gv_fetchpv("a", TRUE, SVt_PV); - PL_secondgv = gv_fetchpv("b", TRUE, SVt_PV); - } - - New(0, buf, alloc = maxitems, SV*); - - ENTER; - for (d = 0, i = 0; i < maxitems; i++) { - int nret; - SV **svp = av_fetch(avs[0], i, FALSE); - GvSV(PL_firstgv) = svp ? *svp : &PL_sv_undef; - svp = av_fetch(avs[1], i, FALSE); - GvSV(PL_secondgv) = svp ? *svp : &PL_sv_undef; - PUSHMARK(SP); - PUTBACK; - nret = call_sv(code, G_EVAL|G_ARRAY); - if (SvTRUE(ERRSV)) { - Safefree(buf); - croak("%s", SvPV_nolen(ERRSV)); - } - SPAGAIN; - nitems += nret; - if (nitems > alloc) { - alloc <<= 2; - Renew(buf, alloc, SV*); - } - for (j = nret-1; j >= 0; j--) { - /* POPs would return elements in reverse order */ - buf[d] = sp[-j]; - d++; - } - sp -= nret; - } - LEAVE; - EXTEND(SP, nitems); - p = buf; - for (i = 0; i < nitems; i++) - ST(i) = *p++; - - Safefree(buf); - XSRETURN(nitems); - } - -void -_natatime_iterator () - PROTOTYPE: - CODE: - { - int i; - int nret; - - /* 'cv' is the hidden argument with which XS_List__MoreUtils__array_iterator (this XSUB) - * is called. The closure_arg struct is stored in this CV. */ - - natatime_args *args = (natatime_args*)CvXSUBANY(cv).any_ptr; - - nret = args->natatime; - - EXTEND(SP, nret); - - for (i = 0; i < args->natatime; i++) { - if (args->curidx < args->nsvs) { - ST(i) = sv_2mortal(newSVsv(args->svs[args->curidx++])); - } - else { - XSRETURN(i); - } - } - - XSRETURN(nret); - } - -SV * -natatime (n, ...) - int n; - PROTOTYPE: $@ - CODE: - { - int i; - natatime_args * args; - HV *stash = gv_stashpv("List::MoreUtils_na", TRUE); - - CV *closure = newXS(NULL, XS_List__MoreUtils__natatime_iterator, __FILE__); - - /* must NOT set prototype on iterator: - * otherwise one cannot write: &$it */ - /* !! sv_setpv((SV*)closure, ""); !! */ - - New(0, args, 1, natatime_args); - New(0, args->svs, items-1, SV*); - args->nsvs = items-1; - args->curidx = 0; - args->natatime = n; - - for (i = 1; i < items; i++) - SvREFCNT_inc(args->svs[i-1] = ST(i)); - - CvXSUBANY(closure).any_ptr = args; - RETVAL = newRV_noinc((SV*)closure); - - /* in order to allow proper cleanup in DESTROY-handler */ - sv_bless(RETVAL, stash); - } - OUTPUT: - RETVAL - -void -mesh (...) - PROTOTYPE: \@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ - CODE: - { - int i, j, maxidx = -1; - AV **avs; - New(0, avs, items, AV*); - - for (i = 0; i < items; i++) { - if(!arraylike(ST(i))) - croak_xs_usage(cv, "\\@;\\@\\@..."); - avs[i] = (AV*)SvRV(ST(i)); - if (av_len(avs[i]) > maxidx) - maxidx = av_len(avs[i]); - } - - EXTEND(SP, items * (maxidx + 1)); - for (i = 0; i <= maxidx; i++) - for (j = 0; j < items; j++) { - SV **svp = av_fetch(avs[j], i, FALSE); - ST(i*items + j) = svp ? sv_2mortal(newSVsv(*svp)) : &PL_sv_undef; - } - - Safefree(avs); - XSRETURN(items * (maxidx + 1)); - } - -void -uniq (...) - PROTOTYPE: @ - CODE: - { - I32 i; - IV count = 0, seen_undef = 0; - HV *hv = newHV(); - SV **args = &PL_stack_base[ax]; - SV *tmp = sv_newmortal(); - sv_2mortal(newRV_noinc((SV*)hv)); - - /* don't build return list in scalar context */ - if (GIMME_V == G_SCALAR) { - for (i = 0; i < items; i++) { - SvGETMAGIC(args[i]); - if(SvOK(args[i])) { - sv_setsv_nomg(tmp, args[i]); - if (!hv_exists_ent(hv, tmp, 0)) { - ++count; - hv_store_ent(hv, tmp, &PL_sv_yes, 0); - } - } - else if(0 == seen_undef++) { - ++count; - } - } - ST(0) = sv_2mortal(newSVuv(count)); - XSRETURN(1); - } - - /* list context: populate SP with mortal copies */ - for (i = 0; i < items; i++) { - SvGETMAGIC(args[i]); - if(SvOK(args[i])) { - SvSetSV_nosteal(tmp, args[i]); - if (!hv_exists_ent(hv, tmp, 0)) { - /*ST(count) = sv_2mortal(newSVsv(ST(i))); - ++count;*/ - args[count++] = args[i]; - hv_store_ent(hv, tmp, &PL_sv_yes, 0); - } - } - else if(0 == seen_undef++) { - args[count++] = args[i]; - } - } - - XSRETURN(count); - } - -void -singleton (...) - PROTOTYPE: @ - CODE: - { - I32 i; - IV cnt = 0, count = 0, seen_undef = 0; - HV *hv = newHV(); - SV **args = &PL_stack_base[ax]; - SV *tmp = sv_newmortal(); - - sv_2mortal(newRV_noinc((SV*)hv)); - - for (i = 0; i < items; i++) { - SvGETMAGIC(args[i]); - if(SvOK(args[i])) { - HE *he; - SvSetSV_nosteal(tmp, args[i]); - he = hv_fetch_ent(hv, tmp, 0, 0); - if (NULL == he) { - /* ST(count) = sv_2mortal(newSVsv(ST(i))); */ - args[count++] = args[i]; - hv_store_ent(hv, tmp, newSViv(1), 0); - } - else { - SV *v = HeVAL(he); - IV how_many = SvIVX(v); - sv_setiv(v, ++how_many); - } - } - else if(0 == seen_undef++) { - args[count++] = args[i]; - } - } - - /* don't build return list in scalar context */ - if (GIMME_V == G_SCALAR) { - for (i = 0; i < count; i++) { - if(SvOK(args[i])) { - HE *he; - sv_setsv_nomg(tmp, args[i]); - he = hv_fetch_ent(hv, tmp, 0, 0); - if (he) { - SV *v = HeVAL(he); - IV how_many = SvIVX(v); - if( 1 == how_many ) - ++cnt; - } - } - else if(1 == seen_undef) { - ++cnt; - } - } - ST(0) = sv_2mortal(newSViv(cnt)); - XSRETURN(1); - } - - /* list context: populate SP with mortal copies */ - for (i = 0; i < count; i++) { - if(SvOK(args[i])) { - HE *he; - SvSetSV_nosteal(tmp, args[i]); - he = hv_fetch_ent(hv, tmp, 0, 0); - if (he) { - SV *v = HeVAL(he); - IV how_many = SvIVX(v); - if( 1 == how_many ) - args[cnt++] = args[i]; - } - } - else if(1 == seen_undef) { - args[cnt++] = args[i]; - } - } - - XSRETURN(cnt); - } - -void -minmax (...) - PROTOTYPE: @ - CODE: - { - I32 i; - SV *minsv, *maxsv; - - if (!items) - XSRETURN_EMPTY; - - if (items == 1) { - EXTEND(SP, 1); - ST(1) = sv_2mortal(newSVsv(ST(0))); - XSRETURN(2); - } - - minsv = maxsv = ST(0); - - for (i = 1; i < items; i += 2) { - SV *asv = ST(i-1); - SV *bsv = ST(i); - int cmp = ncmp(asv, bsv); - if (cmp < 0) { - int min_cmp = ncmp(minsv, asv); - int max_cmp = ncmp(maxsv, bsv); - if (min_cmp > 0) { - minsv = asv; - } - if (max_cmp < 0) { - maxsv = bsv; - } - } else { - int min_cmp = ncmp(minsv, bsv); - int max_cmp = ncmp(maxsv, asv); - if (min_cmp > 0) { - minsv = bsv; - } - if (max_cmp < 0) { - maxsv = asv; - } - } - } - - if (items & 1) { - SV *rsv = ST(items-1); - if (ncmp(minsv, rsv) > 0) { - minsv = rsv; - } - else if (ncmp(maxsv, rsv) < 0) { - maxsv = rsv; - } - } - - ST(0) = minsv; - ST(1) = maxsv; - - XSRETURN(2); - } - -void -part (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - int i; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - SV **args = &PL_stack_base[ax]; - CV *_cv; - - AV **tmp = NULL; - int last = 0; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items == 1) - XSRETURN_EMPTY; - - _cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - for(i = 1 ; i < items ; ++i) { - int idx; - GvSV(PL_defgv) = args[i]; - MULTICALL; - idx = SvIV(*PL_stack_sp); - - if (idx < 0 && (idx += last) < 0) - croak("Modification of non-creatable array value attempted, subscript %i", idx); - - if (idx >= last) { - int oldlast = last; - last = idx + 1; - Renew(tmp, last, AV*); - Zero(tmp + oldlast, last - oldlast, AV*); - } - if (!tmp[idx]) - tmp[idx] = newAV(); - av_push(tmp[idx], newSVsv( args[i] )); - } - POP_MULTICALL; - - EXTEND(SP, last); - for (i = 0; i < last; ++i) { - if (tmp[i]) - ST(i) = sv_2mortal(newRV_noinc((SV*)tmp[i])); - else - ST(i) = &PL_sv_undef; - } - - Safefree(tmp); - XSRETURN(last); -} - -#if 0 -void -part_dhash (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - /* We might want to keep this dhash-implementation. - * It is currently slower than the above but it uses less - * memory for sparse parts such as - * @part = part { 10_000_000 } 1 .. 100_000; - * Maybe there's a way to optimize dhash.h to get more speed - * from it. - */ - dMULTICALL; - int i, j, lastidx = -1; - int max; - HV *stash; - GV *gv; - I32 gimme = G_SCALAR; - I32 count = 0; - SV **args = &PL_stack_base[ax]; - CV *cv; - - dhash_t *h = dhash_init(); - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items == 1) - XSRETURN_EMPTY; - - cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(cv); - SAVESPTR(GvSV(PL_defgv)); - - for(i = 1 ; i < items ; ++i) { - int idx; - GvSV(PL_defgv) = args[i]; - MULTICALL; - idx = SvIV(*PL_stack_sp); - - if (idx < 0 && (idx += h->max) < 0) - croak("Modification of non-creatable array value attempted, subscript %i", idx); - - dhash_store(h, idx, args[i]); - } - POP_MULTICALL; - - dhash_sort_final(h); - - EXTEND(SP, max = h->max+1); - i = 0; - lastidx = -1; - while (i < h->count) { - int retidx = h->ary[i].key; - int fill = retidx - lastidx - 1; - for (j = 0; j < fill; j++) { - ST(retidx - j - 1) = &PL_sv_undef; - } - ST(retidx) = newRV_noinc((SV*)h->ary[i].val); - i++; - lastidx = retidx; - } - - dhash_destroy(h); - XSRETURN(max); -} - -#endif - -SV * -bsearch (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - HV *stash; - GV *gv; - I32 gimme = GIMME_V; /* perl-5.5.4 bus-errors out later when using GIMME - therefore we save its value in a fresh variable */ - SV **args = &PL_stack_base[ax]; - - long i, j; - int val = -1; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - if (items > 1) { - CV *_cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - i = 0; - j = items - 1; - do { - long k = (i + j) / 2; - - if (k >= items-1) - break; - - GvSV(PL_defgv) = args[1+k]; - MULTICALL; - val = SvIV(*PL_stack_sp); - - if (val == 0) { - POP_MULTICALL; - if (gimme != G_ARRAY) { - XSRETURN_YES; - } - SvREFCNT_inc(RETVAL = args[1+k]); - goto yes; - } - if (val < 0) { - i = k+1; - } else { - j = k-1; - } - } while (i <= j); - POP_MULTICALL; - } - - if (gimme == G_ARRAY) - XSRETURN_EMPTY; - else - XSRETURN_UNDEF; -yes: - ; -} -OUTPUT: - RETVAL - -int -bsearchidx (code, ...) - SV *code; -PROTOTYPE: &@ -CODE: -{ - dMULTICALL; - HV *stash; - GV *gv; - I32 gimme = GIMME_V; /* perl-5.5.4 bus-errors out later when using GIMME - therefore we save its value in a fresh variable */ - SV **args = &PL_stack_base[ax]; - - long i, j; - int val = -1; - - if(!codelike(code)) - croak_xs_usage(cv, "code, ..."); - - RETVAL = -1; - - if (items > 1) { - CV *_cv = sv_2cv(code, &stash, &gv, 0); - PUSH_MULTICALL(_cv); - SAVESPTR(GvSV(PL_defgv)); - - i = 0; - j = items - 1; - do { - long k = (i + j) / 2; - - if (k >= items-1) - break; - - GvSV(PL_defgv) = args[1+k]; - MULTICALL; - val = SvIV(*PL_stack_sp); - - if (val == 0) { - RETVAL = k; - break; - } - if (val < 0) { - i = k+1; - } else { - j = k-1; - } - } while (i <= j); - POP_MULTICALL; - } -} -OUTPUT: - RETVAL - -void -_XScompiled () - CODE: - XSRETURN_YES; diff -Nru liblist-moreutils-perl-0.416/multicall.h liblist-moreutils-perl-0.430/multicall.h --- liblist-moreutils-perl-0.416/multicall.h 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/multicall.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,165 +0,0 @@ -/* multicall.h (version 1.0) - * - * Implements a poor-man's MULTICALL interface for old versions - * of perl that don't offer a proper one. Intended to be compatible - * with 5.6.0 and later. - * - */ - -#ifdef dMULTICALL -#define REAL_MULTICALL -#else -#undef REAL_MULTICALL - -/* In versions of perl where MULTICALL is not defined (i.e. prior - * to 5.9.4), Perl_pad_push is not exported either. It also has - * an extra argument in older versions; certainly in the 5.8 series. - * So we redefine it here. - */ - -#ifndef AVf_REIFY -# ifdef SVpav_REIFY -# define AVf_REIFY SVpav_REIFY -# else -# error Neither AVf_REIFY nor SVpav_REIFY is defined -# endif -#endif - -#ifndef AvFLAGS -# define AvFLAGS SvFLAGS -#endif - -static void -multicall_pad_push(pTHX_ AV *padlist, int depth) -{ - if (depth <= AvFILLp(padlist)) - return; - - { - SV** const svp = AvARRAY(padlist); - AV* const newpad = newAV(); - SV** const oldpad = AvARRAY(svp[depth-1]); - I32 ix = AvFILLp((AV*)svp[1]); - const I32 names_fill = AvFILLp((AV*)svp[0]); - SV** const names = AvARRAY(svp[0]); - AV *av; - - for ( ;ix > 0; ix--) { - if (names_fill >= ix && names[ix] != &PL_sv_undef) { - const char sigil = SvPVX(names[ix])[0]; - if ((SvFLAGS(names[ix]) & SVf_FAKE) || sigil == '&') { - /* outer lexical or anon code */ - av_store(newpad, ix, SvREFCNT_inc(oldpad[ix])); - } - else { /* our own lexical */ - SV *sv; - if (sigil == '@') - sv = (SV*)newAV(); - else if (sigil == '%') - sv = (SV*)newHV(); - else - sv = NEWSV(0, 0); - av_store(newpad, ix, sv); - SvPADMY_on(sv); - } - } - else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) { - av_store(newpad, ix, SvREFCNT_inc(oldpad[ix])); - } - else { - /* save temporaries on recursion? */ - SV * const sv = NEWSV(0, 0); - av_store(newpad, ix, sv); - SvPADTMP_on(sv); - } - } - av = newAV(); - av_extend(av, 0); - av_store(newpad, 0, (SV*)av); - AvFLAGS(av) = AVf_REIFY; - - av_store(padlist, depth, (SV*)newpad); - AvFILLp(padlist) = depth; - } -} - -#define dMULTICALL \ - SV **newsp; /* set by POPBLOCK */ \ - PERL_CONTEXT *cx; \ - CV *multicall_cv; \ - OP *multicall_cop; \ - bool multicall_oldcatch; \ - U8 hasargs = 0 - -/* Between 5.9.1 and 5.9.2 the retstack was removed, and the - return op is now stored on the cxstack. */ -#define HAS_RETSTACK (\ - PERL_REVISION < 5 || \ - (PERL_REVISION == 5 && PERL_VERSION < 9) || \ - (PERL_REVISION == 5 && PERL_VERSION == 9 && PERL_SUBVERSION < 2) \ -) - - -/* PUSHSUB is defined so differently on different versions of perl - * that it's easier to define our own version than code for all the - * different possibilities. - */ -#if HAS_RETSTACK -# define PUSHSUB_RETSTACK(cx) -#else -# define PUSHSUB_RETSTACK(cx) cx->blk_sub.retop = Nullop; -#endif -#define MULTICALL_PUSHSUB(cx, the_cv) \ - cx->blk_sub.cv = the_cv; \ - cx->blk_sub.olddepth = CvDEPTH(the_cv); \ - cx->blk_sub.hasargs = hasargs; \ - cx->blk_sub.lval = PL_op->op_private & \ - (OPpLVAL_INTRO|OPpENTERSUB_INARGS); \ - PUSHSUB_RETSTACK(cx) \ - if (!CvDEPTH(the_cv)) { \ - (void)SvREFCNT_inc(the_cv); \ - (void)SvREFCNT_inc(the_cv); \ - SAVEFREESV(the_cv); \ - } - -#define PUSH_MULTICALL(the_cv) \ - STMT_START { \ - CV *_nOnclAshIngNamE_ = the_cv; \ - AV* padlist = CvPADLIST(_nOnclAshIngNamE_); \ - multicall_cv = _nOnclAshIngNamE_; \ - ENTER; \ - multicall_oldcatch = CATCH_GET; \ - SAVESPTR(CvROOT(multicall_cv)->op_ppaddr); \ - CvROOT(multicall_cv)->op_ppaddr = PL_ppaddr[OP_NULL]; \ - SAVETMPS; SAVEVPTR(PL_op); \ - CATCH_SET(TRUE); \ - PUSHSTACKi(PERLSI_SORT); \ - PUSHBLOCK(cx, CXt_SUB, PL_stack_sp); \ - MULTICALL_PUSHSUB(cx, multicall_cv); \ - if (++CvDEPTH(multicall_cv) >= 2) { \ - PERL_STACK_OVERFLOW_CHECK(); \ - multicall_pad_push(aTHX_ padlist, CvDEPTH(multicall_cv)); \ - } \ - SAVECOMPPAD(); \ - PL_comppad = (AV*) (AvARRAY(padlist)[CvDEPTH(multicall_cv)]); \ - PL_curpad = AvARRAY(PL_comppad); \ - multicall_cop = CvSTART(multicall_cv); \ - } STMT_END - -#define MULTICALL \ - STMT_START { \ - PL_op = multicall_cop; \ - CALLRUNOPS(aTHX); \ - } STMT_END - -#define POP_MULTICALL \ - STMT_START { \ - CvDEPTH(multicall_cv)--; \ - LEAVESUB(multicall_cv); \ - POPBLOCK(cx,PL_curpm); \ - POPSTACK; \ - CATCH_SET(multicall_oldcatch); \ - LEAVE; \ - SPAGAIN; \ - } STMT_END -#endif diff -Nru liblist-moreutils-perl-0.416/.perltidyrc liblist-moreutils-perl-0.430/.perltidyrc --- liblist-moreutils-perl-0.416/.perltidyrc 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/.perltidyrc 2020-10-05 05:45:35.000000000 +0000 @@ -0,0 +1,17 @@ +-b +-bl +-noll +-pt=2 +-bt=2 +-sbt=2 +-vt=0 +-vtc=0 +-dws +-aws +-nsfs +-asc +-bbt=0 +-cab=0 +-l=130 +-ole=unix +--noblanks-before-comments diff -Nru liblist-moreutils-perl-0.416/ppport.h liblist-moreutils-perl-0.430/ppport.h --- liblist-moreutils-perl-0.416/ppport.h 2016-04-13 09:59:18.000000000 +0000 +++ liblist-moreutils-perl-0.430/ppport.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,7748 +0,0 @@ -#if 0 -<<'SKIP'; -#endif -/* ----------------------------------------------------------------------- - - ppport.h -- Perl/Pollution/Portability Version 3.31 - - Automatically created by Devel::PPPort running under perl 5.020002. - - Do NOT edit this file directly! -- Edit PPPort_pm.PL and the - includes in parts/inc/ instead. - - Use 'perldoc ppport.h' to view the documentation below. - ----------------------------------------------------------------------- - -SKIP - -=pod - -=head1 NAME - -ppport.h - Perl/Pollution/Portability version 3.31 - -=head1 SYNOPSIS - - perl ppport.h [options] [source files] - - Searches current directory for files if no [source files] are given - - --help show short help - - --version show version - - --patch=file write one patch file with changes - --copy=suffix write changed copies with suffix - --diff=program use diff program and options - - --compat-version=version provide compatibility with Perl version - --cplusplus accept C++ comments - - --quiet don't output anything except fatal errors - --nodiag don't show diagnostics - --nohints don't show hints - --nochanges don't suggest changes - --nofilter don't filter input files - - --strip strip all script and doc functionality from - ppport.h - - --list-provided list provided API - --list-unsupported list unsupported API - --api-info=name show Perl API portability information - -=head1 COMPATIBILITY - -This version of F is designed to support operation with Perl -installations back to 5.003, and has been tested up to 5.20. - -=head1 OPTIONS - -=head2 --help - -Display a brief usage summary. - -=head2 --version - -Display the version of F. - -=head2 --patch=I - -If this option is given, a single patch file will be created if -any changes are suggested. This requires a working diff program -to be installed on your system. - -=head2 --copy=I - -If this option is given, a copy of each file will be saved with -the given suffix that contains the suggested changes. This does -not require any external programs. Note that this does not -automagically add a dot between the original filename and the -suffix. If you want the dot, you have to include it in the option -argument. - -If neither C<--patch> or C<--copy> are given, the default is to -simply print the diffs for each file. This requires either -C or a C program to be installed. - -=head2 --diff=I - -Manually set the diff program and options to use. The default -is to use C, when installed, and output unified -context diffs. - -=head2 --compat-version=I - -Tell F to check for compatibility with the given -Perl version. The default is to check for compatibility with Perl -version 5.003. You can use this option to reduce the output -of F if you intend to be backward compatible only -down to a certain Perl version. - -=head2 --cplusplus - -Usually, F will detect C++ style comments and -replace them with C style comments for portability reasons. -Using this option instructs F to leave C++ -comments untouched. - -=head2 --quiet - -Be quiet. Don't print anything except fatal errors. - -=head2 --nodiag - -Don't output any diagnostic messages. Only portability -alerts will be printed. - -=head2 --nohints - -Don't output any hints. Hints often contain useful portability -notes. Warnings will still be displayed. - -=head2 --nochanges - -Don't suggest any changes. Only give diagnostic output and hints -unless these are also deactivated. - -=head2 --nofilter - -Don't filter the list of input files. By default, files not looking -like source code (i.e. not *.xs, *.c, *.cc, *.cpp or *.h) are skipped. - -=head2 --strip - -Strip all script and documentation functionality from F. -This reduces the size of F dramatically and may be useful -if you want to include F in smaller modules without -increasing their distribution size too much. - -The stripped F will have a C<--unstrip> option that allows -you to undo the stripping, but only if an appropriate C -module is installed. - -=head2 --list-provided - -Lists the API elements for which compatibility is provided by -F. Also lists if it must be explicitly requested, -if it has dependencies, and if there are hints or warnings for it. - -=head2 --list-unsupported - -Lists the API elements that are known not to be supported by -F and below which version of Perl they probably -won't be available or work. - -=head2 --api-info=I - -Show portability information for API elements matching I. -If I is surrounded by slashes, it is interpreted as a regular -expression. - -=head1 DESCRIPTION - -In order for a Perl extension (XS) module to be as portable as possible -across differing versions of Perl itself, certain steps need to be taken. - -=over 4 - -=item * - -Including this header is the first major one. This alone will give you -access to a large part of the Perl API that hasn't been available in -earlier Perl releases. Use - - perl ppport.h --list-provided - -to see which API elements are provided by ppport.h. - -=item * - -You should avoid using deprecated parts of the API. For example, using -global Perl variables without the C prefix is deprecated. Also, -some API functions used to have a C prefix. Using this form is -also deprecated. You can safely use the supported API, as F -will provide wrappers for older Perl versions. - -=item * - -If you use one of a few functions or variables that were not present in -earlier versions of Perl, and that can't be provided using a macro, you -have to explicitly request support for these functions by adding one or -more C<#define>s in your source code before the inclusion of F. - -These functions or variables will be marked C in the list shown -by C<--list-provided>. - -Depending on whether you module has a single or multiple files that -use such functions or variables, you want either C or global -variants. - -For a C function or variable (used only in a single source -file), use: - - #define NEED_function - #define NEED_variable - -For a global function or variable (used in multiple source files), -use: - - #define NEED_function_GLOBAL - #define NEED_variable_GLOBAL - -Note that you mustn't have more than one global request for the -same function or variable in your project. - - Function / Variable Static Request Global Request - ----------------------------------------------------------------------------------------- - PL_parser NEED_PL_parser NEED_PL_parser_GLOBAL - PL_signals NEED_PL_signals NEED_PL_signals_GLOBAL - caller_cx() NEED_caller_cx NEED_caller_cx_GLOBAL - eval_pv() NEED_eval_pv NEED_eval_pv_GLOBAL - grok_bin() NEED_grok_bin NEED_grok_bin_GLOBAL - grok_hex() NEED_grok_hex NEED_grok_hex_GLOBAL - grok_number() NEED_grok_number NEED_grok_number_GLOBAL - grok_numeric_radix() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL - grok_oct() NEED_grok_oct NEED_grok_oct_GLOBAL - load_module() NEED_load_module NEED_load_module_GLOBAL - mg_findext() NEED_mg_findext NEED_mg_findext_GLOBAL - my_snprintf() NEED_my_snprintf NEED_my_snprintf_GLOBAL - my_sprintf() NEED_my_sprintf NEED_my_sprintf_GLOBAL - my_strlcat() NEED_my_strlcat NEED_my_strlcat_GLOBAL - my_strlcpy() NEED_my_strlcpy NEED_my_strlcpy_GLOBAL - newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL - newRV_noinc() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL - newSV_type() NEED_newSV_type NEED_newSV_type_GLOBAL - newSVpvn_flags() NEED_newSVpvn_flags NEED_newSVpvn_flags_GLOBAL - newSVpvn_share() NEED_newSVpvn_share NEED_newSVpvn_share_GLOBAL - pv_display() NEED_pv_display NEED_pv_display_GLOBAL - pv_escape() NEED_pv_escape NEED_pv_escape_GLOBAL - pv_pretty() NEED_pv_pretty NEED_pv_pretty_GLOBAL - sv_2pv_flags() NEED_sv_2pv_flags NEED_sv_2pv_flags_GLOBAL - sv_2pvbyte() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL - sv_catpvf_mg() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL - sv_catpvf_mg_nocontext() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL - sv_pvn_force_flags() NEED_sv_pvn_force_flags NEED_sv_pvn_force_flags_GLOBAL - sv_setpvf_mg() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL - sv_setpvf_mg_nocontext() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL - sv_unmagicext() NEED_sv_unmagicext NEED_sv_unmagicext_GLOBAL - vload_module() NEED_vload_module NEED_vload_module_GLOBAL - vnewSVpvf() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL - warner() NEED_warner NEED_warner_GLOBAL - -To avoid namespace conflicts, you can change the namespace of the -explicitly exported functions / variables using the C -macro. Just C<#define> the macro before including C: - - #define DPPP_NAMESPACE MyOwnNamespace_ - #include "ppport.h" - -The default namespace is C. - -=back - -The good thing is that most of the above can be checked by running -F on your source code. See the next section for -details. - -=head1 EXAMPLES - -To verify whether F is needed for your module, whether you -should make any changes to your code, and whether any special defines -should be used, F can be run as a Perl script to check your -source code. Simply say: - - perl ppport.h - -The result will usually be a list of patches suggesting changes -that should at least be acceptable, if not necessarily the most -efficient solution, or a fix for all possible problems. - -If you know that your XS module uses features only available in -newer Perl releases, if you're aware that it uses C++ comments, -and if you want all suggestions as a single patch file, you could -use something like this: - - perl ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff - -If you only want your code to be scanned without any suggestions -for changes, use: - - perl ppport.h --nochanges - -You can specify a different C program or options, using -the C<--diff> option: - - perl ppport.h --diff='diff -C 10' - -This would output context diffs with 10 lines of context. - -If you want to create patched copies of your files instead, use: - - perl ppport.h --copy=.new - -To display portability information for the C function, -use: - - perl ppport.h --api-info=newSVpvn - -Since the argument to C<--api-info> can be a regular expression, -you can use - - perl ppport.h --api-info=/_nomg$/ - -to display portability information for all C<_nomg> functions or - - perl ppport.h --api-info=/./ - -to display information for all known API elements. - -=head1 BUGS - -If this version of F is causing failure during -the compilation of this module, please check if newer versions -of either this module or C are available on CPAN -before sending a bug report. - -If F was generated using the latest version of -C and is causing failure of this module, please -file a bug report here: L - -Please include the following information: - -=over 4 - -=item 1. - -The complete output from running "perl -V" - -=item 2. - -This file. - -=item 3. - -The name and version of the module you were trying to build. - -=item 4. - -A full log of the build that failed. - -=item 5. - -Any other information that you think could be relevant. - -=back - -For the latest version of this code, please get the C -module from CPAN. - -=head1 COPYRIGHT - -Version 3.x, Copyright (c) 2004-2013, Marcus Holland-Moritz. - -Version 2.x, Copyright (C) 2001, Paul Marquess. - -Version 1.x, Copyright (C) 1999, Kenneth Albanowski. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - -=head1 SEE ALSO - -See L. - -=cut - -use strict; - -# Disable broken TRIE-optimization -BEGIN { eval '${^RE_TRIE_MAXBUF} = -1' if $] >= 5.009004 && $] <= 5.009005 } - -my $VERSION = 3.31; - -my %opt = ( - quiet => 0, - diag => 1, - hints => 1, - changes => 1, - cplusplus => 0, - filter => 1, - strip => 0, - version => 0, -); - -my($ppport) = $0 =~ /([\w.]+)$/; -my $LF = '(?:\r\n|[\r\n])'; # line feed -my $HS = "[ \t]"; # horizontal whitespace - -# Never use C comments in this file! -my $ccs = '/'.'*'; -my $cce = '*'.'/'; -my $rccs = quotemeta $ccs; -my $rcce = quotemeta $cce; - -eval { - require Getopt::Long; - Getopt::Long::GetOptions(\%opt, qw( - help quiet diag! filter! hints! changes! cplusplus strip version - patch=s copy=s diff=s compat-version=s - list-provided list-unsupported api-info=s - )) or usage(); -}; - -if ($@ and grep /^-/, @ARGV) { - usage() if "@ARGV" =~ /^--?h(?:elp)?$/; - die "Getopt::Long not found. Please don't use any options.\n"; -} - -if ($opt{version}) { - print "This is $0 $VERSION.\n"; - exit 0; -} - -usage() if $opt{help}; -strip() if $opt{strip}; - -if (exists $opt{'compat-version'}) { - my($r,$v,$s) = eval { parse_version($opt{'compat-version'}) }; - if ($@) { - die "Invalid version number format: '$opt{'compat-version'}'\n"; - } - die "Only Perl 5 is supported\n" if $r != 5; - die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000; - $opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s; -} -else { - $opt{'compat-version'} = 5; -} - -my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/ - ? ( $1 => { - ($2 ? ( base => $2 ) : ()), - ($3 ? ( todo => $3 ) : ()), - (index($4, 'v') >= 0 ? ( varargs => 1 ) : ()), - (index($4, 'p') >= 0 ? ( provided => 1 ) : ()), - (index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()), - } ) - : die "invalid spec: $_" } qw( -ASCII_TO_NEED||5.007001|n -AvFILLp|5.004050||p -AvFILL||| -BhkDISABLE||5.021008| -BhkENABLE||5.021008| -BhkENTRY_set||5.021008| -BhkENTRY||| -BhkFLAGS||| -CALL_BLOCK_HOOKS||| -CLASS|||n -CPERLscope|5.005000||p -CX_CURPAD_SAVE||| -CX_CURPAD_SV||| -CopFILEAV|5.006000||p -CopFILEGV_set|5.006000||p -CopFILEGV|5.006000||p -CopFILESV|5.006000||p -CopFILE_set|5.006000||p -CopFILE|5.006000||p -CopSTASHPV_set|5.006000||p -CopSTASHPV|5.006000||p -CopSTASH_eq|5.006000||p -CopSTASH_set|5.006000||p -CopSTASH|5.006000||p -CopyD|5.009002|5.004050|p -Copy||| -CvPADLIST||5.008001| -CvSTASH||| -CvWEAKOUTSIDE||| -DEFSV_set|5.010001||p -DEFSV|5.004050||p -END_EXTERN_C|5.005000||p -ENTER||| -ERRSV|5.004050||p -EXTEND||| -EXTERN_C|5.005000||p -F0convert|||n -FREETMPS||| -GIMME_V||5.004000|n -GIMME|||n -GROK_NUMERIC_RADIX|5.007002||p -G_ARRAY||| -G_DISCARD||| -G_EVAL||| -G_METHOD|5.006001||p -G_NOARGS||| -G_SCALAR||| -G_VOID||5.004000| -GetVars||| -GvAV||| -GvCV||| -GvHV||| -GvSVn|5.009003||p -GvSV||| -Gv_AMupdate||5.011000| -HEf_SVKEY|5.003070||p -HeHASH||5.003070| -HeKEY||5.003070| -HeKLEN||5.003070| -HePV||5.004000| -HeSVKEY_force||5.003070| -HeSVKEY_set||5.004000| -HeSVKEY||5.003070| -HeUTF8|5.010001|5.008000|p -HeVAL||5.003070| -HvENAMELEN||5.015004| -HvENAMEUTF8||5.015004| -HvENAME||5.013007| -HvNAMELEN_get|5.009003||p -HvNAMELEN||5.015004| -HvNAMEUTF8||5.015004| -HvNAME_get|5.009003||p -HvNAME||| -INT2PTR|5.006000||p -IN_LOCALE_COMPILETIME|5.007002||p -IN_LOCALE_RUNTIME|5.007002||p -IN_LOCALE|5.007002||p -IN_PERL_COMPILETIME|5.008001||p -IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p -IS_NUMBER_INFINITY|5.007002||p -IS_NUMBER_IN_UV|5.007002||p -IS_NUMBER_NAN|5.007003||p -IS_NUMBER_NEG|5.007002||p -IS_NUMBER_NOT_INT|5.007002||p -IVSIZE|5.006000||p -IVTYPE|5.006000||p -IVdf|5.006000||p -LEAVE||| -LINKLIST||5.013006| -LVRET||| -MARK||| -MULTICALL||5.021008| -MUTABLE_PTR|5.010001||p -MUTABLE_SV|5.010001||p -MY_CXT_CLONE|5.009002||p -MY_CXT_INIT|5.007003||p -MY_CXT|5.007003||p -MoveD|5.009002|5.004050|p -Move||| -NATIVE_TO_NEED||5.007001|n -NOOP|5.005000||p -NUM2PTR|5.006000||p -NVTYPE|5.006000||p -NVef|5.006001||p -NVff|5.006001||p -NVgf|5.006001||p -Newxc|5.009003||p -Newxz|5.009003||p -Newx|5.009003||p -Nullav||| -Nullch||| -Nullcv||| -Nullhv||| -Nullsv||| -OP_CLASS||5.013007| -OP_DESC||5.007003| -OP_NAME||5.007003| -OP_TYPE_IS_OR_WAS||5.019010| -OP_TYPE_IS||5.019007| -ORIGMARK||| -OpHAS_SIBLING||5.021007| -OpSIBLING_set||5.021007| -OpSIBLING||5.021007| -PAD_BASE_SV||| -PAD_CLONE_VARS||| -PAD_COMPNAME_FLAGS||| -PAD_COMPNAME_GEN_set||| -PAD_COMPNAME_GEN||| -PAD_COMPNAME_OURSTASH||| -PAD_COMPNAME_PV||| -PAD_COMPNAME_TYPE||| -PAD_RESTORE_LOCAL||| -PAD_SAVE_LOCAL||| -PAD_SAVE_SETNULLPAD||| -PAD_SETSV||| -PAD_SET_CUR_NOSAVE||| -PAD_SET_CUR||| -PAD_SVl||| -PAD_SV||| -PERLIO_FUNCS_CAST|5.009003||p -PERLIO_FUNCS_DECL|5.009003||p -PERL_ABS|5.008001||p -PERL_BCDVERSION|5.021008||p -PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p -PERL_HASH|5.003070||p -PERL_INT_MAX|5.003070||p -PERL_INT_MIN|5.003070||p -PERL_LONG_MAX|5.003070||p -PERL_LONG_MIN|5.003070||p -PERL_MAGIC_arylen|5.007002||p -PERL_MAGIC_backref|5.007002||p -PERL_MAGIC_bm|5.007002||p -PERL_MAGIC_collxfrm|5.007002||p -PERL_MAGIC_dbfile|5.007002||p -PERL_MAGIC_dbline|5.007002||p -PERL_MAGIC_defelem|5.007002||p -PERL_MAGIC_envelem|5.007002||p -PERL_MAGIC_env|5.007002||p -PERL_MAGIC_ext|5.007002||p -PERL_MAGIC_fm|5.007002||p -PERL_MAGIC_glob|5.021008||p -PERL_MAGIC_isaelem|5.007002||p -PERL_MAGIC_isa|5.007002||p -PERL_MAGIC_mutex|5.021008||p -PERL_MAGIC_nkeys|5.007002||p -PERL_MAGIC_overload_elem|5.021008||p -PERL_MAGIC_overload_table|5.007002||p -PERL_MAGIC_overload|5.021008||p -PERL_MAGIC_pos|5.007002||p -PERL_MAGIC_qr|5.007002||p -PERL_MAGIC_regdata|5.007002||p -PERL_MAGIC_regdatum|5.007002||p -PERL_MAGIC_regex_global|5.007002||p -PERL_MAGIC_shared_scalar|5.007003||p -PERL_MAGIC_shared|5.007003||p -PERL_MAGIC_sigelem|5.007002||p -PERL_MAGIC_sig|5.007002||p -PERL_MAGIC_substr|5.007002||p -PERL_MAGIC_sv|5.007002||p -PERL_MAGIC_taint|5.007002||p -PERL_MAGIC_tiedelem|5.007002||p -PERL_MAGIC_tiedscalar|5.007002||p -PERL_MAGIC_tied|5.007002||p -PERL_MAGIC_utf8|5.008001||p -PERL_MAGIC_uvar_elem|5.007003||p -PERL_MAGIC_uvar|5.007002||p -PERL_MAGIC_vec|5.007002||p -PERL_MAGIC_vstring|5.008001||p -PERL_PV_ESCAPE_ALL|5.009004||p -PERL_PV_ESCAPE_FIRSTCHAR|5.009004||p -PERL_PV_ESCAPE_NOBACKSLASH|5.009004||p -PERL_PV_ESCAPE_NOCLEAR|5.009004||p -PERL_PV_ESCAPE_QUOTE|5.009004||p -PERL_PV_ESCAPE_RE|5.009005||p -PERL_PV_ESCAPE_UNI_DETECT|5.009004||p -PERL_PV_ESCAPE_UNI|5.009004||p -PERL_PV_PRETTY_DUMP|5.009004||p -PERL_PV_PRETTY_ELLIPSES|5.010000||p -PERL_PV_PRETTY_LTGT|5.009004||p -PERL_PV_PRETTY_NOCLEAR|5.010000||p -PERL_PV_PRETTY_QUOTE|5.009004||p -PERL_PV_PRETTY_REGPROP|5.009004||p -PERL_QUAD_MAX|5.003070||p -PERL_QUAD_MIN|5.003070||p -PERL_REVISION|5.006000||p -PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p -PERL_SCAN_DISALLOW_PREFIX|5.007003||p -PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p -PERL_SCAN_SILENT_ILLDIGIT|5.008001||p -PERL_SHORT_MAX|5.003070||p -PERL_SHORT_MIN|5.003070||p -PERL_SIGNALS_UNSAFE_FLAG|5.008001||p -PERL_SUBVERSION|5.006000||p -PERL_SYS_INIT3||5.006000| -PERL_SYS_INIT||| -PERL_SYS_TERM||5.021008| -PERL_UCHAR_MAX|5.003070||p -PERL_UCHAR_MIN|5.003070||p -PERL_UINT_MAX|5.003070||p -PERL_UINT_MIN|5.003070||p -PERL_ULONG_MAX|5.003070||p -PERL_ULONG_MIN|5.003070||p -PERL_UNUSED_ARG|5.009003||p -PERL_UNUSED_CONTEXT|5.009004||p -PERL_UNUSED_DECL|5.007002||p -PERL_UNUSED_VAR|5.007002||p -PERL_UQUAD_MAX|5.003070||p -PERL_UQUAD_MIN|5.003070||p -PERL_USE_GCC_BRACE_GROUPS|5.009004||p -PERL_USHORT_MAX|5.003070||p -PERL_USHORT_MIN|5.003070||p -PERL_VERSION|5.006000||p -PL_DBsignal|5.005000||p -PL_DBsingle|||pn -PL_DBsub|||pn -PL_DBtrace|||pn -PL_Sv|5.005000||p -PL_bufend|5.021008||p -PL_bufptr|5.021008||p -PL_check||5.006000| -PL_compiling|5.004050||p -PL_comppad_name||5.017004| -PL_comppad||5.008001| -PL_copline|5.021008||p -PL_curcop|5.004050||p -PL_curpad||5.005000| -PL_curstash|5.004050||p -PL_debstash|5.004050||p -PL_defgv|5.004050||p -PL_diehook|5.004050||p -PL_dirty|5.004050||p -PL_dowarn|||pn -PL_errgv|5.004050||p -PL_error_count|5.021008||p -PL_expect|5.021008||p -PL_hexdigit|5.005000||p -PL_hints|5.005000||p -PL_in_my_stash|5.021008||p -PL_in_my|5.021008||p -PL_keyword_plugin||5.011002| -PL_last_in_gv|||n -PL_laststatval|5.005000||p -PL_lex_state|5.021008||p -PL_lex_stuff|5.021008||p -PL_linestr|5.021008||p -PL_modglobal||5.005000|n -PL_na|5.004050||pn -PL_no_modify|5.006000||p -PL_ofsgv|||n -PL_opfreehook||5.011000|n -PL_parser|5.009005||p -PL_peepp||5.007003|n -PL_perl_destruct_level|5.004050||p -PL_perldb|5.004050||p -PL_ppaddr|5.006000||p -PL_rpeepp||5.013005|n -PL_rsfp_filters|5.021008||p -PL_rsfp|5.021008||p -PL_rs|||n -PL_signals|5.008001||p -PL_stack_base|5.004050||p -PL_stack_sp|5.004050||p -PL_statcache|5.005000||p -PL_stdingv|5.004050||p -PL_sv_arenaroot|5.004050||p -PL_sv_no|5.004050||pn -PL_sv_undef|5.004050||pn -PL_sv_yes|5.004050||pn -PL_tainted|5.004050||p -PL_tainting|5.004050||p -PL_tokenbuf|5.021008||p -POP_MULTICALL||5.021008| -POPi|||n -POPl|||n -POPn|||n -POPpbytex||5.007001|n -POPpx||5.005030|n -POPp|||n -POPs|||n -PTR2IV|5.006000||p -PTR2NV|5.006000||p -PTR2UV|5.006000||p -PTR2nat|5.009003||p -PTR2ul|5.007001||p -PTRV|5.006000||p -PUSHMARK||| -PUSH_MULTICALL||5.021008| -PUSHi||| -PUSHmortal|5.009002||p -PUSHn||| -PUSHp||| -PUSHs||| -PUSHu|5.004000||p -PUTBACK||| -PadARRAY||5.021008| -PadMAX||5.021008| -PadlistARRAY||5.021008| -PadlistMAX||5.021008| -PadlistNAMESARRAY||5.021008| -PadlistNAMESMAX||5.021008| -PadlistNAMES||5.021008| -PadlistREFCNT||5.017004| -PadnameIsOUR||| -PadnameIsSTATE||| -PadnameLEN||5.021008| -PadnameOURSTASH||| -PadnameOUTER||| -PadnamePV||5.021008| -PadnameREFCNT_dec||5.021008| -PadnameREFCNT||5.021008| -PadnameSV||5.021008| -PadnameTYPE||| -PadnameUTF8||5.021007| -PadnamelistARRAY||5.021008| -PadnamelistMAX||5.021008| -PadnamelistREFCNT_dec||5.021008| -PadnamelistREFCNT||5.021008| -PerlIO_clearerr||5.007003| -PerlIO_close||5.007003| -PerlIO_context_layers||5.009004| -PerlIO_eof||5.007003| -PerlIO_error||5.007003| -PerlIO_fileno||5.007003| -PerlIO_fill||5.007003| -PerlIO_flush||5.007003| -PerlIO_get_base||5.007003| -PerlIO_get_bufsiz||5.007003| -PerlIO_get_cnt||5.007003| -PerlIO_get_ptr||5.007003| -PerlIO_read||5.007003| -PerlIO_restore_errno||| -PerlIO_save_errno||| -PerlIO_seek||5.007003| -PerlIO_set_cnt||5.007003| -PerlIO_set_ptrcnt||5.007003| -PerlIO_setlinebuf||5.007003| -PerlIO_stderr||5.007003| -PerlIO_stdin||5.007003| -PerlIO_stdout||5.007003| -PerlIO_tell||5.007003| -PerlIO_unread||5.007003| -PerlIO_write||5.007003| -Perl_signbit||5.009005|n -PoisonFree|5.009004||p -PoisonNew|5.009004||p -PoisonWith|5.009004||p -Poison|5.008000||p -READ_XDIGIT||5.017006| -RETVAL|||n -Renewc||| -Renew||| -SAVECLEARSV||| -SAVECOMPPAD||| -SAVEPADSV||| -SAVETMPS||| -SAVE_DEFSV|5.004050||p -SPAGAIN||| -SP||| -START_EXTERN_C|5.005000||p -START_MY_CXT|5.007003||p -STMT_END|||p -STMT_START|||p -STR_WITH_LEN|5.009003||p -ST||| -SV_CONST_RETURN|5.009003||p -SV_COW_DROP_PV|5.008001||p -SV_COW_SHARED_HASH_KEYS|5.009005||p -SV_GMAGIC|5.007002||p -SV_HAS_TRAILING_NUL|5.009004||p -SV_IMMEDIATE_UNREF|5.007001||p -SV_MUTABLE_RETURN|5.009003||p -SV_NOSTEAL|5.009002||p -SV_SMAGIC|5.009003||p -SV_UTF8_NO_ENCODING|5.008001||p -SVfARG|5.009005||p -SVf_UTF8|5.006000||p -SVf|5.006000||p -SVt_INVLIST||5.019002| -SVt_IV||| -SVt_NULL||| -SVt_NV||| -SVt_PVAV||| -SVt_PVCV||| -SVt_PVFM||| -SVt_PVGV||| -SVt_PVHV||| -SVt_PVIO||| -SVt_PVIV||| -SVt_PVLV||| -SVt_PVMG||| -SVt_PVNV||| -SVt_PV||| -SVt_REGEXP||5.011000| -Safefree||| -Slab_Alloc||| -Slab_Free||| -Slab_to_ro||| -Slab_to_rw||| -StructCopy||| -SvCUR_set||| -SvCUR||| -SvEND||| -SvGAMAGIC||5.006001| -SvGETMAGIC|5.004050||p -SvGROW||| -SvIOK_UV||5.006000| -SvIOK_notUV||5.006000| -SvIOK_off||| -SvIOK_only_UV||5.006000| -SvIOK_only||| -SvIOK_on||| -SvIOKp||| -SvIOK||| -SvIVX||| -SvIV_nomg|5.009001||p -SvIV_set||| -SvIVx||| -SvIV||| -SvIsCOW_shared_hash||5.008003| -SvIsCOW||5.008003| -SvLEN_set||| -SvLEN||| -SvLOCK||5.007003| -SvMAGIC_set|5.009003||p -SvNIOK_off||| -SvNIOKp||| -SvNIOK||| -SvNOK_off||| -SvNOK_only||| -SvNOK_on||| -SvNOKp||| -SvNOK||| -SvNVX||| -SvNV_nomg||5.013002| -SvNV_set||| -SvNVx||| -SvNV||| -SvOK||| -SvOOK_offset||5.011000| -SvOOK||| -SvPOK_off||| -SvPOK_only_UTF8||5.006000| -SvPOK_only||| -SvPOK_on||| -SvPOKp||| -SvPOK||| -SvPVX_const|5.009003||p -SvPVX_mutable|5.009003||p -SvPVX||| -SvPV_const|5.009003||p -SvPV_flags_const_nolen|5.009003||p -SvPV_flags_const|5.009003||p -SvPV_flags_mutable|5.009003||p -SvPV_flags|5.007002||p -SvPV_force_flags_mutable|5.009003||p -SvPV_force_flags_nolen|5.009003||p -SvPV_force_flags|5.007002||p -SvPV_force_mutable|5.009003||p -SvPV_force_nolen|5.009003||p -SvPV_force_nomg_nolen|5.009003||p -SvPV_force_nomg|5.007002||p -SvPV_force|||p -SvPV_mutable|5.009003||p -SvPV_nolen_const|5.009003||p -SvPV_nolen|5.006000||p -SvPV_nomg_const_nolen|5.009003||p -SvPV_nomg_const|5.009003||p -SvPV_nomg_nolen|5.013007||p -SvPV_nomg|5.007002||p -SvPV_renew|5.009003||p -SvPV_set||| -SvPVbyte_force||5.009002| -SvPVbyte_nolen||5.006000| -SvPVbytex_force||5.006000| -SvPVbytex||5.006000| -SvPVbyte|5.006000||p -SvPVutf8_force||5.006000| -SvPVutf8_nolen||5.006000| -SvPVutf8x_force||5.006000| -SvPVutf8x||5.006000| -SvPVutf8||5.006000| -SvPVx||| -SvPV||| -SvREFCNT_dec_NN||5.017007| -SvREFCNT_dec||| -SvREFCNT_inc_NN|5.009004||p -SvREFCNT_inc_simple_NN|5.009004||p -SvREFCNT_inc_simple_void_NN|5.009004||p -SvREFCNT_inc_simple_void|5.009004||p -SvREFCNT_inc_simple|5.009004||p -SvREFCNT_inc_void_NN|5.009004||p -SvREFCNT_inc_void|5.009004||p -SvREFCNT_inc|||p -SvREFCNT||| -SvROK_off||| -SvROK_on||| -SvROK||| -SvRV_set|5.009003||p -SvRV||| -SvRXOK||5.009005| -SvRX||5.009005| -SvSETMAGIC||| -SvSHARED_HASH|5.009003||p -SvSHARE||5.007003| -SvSTASH_set|5.009003||p -SvSTASH||| -SvSetMagicSV_nosteal||5.004000| -SvSetMagicSV||5.004000| -SvSetSV_nosteal||5.004000| -SvSetSV||| -SvTAINTED_off||5.004000| -SvTAINTED_on||5.004000| -SvTAINTED||5.004000| -SvTAINT||| -SvTHINKFIRST||| -SvTRUE_nomg||5.013006| -SvTRUE||| -SvTYPE||| -SvUNLOCK||5.007003| -SvUOK|5.007001|5.006000|p -SvUPGRADE||| -SvUTF8_off||5.006000| -SvUTF8_on||5.006000| -SvUTF8||5.006000| -SvUVXx|5.004000||p -SvUVX|5.004000||p -SvUV_nomg|5.009001||p -SvUV_set|5.009003||p -SvUVx|5.004000||p -SvUV|5.004000||p -SvVOK||5.008001| -SvVSTRING_mg|5.009004||p -THIS|||n -UNDERBAR|5.009002||p -UTF8_MAXBYTES|5.009002||p -UVSIZE|5.006000||p -UVTYPE|5.006000||p -UVXf|5.007001||p -UVof|5.006000||p -UVuf|5.006000||p -UVxf|5.006000||p -WARN_ALL|5.006000||p -WARN_AMBIGUOUS|5.006000||p -WARN_ASSERTIONS|5.021008||p -WARN_BAREWORD|5.006000||p -WARN_CLOSED|5.006000||p -WARN_CLOSURE|5.006000||p -WARN_DEBUGGING|5.006000||p -WARN_DEPRECATED|5.006000||p -WARN_DIGIT|5.006000||p -WARN_EXEC|5.006000||p -WARN_EXITING|5.006000||p -WARN_GLOB|5.006000||p -WARN_INPLACE|5.006000||p -WARN_INTERNAL|5.006000||p -WARN_IO|5.006000||p -WARN_LAYER|5.008000||p -WARN_MALLOC|5.006000||p -WARN_MISC|5.006000||p -WARN_NEWLINE|5.006000||p -WARN_NUMERIC|5.006000||p -WARN_ONCE|5.006000||p -WARN_OVERFLOW|5.006000||p -WARN_PACK|5.006000||p -WARN_PARENTHESIS|5.006000||p -WARN_PIPE|5.006000||p -WARN_PORTABLE|5.006000||p -WARN_PRECEDENCE|5.006000||p -WARN_PRINTF|5.006000||p -WARN_PROTOTYPE|5.006000||p -WARN_QW|5.006000||p -WARN_RECURSION|5.006000||p -WARN_REDEFINE|5.006000||p -WARN_REGEXP|5.006000||p -WARN_RESERVED|5.006000||p -WARN_SEMICOLON|5.006000||p -WARN_SEVERE|5.006000||p -WARN_SIGNAL|5.006000||p -WARN_SUBSTR|5.006000||p -WARN_SYNTAX|5.006000||p -WARN_TAINT|5.006000||p -WARN_THREADS|5.008000||p -WARN_UNINITIALIZED|5.006000||p -WARN_UNOPENED|5.006000||p -WARN_UNPACK|5.006000||p -WARN_UNTIE|5.006000||p -WARN_UTF8|5.006000||p -WARN_VOID|5.006000||p -WIDEST_UTYPE|5.015004||p -XCPT_CATCH|5.009002||p -XCPT_RETHROW|5.009002||p -XCPT_TRY_END|5.009002||p -XCPT_TRY_START|5.009002||p -XPUSHi||| -XPUSHmortal|5.009002||p -XPUSHn||| -XPUSHp||| -XPUSHs||| -XPUSHu|5.004000||p -XSPROTO|5.010000||p -XSRETURN_EMPTY||| -XSRETURN_IV||| -XSRETURN_NO||| -XSRETURN_NV||| -XSRETURN_PV||| -XSRETURN_UNDEF||| -XSRETURN_UV|5.008001||p -XSRETURN_YES||| -XSRETURN|||p -XST_mIV||| -XST_mNO||| -XST_mNV||| -XST_mPV||| -XST_mUNDEF||| -XST_mUV|5.008001||p -XST_mYES||| -XS_APIVERSION_BOOTCHECK||5.021008| -XS_EXTERNAL||5.021008| -XS_INTERNAL||5.021008| -XS_VERSION_BOOTCHECK||5.021008| -XS_VERSION||| -XSprePUSH|5.006000||p -XS||| -XopDISABLE||5.021008| -XopENABLE||5.021008| -XopENTRYCUSTOM||5.021008| -XopENTRY_set||5.021008| -XopENTRY||5.021008| -XopFLAGS||5.013007| -ZeroD|5.009002||p -Zero||| -_aMY_CXT|5.007003||p -_add_range_to_invlist||| -_append_range_to_invlist||| -_core_swash_init||| -_get_encoding||| -_get_regclass_nonbitmap_data||| -_get_swash_invlist||| -_invlist_array_init|||n -_invlist_contains_cp|||n -_invlist_contents||| -_invlist_dump||| -_invlist_intersection_maybe_complement_2nd||| -_invlist_intersection||| -_invlist_invert||| -_invlist_len|||n -_invlist_populate_swatch|||n -_invlist_search|||n -_invlist_subtract||| -_invlist_union_maybe_complement_2nd||| -_invlist_union||| -_is_cur_LC_category_utf8||| -_is_in_locale_category||5.021001| -_is_uni_FOO||5.017008| -_is_uni_perl_idcont||5.017008| -_is_uni_perl_idstart||5.017007| -_is_utf8_FOO||5.017008| -_is_utf8_char_slow||5.021001|n -_is_utf8_idcont||5.021001| -_is_utf8_idstart||5.021001| -_is_utf8_mark||5.017008| -_is_utf8_perl_idcont||5.017008| -_is_utf8_perl_idstart||5.017007| -_is_utf8_xidcont||5.021001| -_is_utf8_xidstart||5.021001| -_load_PL_utf8_foldclosures||| -_make_exactf_invlist||| -_new_invlist_C_array||| -_new_invlist||| -_pMY_CXT|5.007003||p -_setup_canned_invlist||| -_swash_inversion_hash||| -_swash_to_invlist||| -_to_fold_latin1||| -_to_uni_fold_flags||5.014000| -_to_upper_title_latin1||| -_to_utf8_fold_flags||5.019009| -_to_utf8_lower_flags||5.019009| -_to_utf8_title_flags||5.019009| -_to_utf8_upper_flags||5.019009| -_warn_problematic_locale|||n -aMY_CXT_|5.007003||p -aMY_CXT|5.007003||p -aTHXR_|5.021008||p -aTHXR|5.021008||p -aTHX_|5.006000||p -aTHX|5.006000||p -aassign_common_vars||| -add_above_Latin1_folds||| -add_cp_to_invlist||| -add_data|||n -add_multi_match||| -add_utf16_textfilter||| -adjust_size_and_find_bucket|||n -advance_one_SB||| -advance_one_WB||| -alloc_maybe_populate_EXACT||| -alloccopstash||| -allocmy||| -amagic_call||| -amagic_cmp_locale||| -amagic_cmp||| -amagic_deref_call||5.013007| -amagic_i_ncmp||| -amagic_is_enabled||| -amagic_ncmp||| -anonymise_cv_maybe||| -any_dup||| -ao||| -append_utf8_from_native_byte||5.019004|n -apply_attrs_my||| -apply_attrs_string||5.006001| -apply_attrs||| -apply||| -assert_uft8_cache_coherent||| -assignment_type||| -atfork_lock||5.007003|n -atfork_unlock||5.007003|n -av_arylen_p||5.009003| -av_clear||| -av_create_and_push||5.009005| -av_create_and_unshift_one||5.009005| -av_delete||5.006000| -av_exists||5.006000| -av_extend_guts||| -av_extend||| -av_fetch||| -av_fill||| -av_iter_p||5.011000| -av_len||| -av_make||| -av_pop||| -av_push||| -av_reify||| -av_shift||| -av_store||| -av_tindex||5.017009| -av_top_index||5.017009| -av_undef||| -av_unshift||| -ax|||n -backup_one_SB||| -backup_one_WB||| -bad_type_gv||| -bad_type_pv||| -bind_match||| -block_end||5.004000| -block_gimme||5.004000| -block_start||5.004000| -blockhook_register||5.013003| -boolSV|5.004000||p -boot_core_PerlIO||| -boot_core_UNIVERSAL||| -boot_core_mro||| -bytes_cmp_utf8||5.013007| -bytes_from_utf8||5.007001| -bytes_to_utf8||5.006001| -call_argv|5.006000||p -call_atexit||5.006000| -call_list||5.004000| -call_method|5.006000||p -call_pv|5.006000||p -call_sv|5.006000||p -caller_cx|5.013005|5.006000|p -calloc||5.007002|n -cando||| -cast_i32||5.006000|n -cast_iv||5.006000|n -cast_ulong||5.006000|n -cast_uv||5.006000|n -check_locale_boundary_crossing||| -check_type_and_open||| -check_uni||| -check_utf8_print||| -checkcomma||| -ckWARN|5.006000||p -ck_entersub_args_core||| -ck_entersub_args_list||5.013006| -ck_entersub_args_proto_or_list||5.013006| -ck_entersub_args_proto||5.013006| -ck_warner_d||5.011001|v -ck_warner||5.011001|v -ckwarn_common||| -ckwarn_d||5.009003| -ckwarn||5.009003| -clear_placeholders||| -clear_special_blocks||| -clone_params_del|||n -clone_params_new|||n -closest_cop||| -cntrl_to_mnemonic|||n -compute_EXACTish|||n -construct_ahocorasick_from_trie||| -cop_fetch_label||5.015001| -cop_free||| -cop_hints_2hv||5.013007| -cop_hints_fetch_pvn||5.013007| -cop_hints_fetch_pvs||5.013007| -cop_hints_fetch_pv||5.013007| -cop_hints_fetch_sv||5.013007| -cop_store_label||5.015001| -cophh_2hv||5.013007| -cophh_copy||5.013007| -cophh_delete_pvn||5.013007| -cophh_delete_pvs||5.013007| -cophh_delete_pv||5.013007| -cophh_delete_sv||5.013007| -cophh_fetch_pvn||5.013007| -cophh_fetch_pvs||5.013007| -cophh_fetch_pv||5.013007| -cophh_fetch_sv||5.013007| -cophh_free||5.013007| -cophh_new_empty||5.021008| -cophh_store_pvn||5.013007| -cophh_store_pvs||5.013007| -cophh_store_pv||5.013007| -cophh_store_sv||5.013007| -core_prototype||| -coresub_op||| -could_it_be_a_POSIX_class|||n -cr_textfilter||| -create_eval_scope||| -croak_memory_wrap||5.019003|n -croak_no_mem|||n -croak_no_modify||5.013003|n -croak_nocontext|||vn -croak_popstack|||n -croak_sv||5.013001| -croak_xs_usage||5.010001|n -croak|||v -csighandler||5.009003|n -current_re_engine||| -curse||| -custom_op_desc||5.007003| -custom_op_get_field||| -custom_op_name||5.007003| -custom_op_register||5.013007| -custom_op_xop||5.013007| -cv_ckproto_len_flags||| -cv_clone_into||| -cv_clone||| -cv_const_sv_or_av|||n -cv_const_sv||5.003070|n -cv_dump||| -cv_forget_slab||| -cv_get_call_checker||5.013006| -cv_name||5.021005| -cv_set_call_checker_flags||5.021004| -cv_set_call_checker||5.013006| -cv_undef_flags||| -cv_undef||| -cvgv_from_hek||| -cvgv_set||| -cvstash_set||| -cx_dump||5.005000| -cx_dup||| -cxinc||| -dAXMARK|5.009003||p -dAX|5.007002||p -dITEMS|5.007002||p -dMARK||| -dMULTICALL||5.009003| -dMY_CXT_SV|5.007003||p -dMY_CXT|5.007003||p -dNOOP|5.006000||p -dORIGMARK||| -dSP||| -dTHR|5.004050||p -dTHXR|5.021008||p -dTHXa|5.006000||p -dTHXoa|5.006000||p -dTHX|5.006000||p -dUNDERBAR|5.009002||p -dVAR|5.009003||p -dXCPT|5.009002||p -dXSARGS||| -dXSI32||| -dXSTARG|5.006000||p -deb_curcv||| -deb_nocontext|||vn -deb_stack_all||| -deb_stack_n||| -debop||5.005000| -debprofdump||5.005000| -debprof||| -debstackptrs||5.007003| -debstack||5.007003| -debug_start_match||| -deb||5.007003|v -defelem_target||| -del_sv||| -delete_eval_scope||| -delimcpy||5.004000|n -deprecate_commaless_var_list||| -despatch_signals||5.007001| -destroy_matcher||| -die_nocontext|||vn -die_sv||5.013001| -die_unwind||| -die|||v -dirp_dup||| -div128||| -djSP||| -do_aexec5||| -do_aexec||| -do_aspawn||| -do_binmode||5.004050| -do_chomp||| -do_close||| -do_delete_local||| -do_dump_pad||| -do_eof||| -do_exec3||| -do_execfree||| -do_exec||| -do_gv_dump||5.006000| -do_gvgv_dump||5.006000| -do_hv_dump||5.006000| -do_ipcctl||| -do_ipcget||| -do_join||| -do_magic_dump||5.006000| -do_msgrcv||| -do_msgsnd||| -do_ncmp||| -do_oddball||| -do_op_dump||5.006000| -do_open6||| -do_open9||5.006000| -do_open_raw||| -do_openn||5.007001| -do_open||5.003070| -do_pmop_dump||5.006000| -do_print||| -do_readline||| -do_seek||| -do_semop||| -do_shmio||| -do_smartmatch||| -do_spawn_nowait||| -do_spawn||| -do_sprintf||| -do_sv_dump||5.006000| -do_sysseek||| -do_tell||| -do_trans_complex_utf8||| -do_trans_complex||| -do_trans_count_utf8||| -do_trans_count||| -do_trans_simple_utf8||| -do_trans_simple||| -do_trans||| -do_vecget||| -do_vecset||| -do_vop||| -docatch||| -doeval||| -dofile||| -dofindlabel||| -doform||| -doing_taint||5.008001|n -dooneliner||| -doopen_pm||| -doparseform||| -dopoptoeval||| -dopoptogiven||| -dopoptolabel||| -dopoptoloop||| -dopoptosub_at||| -dopoptowhen||| -doref||5.009003| -dounwind||| -dowantarray||| -drand48_init_r|||n -drand48_r|||n -dump_all_perl||| -dump_all||5.006000| -dump_c_backtrace||| -dump_eval||5.006000| -dump_exec_pos||| -dump_form||5.006000| -dump_indent||5.006000|v -dump_mstats||| -dump_packsubs_perl||| -dump_packsubs||5.006000| -dump_sub_perl||| -dump_sub||5.006000| -dump_sv_child||| -dump_trie_interim_list||| -dump_trie_interim_table||| -dump_trie||| -dump_vindent||5.006000| -dumpuntil||| -dup_attrlist||| -emulate_cop_io||| -eval_pv|5.006000||p -eval_sv|5.006000||p -exec_failed||| -expect_number||| -fbm_compile||5.005000| -fbm_instr||5.005000| -feature_is_enabled||| -filter_add||| -filter_del||| -filter_gets||| -filter_read||| -finalize_optree||| -finalize_op||| -find_and_forget_pmops||| -find_array_subscript||| -find_beginning||| -find_byclass||| -find_default_stash||| -find_hash_subscript||| -find_in_my_stash||| -find_lexical_cv||| -find_runcv_where||| -find_runcv||5.008001| -find_rundefsv2||| -find_rundefsvoffset||5.009002| -find_rundefsv||5.013002| -find_script||| -find_uninit_var||| -first_symbol|||n -fixup_errno_string||| -foldEQ_latin1||5.013008|n -foldEQ_locale||5.013002|n -foldEQ_utf8_flags||5.013010| -foldEQ_utf8||5.013002| -foldEQ||5.013002|n -fold_constants||| -forbid_setid||| -force_ident_maybe_lex||| -force_ident||| -force_list||| -force_next||| -force_strict_version||| -force_version||| -force_word||| -forget_pmop||| -form_nocontext|||vn -form_short_octal_warning||| -form||5.004000|v -fp_dup||| -fprintf_nocontext|||vn -free_c_backtrace||| -free_global_struct||| -free_tied_hv_pool||| -free_tmps||| -gen_constant_list||| -get_ANYOF_cp_list_for_ssc||| -get_and_check_backslash_N_name||| -get_aux_mg||| -get_av|5.006000||p -get_c_backtrace_dump||| -get_c_backtrace||| -get_context||5.006000|n -get_cvn_flags|5.009005||p -get_cvs|5.011000||p -get_cv|5.006000||p -get_db_sub||| -get_debug_opts||| -get_hash_seed||| -get_hv|5.006000||p -get_invlist_iter_addr|||n -get_invlist_offset_addr|||n -get_invlist_previous_index_addr|||n -get_mstats||| -get_no_modify||| -get_num||| -get_op_descs||5.005000| -get_op_names||5.005000| -get_opargs||| -get_ppaddr||5.006000| -get_re_arg||| -get_sv|5.006000||p -get_vtbl||5.005030| -getcwd_sv||5.007002| -getenv_len||| -glob_2number||| -glob_assign_glob||| -gp_dup||| -gp_free||| -gp_ref||| -grok_atoUV|||n -grok_bin|5.007003||p -grok_bslash_N||| -grok_bslash_c||| -grok_bslash_o||| -grok_bslash_x||| -grok_hex|5.007003||p -grok_infnan||5.021004| -grok_number_flags||5.021002| -grok_number|5.007002||p -grok_numeric_radix|5.007002||p -grok_oct|5.007003||p -group_end||| -gv_AVadd||| -gv_HVadd||| -gv_IOadd||| -gv_SVadd||| -gv_add_by_type||5.011000| -gv_autoload4||5.004000| -gv_autoload_pvn||5.015004| -gv_autoload_pv||5.015004| -gv_autoload_sv||5.015004| -gv_check||| -gv_const_sv||5.009003| -gv_dump||5.006000| -gv_efullname3||5.003070| -gv_efullname4||5.006001| -gv_efullname||| -gv_fetchfile_flags||5.009005| -gv_fetchfile||| -gv_fetchmeth_autoload||5.007003| -gv_fetchmeth_internal||| -gv_fetchmeth_pv_autoload||5.015004| -gv_fetchmeth_pvn_autoload||5.015004| -gv_fetchmeth_pvn||5.015004| -gv_fetchmeth_pv||5.015004| -gv_fetchmeth_sv_autoload||5.015004| -gv_fetchmeth_sv||5.015004| -gv_fetchmethod_autoload||5.004000| -gv_fetchmethod_pv_flags||5.015004| -gv_fetchmethod_pvn_flags||5.015004| -gv_fetchmethod_sv_flags||5.015004| -gv_fetchmethod||| -gv_fetchmeth||| -gv_fetchpvn_flags|5.009002||p -gv_fetchpvs|5.009004||p -gv_fetchpv||| -gv_fetchsv|5.009002||p -gv_fullname3||5.003070| -gv_fullname4||5.006001| -gv_fullname||| -gv_handler||5.007001| -gv_init_pvn||5.015004| -gv_init_pv||5.015004| -gv_init_svtype||| -gv_init_sv||5.015004| -gv_init||| -gv_is_in_main||| -gv_magicalize_isa||| -gv_magicalize||| -gv_name_set||5.009004| -gv_override||| -gv_setref||| -gv_stashpvn_internal||| -gv_stashpvn|5.003070||p -gv_stashpvs|5.009003||p -gv_stashpv||| -gv_stashsvpvn_cached||| -gv_stashsv||| -gv_try_downgrade||| -handle_regex_sets||| -he_dup||| -hek_dup||| -hfree_next_entry||| -hfreeentries||| -hsplit||| -hv_assert||| -hv_auxinit_internal|||n -hv_auxinit||| -hv_backreferences_p||| -hv_clear_placeholders||5.009001| -hv_clear||| -hv_common_key_len||5.010000| -hv_common||5.010000| -hv_copy_hints_hv||5.009004| -hv_delayfree_ent||5.004000| -hv_delete_common||| -hv_delete_ent||5.003070| -hv_delete||| -hv_eiter_p||5.009003| -hv_eiter_set||5.009003| -hv_ename_add||| -hv_ename_delete||| -hv_exists_ent||5.003070| -hv_exists||| -hv_fetch_ent||5.003070| -hv_fetchs|5.009003||p -hv_fetch||| -hv_fill||5.013002| -hv_free_ent_ret||| -hv_free_ent||5.004000| -hv_iterinit||| -hv_iterkeysv||5.003070| -hv_iterkey||| -hv_iternext_flags||5.008000| -hv_iternextsv||| -hv_iternext||| -hv_iterval||| -hv_kill_backrefs||| -hv_ksplit||5.003070| -hv_magic_check|||n -hv_magic||| -hv_name_set||5.009003| -hv_notallowed||| -hv_placeholders_get||5.009003| -hv_placeholders_p||| -hv_placeholders_set||5.009003| -hv_rand_set||5.018000| -hv_riter_p||5.009003| -hv_riter_set||5.009003| -hv_scalar||5.009001| -hv_store_ent||5.003070| -hv_store_flags||5.008000| -hv_stores|5.009004||p -hv_store||| -hv_undef_flags||| -hv_undef||| -ibcmp_locale||5.004000| -ibcmp_utf8||5.007003| -ibcmp||| -incline||| -incpush_if_exists||| -incpush_use_sep||| -incpush||| -ingroup||| -init_argv_symbols||| -init_constants||| -init_dbargs||| -init_debugger||| -init_global_struct||| -init_i18nl10n||5.006000| -init_i18nl14n||5.006000| -init_ids||| -init_interp||| -init_main_stash||| -init_perllib||| -init_postdump_symbols||| -init_predump_symbols||| -init_stacks||5.005000| -init_tm||5.007002| -inplace_aassign||| -instr|||n -intro_my||5.004000| -intuit_method||| -intuit_more||| -invert||| -invlist_array|||n -invlist_clone||| -invlist_extend||| -invlist_highest|||n -invlist_is_iterating|||n -invlist_iterfinish|||n -invlist_iterinit|||n -invlist_iternext|||n -invlist_max|||n -invlist_previous_index|||n -invlist_set_len||| -invlist_set_previous_index|||n -invlist_trim|||n -invoke_exception_hook||| -io_close||| -isALNUMC|5.006000||p -isALNUM_lazy||5.021001| -isALPHANUMERIC||5.017008| -isALPHA||| -isASCII|5.006000||p -isBLANK|5.006001||p -isCNTRL|5.006000||p -isDIGIT||| -isFOO_lc||| -isFOO_utf8_lc||| -isGCB|||n -isGRAPH|5.006000||p -isGV_with_GP|5.009004||p -isIDCONT||5.017008| -isIDFIRST_lazy||5.021001| -isIDFIRST||| -isLOWER||| -isOCTAL||5.013005| -isPRINT|5.004000||p -isPSXSPC|5.006001||p -isPUNCT|5.006000||p -isSB||| -isSPACE||| -isUPPER||| -isUTF8_CHAR||5.021001| -isWB||| -isWORDCHAR||5.013006| -isXDIGIT|5.006000||p -is_an_int||| -is_ascii_string||5.011000| -is_handle_constructor|||n -is_invariant_string||5.021007|n -is_lvalue_sub||5.007001| -is_safe_syscall||5.019004| -is_ssc_worth_it|||n -is_uni_alnum_lc||5.006000| -is_uni_alnumc_lc||5.017007| -is_uni_alnumc||5.017007| -is_uni_alnum||5.006000| -is_uni_alpha_lc||5.006000| -is_uni_alpha||5.006000| -is_uni_ascii_lc||5.006000| -is_uni_ascii||5.006000| -is_uni_blank_lc||5.017002| -is_uni_blank||5.017002| -is_uni_cntrl_lc||5.006000| -is_uni_cntrl||5.006000| -is_uni_digit_lc||5.006000| -is_uni_digit||5.006000| -is_uni_graph_lc||5.006000| -is_uni_graph||5.006000| -is_uni_idfirst_lc||5.006000| -is_uni_idfirst||5.006000| -is_uni_lower_lc||5.006000| -is_uni_lower||5.006000| -is_uni_print_lc||5.006000| -is_uni_print||5.006000| -is_uni_punct_lc||5.006000| -is_uni_punct||5.006000| -is_uni_space_lc||5.006000| -is_uni_space||5.006000| -is_uni_upper_lc||5.006000| -is_uni_upper||5.006000| -is_uni_xdigit_lc||5.006000| -is_uni_xdigit||5.006000| -is_utf8_alnumc||5.017007| -is_utf8_alnum||5.006000| -is_utf8_alpha||5.006000| -is_utf8_ascii||5.006000| -is_utf8_blank||5.017002| -is_utf8_char_buf||5.015008|n -is_utf8_char||5.006000|n -is_utf8_cntrl||5.006000| -is_utf8_common||| -is_utf8_digit||5.006000| -is_utf8_graph||5.006000| -is_utf8_idcont||5.008000| -is_utf8_idfirst||5.006000| -is_utf8_lower||5.006000| -is_utf8_mark||5.006000| -is_utf8_perl_space||5.011001| -is_utf8_perl_word||5.011001| -is_utf8_posix_digit||5.011001| -is_utf8_print||5.006000| -is_utf8_punct||5.006000| -is_utf8_space||5.006000| -is_utf8_string_loclen||5.009003|n -is_utf8_string_loc||5.008001|n -is_utf8_string||5.006001|n -is_utf8_upper||5.006000| -is_utf8_xdigit||5.006000| -is_utf8_xidcont||5.013010| -is_utf8_xidfirst||5.013010| -isa_lookup||| -isinfnansv||| -isinfnan||5.021004|n -items|||n -ix|||n -jmaybe||| -join_exact||| -keyword_plugin_standard||| -keyword||| -leave_common||| -leave_scope||| -lex_bufutf8||5.011002| -lex_discard_to||5.011002| -lex_grow_linestr||5.011002| -lex_next_chunk||5.011002| -lex_peek_unichar||5.011002| -lex_read_space||5.011002| -lex_read_to||5.011002| -lex_read_unichar||5.011002| -lex_start||5.009005| -lex_stuff_pvn||5.011002| -lex_stuff_pvs||5.013005| -lex_stuff_pv||5.013006| -lex_stuff_sv||5.011002| -lex_unstuff||5.011002| -listkids||| -list||| -load_module_nocontext|||vn -load_module|5.006000||pv -localize||| -looks_like_bool||| -looks_like_number||| -lop||| -mPUSHi|5.009002||p -mPUSHn|5.009002||p -mPUSHp|5.009002||p -mPUSHs|5.010001||p -mPUSHu|5.009002||p -mXPUSHi|5.009002||p -mXPUSHn|5.009002||p -mXPUSHp|5.009002||p -mXPUSHs|5.010001||p -mXPUSHu|5.009002||p -magic_clear_all_env||| -magic_cleararylen_p||| -magic_clearenv||| -magic_clearhints||| -magic_clearhint||| -magic_clearisa||| -magic_clearpack||| -magic_clearsig||| -magic_copycallchecker||| -magic_dump||5.006000| -magic_existspack||| -magic_freearylen_p||| -magic_freeovrld||| -magic_getarylen||| -magic_getdebugvar||| -magic_getdefelem||| -magic_getnkeys||| -magic_getpack||| -magic_getpos||| -magic_getsig||| -magic_getsubstr||| -magic_gettaint||| -magic_getuvar||| -magic_getvec||| -magic_get||| -magic_killbackrefs||| -magic_methcall1||| -magic_methcall|||v -magic_methpack||| -magic_nextpack||| -magic_regdata_cnt||| -magic_regdatum_get||| -magic_regdatum_set||| -magic_scalarpack||| -magic_set_all_env||| -magic_setarylen||| -magic_setcollxfrm||| -magic_setdbline||| -magic_setdebugvar||| -magic_setdefelem||| -magic_setenv||| -magic_sethint||| -magic_setisa||| -magic_setlvref||| -magic_setmglob||| -magic_setnkeys||| -magic_setpack||| -magic_setpos||| -magic_setregexp||| -magic_setsig||| -magic_setsubstr||| -magic_settaint||| -magic_setutf8||| -magic_setuvar||| -magic_setvec||| -magic_set||| -magic_sizepack||| -magic_wipepack||| -make_matcher||| -make_trie||| -malloc_good_size|||n -malloced_size|||n -malloc||5.007002|n -markstack_grow||5.021001| -matcher_matches_sv||| -maybe_multimagic_gv||| -mayberelocate||| -measure_struct||| -memEQs|5.009005||p -memEQ|5.004000||p -memNEs|5.009005||p -memNE|5.004000||p -mem_collxfrm||| -mem_log_common|||n -mess_alloc||| -mess_nocontext|||vn -mess_sv||5.013001| -mess||5.006000|v -mfree||5.007002|n -mg_clear||| -mg_copy||| -mg_dup||| -mg_find_mglob||| -mg_findext|5.013008||pn -mg_find|||n -mg_free_type||5.013006| -mg_free||| -mg_get||| -mg_length||5.005000| -mg_localize||| -mg_magical|||n -mg_set||| -mg_size||5.005000| -mini_mktime||5.007002|n -minus_v||| -missingterm||| -mode_from_discipline||| -modkids||| -more_bodies||| -more_sv||| -moreswitches||| -move_proto_attr||| -mro_clean_isarev||| -mro_gather_and_rename||| -mro_get_from_name||5.010001| -mro_get_linear_isa_dfs||| -mro_get_linear_isa||5.009005| -mro_get_private_data||5.010001| -mro_isa_changed_in||| -mro_meta_dup||| -mro_meta_init||| -mro_method_changed_in||5.009005| -mro_package_moved||| -mro_register||5.010001| -mro_set_mro||5.010001| -mro_set_private_data||5.010001| -mul128||| -mulexp10|||n -multideref_stringify||| -my_atof2||5.007002| -my_atof||5.006000| -my_attrs||| -my_bcopy|||n -my_bytes_to_utf8|||n -my_bzero|||n -my_chsize||| -my_clearenv||| -my_cxt_index||| -my_cxt_init||| -my_dirfd||5.009005|n -my_exit_jump||| -my_exit||| -my_failure_exit||5.004000| -my_fflush_all||5.006000| -my_fork||5.007003|n -my_kid||| -my_lstat_flags||| -my_lstat||5.021008| -my_memcmp|||n -my_memset|||n -my_pclose||5.003070| -my_popen_list||5.007001| -my_popen||5.003070| -my_setenv||| -my_setlocale||| -my_snprintf|5.009004||pvn -my_socketpair||5.007003|n -my_sprintf|5.009003||pvn -my_stat_flags||| -my_stat||5.021008| -my_strerror||5.021001| -my_strftime||5.007002| -my_strlcat|5.009004||pn -my_strlcpy|5.009004||pn -my_unexec||| -my_vsnprintf||5.009004|n -need_utf8|||n -newANONATTRSUB||5.006000| -newANONHASH||| -newANONLIST||| -newANONSUB||| -newASSIGNOP||| -newATTRSUB_x||| -newATTRSUB||5.006000| -newAVREF||| -newAV||| -newBINOP||| -newCONDOP||| -newCONSTSUB_flags||5.015006| -newCONSTSUB|5.004050||p -newCVREF||| -newDEFSVOP||5.021006| -newFORM||| -newFOROP||5.013007| -newGIVENOP||5.009003| -newGIVWHENOP||| -newGP||| -newGVOP||| -newGVREF||| -newGVgen_flags||5.015004| -newGVgen||| -newHVREF||| -newHVhv||5.005000| -newHV||| -newIO||| -newLISTOP||| -newLOGOP||| -newLOOPEX||| -newLOOPOP||| -newMETHOP_internal||| -newMETHOP_named||5.021005| -newMETHOP||5.021005| -newMYSUB||5.017004| -newNULLLIST||| -newOP||| -newPADNAMELIST||5.021007|n -newPADNAMEouter||5.021007|n -newPADNAMEpvn||5.021007|n -newPADOP||| -newPMOP||| -newPROG||| -newPVOP||| -newRANGE||| -newRV_inc|5.004000||p -newRV_noinc|5.004000||p -newRV||| -newSLICEOP||| -newSTATEOP||| -newSTUB||| -newSUB||| -newSVOP||| -newSVREF||| -newSV_type|5.009005||p -newSVavdefelem||| -newSVhek||5.009003| -newSViv||| -newSVnv||| -newSVpadname||5.017004| -newSVpv_share||5.013006| -newSVpvf_nocontext|||vn -newSVpvf||5.004000|v -newSVpvn_flags|5.010001||p -newSVpvn_share|5.007001||p -newSVpvn_utf8|5.010001||p -newSVpvn|5.004050||p -newSVpvs_flags|5.010001||p -newSVpvs_share|5.009003||p -newSVpvs|5.009003||p -newSVpv||| -newSVrv||| -newSVsv||| -newSVuv|5.006000||p -newSV||| -newUNOP_AUX||5.021007| -newUNOP||| -newWHENOP||5.009003| -newWHILEOP||5.013007| -newXS_deffile||| -newXS_flags||5.009004| -newXS_len_flags||| -newXSproto||5.006000| -newXS||5.006000| -new_collate||5.006000| -new_constant||| -new_ctype||5.006000| -new_he||| -new_logop||| -new_numeric||5.006000| -new_stackinfo||5.005000| -new_version||5.009000| -new_warnings_bitfield||| -next_symbol||| -nextargv||| -nextchar||| -ninstr|||n -no_bareword_allowed||| -no_fh_allowed||| -no_op||| -noperl_die|||vn -not_a_number||| -not_incrementable||| -nothreadhook||5.008000| -nuke_stacks||| -num_overflow|||n -oopsAV||| -oopsHV||| -op_append_elem||5.013006| -op_append_list||5.013006| -op_clear||| -op_contextualize||5.013006| -op_convert_list||5.021006| -op_dump||5.006000| -op_free||| -op_integerize||| -op_linklist||5.013006| -op_lvalue_flags||| -op_lvalue||5.013007| -op_null||5.007002| -op_parent||5.021002|n -op_prepend_elem||5.013006| -op_refcnt_dec||| -op_refcnt_inc||| -op_refcnt_lock||5.009002| -op_refcnt_unlock||5.009002| -op_relocate_sv||| -op_scope||5.013007| -op_sibling_splice||5.021002|n -op_std_init||| -op_unscope||| -open_script||| -openn_cleanup||| -openn_setup||| -opmethod_stash||| -opslab_force_free||| -opslab_free_nopad||| -opslab_free||| -pMY_CXT_|5.007003||p -pMY_CXT|5.007003||p -pTHX_|5.006000||p -pTHX|5.006000||p -packWARN|5.007003||p -pack_cat||5.007003| -pack_rec||| -package_version||| -package||| -packlist||5.008001| -pad_add_anon||5.008001| -pad_add_name_pvn||5.015001| -pad_add_name_pvs||5.015001| -pad_add_name_pv||5.015001| -pad_add_name_sv||5.015001| -pad_add_weakref||| -pad_alloc_name||| -pad_alloc||| -pad_block_start||| -pad_check_dup||| -pad_compname_type||5.009003| -pad_findlex||| -pad_findmy_pvn||5.015001| -pad_findmy_pvs||5.015001| -pad_findmy_pv||5.015001| -pad_findmy_sv||5.015001| -pad_fixup_inner_anons||| -pad_free||| -pad_leavemy||| -pad_new||5.008001| -pad_push||| -pad_reset||| -pad_setsv||| -pad_sv||| -pad_swipe||| -pad_tidy||5.008001| -padlist_dup||| -padlist_store||| -padname_dup||| -padname_free||| -padnamelist_dup||| -padnamelist_fetch||5.021007|n -padnamelist_free||| -padnamelist_store||5.021007| -parse_arithexpr||5.013008| -parse_barestmt||5.013007| -parse_block||5.013007| -parse_body||| -parse_fullexpr||5.013008| -parse_fullstmt||5.013005| -parse_gv_stash_name||| -parse_ident||| -parse_label||5.013007| -parse_listexpr||5.013008| -parse_lparen_question_flags||| -parse_stmtseq||5.013006| -parse_subsignature||| -parse_termexpr||5.013008| -parse_unicode_opts||| -parser_dup||| -parser_free_nexttoke_ops||| -parser_free||| -path_is_searchable|||n -peep||| -pending_ident||| -perl_alloc_using|||n -perl_alloc|||n -perl_clone_using|||n -perl_clone|||n -perl_construct|||n -perl_destruct||5.007003|n -perl_free|||n -perl_parse||5.006000|n -perl_run|||n -pidgone||| -pm_description||| -pmop_dump||5.006000| -pmruntime||| -pmtrans||| -pop_scope||| -populate_ANYOF_from_invlist||| -populate_isa|||v -pregcomp||5.009005| -pregexec||| -pregfree2||5.011000| -pregfree||| -prescan_version||5.011004| -printbuf||| -printf_nocontext|||vn -process_special_blocks||| -ptr_hash|||n -ptr_table_clear||5.009005| -ptr_table_fetch||5.009005| -ptr_table_find|||n -ptr_table_free||5.009005| -ptr_table_new||5.009005| -ptr_table_split||5.009005| -ptr_table_store||5.009005| -push_scope||| -put_charclass_bitmap_innards||| -put_code_point||| -put_range||| -pv_display|5.006000||p -pv_escape|5.009004||p -pv_pretty|5.009004||p -pv_uni_display||5.007003| -qerror||| -qsortsvu||| -quadmath_format_needed|||n -quadmath_format_single|||n -re_compile||5.009005| -re_croak2||| -re_dup_guts||| -re_intuit_start||5.019001| -re_intuit_string||5.006000| -re_op_compile||| -realloc||5.007002|n -reentrant_free||5.021008| -reentrant_init||5.021008| -reentrant_retry||5.021008|vn -reentrant_size||5.021008| -ref_array_or_hash||| -refcounted_he_chain_2hv||| -refcounted_he_fetch_pvn||| -refcounted_he_fetch_pvs||| -refcounted_he_fetch_pv||| -refcounted_he_fetch_sv||| -refcounted_he_free||| -refcounted_he_inc||| -refcounted_he_new_pvn||| -refcounted_he_new_pvs||| -refcounted_he_new_pv||| -refcounted_he_new_sv||| -refcounted_he_value||| -refkids||| -refto||| -ref||5.021008| -reg2Lanode||| -reg_check_named_buff_matched|||n -reg_named_buff_all||5.009005| -reg_named_buff_exists||5.009005| -reg_named_buff_fetch||5.009005| -reg_named_buff_firstkey||5.009005| -reg_named_buff_iter||| -reg_named_buff_nextkey||5.009005| -reg_named_buff_scalar||5.009005| -reg_named_buff||| -reg_node||| -reg_numbered_buff_fetch||| -reg_numbered_buff_length||| -reg_numbered_buff_store||| -reg_qr_package||| -reg_recode||| -reg_scan_name||| -reg_skipcomment|||n -reg_temp_copy||| -reganode||| -regatom||| -regbranch||| -regclass_swash||5.009004| -regclass||| -regcppop||| -regcppush||| -regcurly|||n -regdump_extflags||| -regdump_intflags||| -regdump||5.005000| -regdupe_internal||| -regexec_flags||5.005000| -regfree_internal||5.009005| -reghop3|||n -reghop4|||n -reghopmaybe3|||n -reginclass||| -reginitcolors||5.006000| -reginsert||| -regmatch||| -regnext||5.005000| -regnode_guts||| -regpatws|||n -regpiece||| -regpposixcc||| -regprop||| -regrepeat||| -regtail_study||| -regtail||| -regtry||| -reg||| -repeatcpy|||n -report_evil_fh||| -report_redefined_cv||| -report_uninit||| -report_wrongway_fh||| -require_pv||5.006000| -require_tie_mod||| -restore_magic||| -rninstr|||n -rpeep||| -rsignal_restore||| -rsignal_save||| -rsignal_state||5.004000| -rsignal||5.004000| -run_body||| -run_user_filter||| -runops_debug||5.005000| -runops_standard||5.005000| -rv2cv_op_cv||5.013006| -rvpv_dup||| -rxres_free||| -rxres_restore||| -rxres_save||| -safesyscalloc||5.006000|n -safesysfree||5.006000|n -safesysmalloc||5.006000|n -safesysrealloc||5.006000|n -same_dirent||| -save_I16||5.004000| -save_I32||| -save_I8||5.006000| -save_adelete||5.011000| -save_aelem_flags||5.011000| -save_aelem||5.004050| -save_aliased_sv||| -save_alloc||5.006000| -save_aptr||| -save_ary||| -save_bool||5.008001| -save_clearsv||| -save_delete||| -save_destructor_x||5.006000| -save_destructor||5.006000| -save_freeop||| -save_freepv||| -save_freesv||| -save_generic_pvref||5.006001| -save_generic_svref||5.005030| -save_gp||5.004000| -save_hash||| -save_hdelete||5.011000| -save_hek_flags|||n -save_helem_flags||5.011000| -save_helem||5.004050| -save_hints||5.010001| -save_hptr||| -save_int||| -save_item||| -save_iv||5.005000| -save_lines||| -save_list||| -save_long||| -save_magic_flags||| -save_mortalizesv||5.007001| -save_nogv||| -save_op||5.005000| -save_padsv_and_mortalize||5.010001| -save_pptr||| -save_pushi32ptr||5.010001| -save_pushptri32ptr||| -save_pushptrptr||5.010001| -save_pushptr||5.010001| -save_re_context||5.006000| -save_scalar_at||| -save_scalar||| -save_set_svflags||5.009000| -save_shared_pvref||5.007003| -save_sptr||| -save_strlen||| -save_svref||| -save_vptr||5.006000| -savepvn||| -savepvs||5.009003| -savepv||| -savesharedpvn||5.009005| -savesharedpvs||5.013006| -savesharedpv||5.007003| -savesharedsvpv||5.013006| -savestack_grow_cnt||5.008001| -savestack_grow||| -savesvpv||5.009002| -sawparens||| -scalar_mod_type|||n -scalarboolean||| -scalarkids||| -scalarseq||| -scalarvoid||| -scalar||| -scan_bin||5.006000| -scan_commit||| -scan_const||| -scan_formline||| -scan_heredoc||| -scan_hex||| -scan_ident||| -scan_inputsymbol||| -scan_num||5.007001| -scan_oct||| -scan_pat||| -scan_str||| -scan_subst||| -scan_trans||| -scan_version||5.009001| -scan_vstring||5.009005| -scan_word||| -search_const||| -seed||5.008001| -sequence_num||| -set_ANYOF_arg||| -set_caret_X||| -set_context||5.006000|n -set_numeric_local||5.006000| -set_numeric_radix||5.006000| -set_numeric_standard||5.006000| -set_padlist|||n -setdefout||| -share_hek_flags||| -share_hek||5.004000| -should_warn_nl|||n -si_dup||| -sighandler|||n -simplify_sort||| -skipspace_flags||| -softref2xv||| -sortcv_stacked||| -sortcv_xsub||| -sortcv||| -sortsv_flags||5.009003| -sortsv||5.007003| -space_join_names_mortal||| -ss_dup||| -ssc_add_range||| -ssc_and||| -ssc_anything||| -ssc_clear_locale|||n -ssc_cp_and||| -ssc_finalize||| -ssc_init||| -ssc_intersection||| -ssc_is_anything|||n -ssc_is_cp_posixl_init|||n -ssc_or||| -ssc_union||| -stack_grow||| -start_glob||| -start_subparse||5.004000| -stdize_locale||| -strEQ||| -strGE||| -strGT||| -strLE||| -strLT||| -strNE||| -str_to_version||5.006000| -strip_return||| -strnEQ||| -strnNE||| -study_chunk||| -sub_crush_depth||| -sublex_done||| -sublex_push||| -sublex_start||| -sv_2bool_flags||5.013006| -sv_2bool||| -sv_2cv||| -sv_2io||| -sv_2iuv_common||| -sv_2iuv_non_preserve||| -sv_2iv_flags||5.009001| -sv_2iv||| -sv_2mortal||| -sv_2num||| -sv_2nv_flags||5.013001| -sv_2pv_flags|5.007002||p -sv_2pv_nolen|5.006000||p -sv_2pvbyte_nolen|5.006000||p -sv_2pvbyte|5.006000||p -sv_2pvutf8_nolen||5.006000| -sv_2pvutf8||5.006000| -sv_2pv||| -sv_2uv_flags||5.009001| -sv_2uv|5.004000||p -sv_add_arena||| -sv_add_backref||| -sv_backoff|||n -sv_bless||| -sv_buf_to_ro||| -sv_buf_to_rw||| -sv_cat_decode||5.008001| -sv_catpv_flags||5.013006| -sv_catpv_mg|5.004050||p -sv_catpv_nomg||5.013006| -sv_catpvf_mg_nocontext|||pvn -sv_catpvf_mg|5.006000|5.004000|pv -sv_catpvf_nocontext|||vn -sv_catpvf||5.004000|v -sv_catpvn_flags||5.007002| -sv_catpvn_mg|5.004050||p -sv_catpvn_nomg|5.007002||p -sv_catpvn||| -sv_catpvs_flags||5.013006| -sv_catpvs_mg||5.013006| -sv_catpvs_nomg||5.013006| -sv_catpvs|5.009003||p -sv_catpv||| -sv_catsv_flags||5.007002| -sv_catsv_mg|5.004050||p -sv_catsv_nomg|5.007002||p -sv_catsv||| -sv_chop||| -sv_clean_all||| -sv_clean_objs||| -sv_clear||| -sv_cmp_flags||5.013006| -sv_cmp_locale_flags||5.013006| -sv_cmp_locale||5.004000| -sv_cmp||| -sv_collxfrm_flags||5.013006| -sv_collxfrm||| -sv_copypv_flags||5.017002| -sv_copypv_nomg||5.017002| -sv_copypv||| -sv_dec_nomg||5.013002| -sv_dec||| -sv_del_backref||| -sv_derived_from_pvn||5.015004| -sv_derived_from_pv||5.015004| -sv_derived_from_sv||5.015004| -sv_derived_from||5.004000| -sv_destroyable||5.010000| -sv_display||| -sv_does_pvn||5.015004| -sv_does_pv||5.015004| -sv_does_sv||5.015004| -sv_does||5.009004| -sv_dump||| -sv_dup_common||| -sv_dup_inc_multiple||| -sv_dup_inc||| -sv_dup||| -sv_eq_flags||5.013006| -sv_eq||| -sv_exp_grow||| -sv_force_normal_flags||5.007001| -sv_force_normal||5.006000| -sv_free2||| -sv_free_arenas||| -sv_free||| -sv_get_backrefs||5.021008|n -sv_gets||5.003070| -sv_grow||| -sv_i_ncmp||| -sv_inc_nomg||5.013002| -sv_inc||| -sv_insert_flags||5.010001| -sv_insert||| -sv_isa||| -sv_isobject||| -sv_iv||5.005000| -sv_kill_backrefs||| -sv_len_utf8_nomg||| -sv_len_utf8||5.006000| -sv_len||| -sv_magic_portable|5.021008|5.004000|p -sv_magicext_mglob||| -sv_magicext||5.007003| -sv_magic||| -sv_mortalcopy_flags||| -sv_mortalcopy||| -sv_ncmp||| -sv_newmortal||| -sv_newref||| -sv_nolocking||5.007003| -sv_nosharing||5.007003| -sv_nounlocking||| -sv_nv||5.005000| -sv_only_taint_gmagic|||n -sv_or_pv_pos_u2b||| -sv_peek||5.005000| -sv_pos_b2u_flags||5.019003| -sv_pos_b2u_midway||| -sv_pos_b2u||5.006000| -sv_pos_u2b_cached||| -sv_pos_u2b_flags||5.011005| -sv_pos_u2b_forwards|||n -sv_pos_u2b_midway|||n -sv_pos_u2b||5.006000| -sv_pvbyten_force||5.006000| -sv_pvbyten||5.006000| -sv_pvbyte||5.006000| -sv_pvn_force_flags|5.007002||p -sv_pvn_force||| -sv_pvn_nomg|5.007003|5.005000|p -sv_pvn||5.005000| -sv_pvutf8n_force||5.006000| -sv_pvutf8n||5.006000| -sv_pvutf8||5.006000| -sv_pv||5.006000| -sv_recode_to_utf8||5.007003| -sv_reftype||| -sv_ref||| -sv_release_COW||| -sv_replace||| -sv_report_used||| -sv_resetpvn||| -sv_reset||| -sv_rvweaken||5.006000| -sv_sethek||| -sv_setiv_mg|5.004050||p -sv_setiv||| -sv_setnv_mg|5.006000||p -sv_setnv||| -sv_setpv_mg|5.004050||p -sv_setpvf_mg_nocontext|||pvn -sv_setpvf_mg|5.006000|5.004000|pv -sv_setpvf_nocontext|||vn -sv_setpvf||5.004000|v -sv_setpviv_mg||5.008001| -sv_setpviv||5.008001| -sv_setpvn_mg|5.004050||p -sv_setpvn||| -sv_setpvs_mg||5.013006| -sv_setpvs|5.009004||p -sv_setpv||| -sv_setref_iv||| -sv_setref_nv||| -sv_setref_pvn||| -sv_setref_pvs||5.021008| -sv_setref_pv||| -sv_setref_uv||5.007001| -sv_setsv_cow||| -sv_setsv_flags||5.007002| -sv_setsv_mg|5.004050||p -sv_setsv_nomg|5.007002||p -sv_setsv||| -sv_setuv_mg|5.004050||p -sv_setuv|5.004000||p -sv_tainted||5.004000| -sv_taint||5.004000| -sv_true||5.005000| -sv_unglob||| -sv_uni_display||5.007003| -sv_unmagicext|5.013008||p -sv_unmagic||| -sv_unref_flags||5.007001| -sv_unref||| -sv_untaint||5.004000| -sv_upgrade||| -sv_usepvn_flags||5.009004| -sv_usepvn_mg|5.004050||p -sv_usepvn||| -sv_utf8_decode||5.006000| -sv_utf8_downgrade||5.006000| -sv_utf8_encode||5.006000| -sv_utf8_upgrade_flags_grow||5.011000| -sv_utf8_upgrade_flags||5.007002| -sv_utf8_upgrade_nomg||5.007002| -sv_utf8_upgrade||5.007001| -sv_uv|5.005000||p -sv_vcatpvf_mg|5.006000|5.004000|p -sv_vcatpvfn_flags||5.017002| -sv_vcatpvfn||5.004000| -sv_vcatpvf|5.006000|5.004000|p -sv_vsetpvf_mg|5.006000|5.004000|p -sv_vsetpvfn||5.004000| -sv_vsetpvf|5.006000|5.004000|p -svtype||| -swallow_bom||| -swash_fetch||5.007002| -swash_init||5.006000| -swash_scan_list_line||| -swatch_get||| -sync_locale||5.021004| -sys_init3||5.010000|n -sys_init||5.010000|n -sys_intern_clear||| -sys_intern_dup||| -sys_intern_init||| -sys_term||5.010000|n -taint_env||| -taint_proper||| -tied_method|||v -tmps_grow_p||| -toFOLD_uni||5.007003| -toFOLD_utf8||5.019001| -toFOLD||5.019001| -toLOWER_L1||5.019001| -toLOWER_LC||5.004000| -toLOWER_uni||5.007003| -toLOWER_utf8||5.015007| -toLOWER||| -toTITLE_uni||5.007003| -toTITLE_utf8||5.015007| -toTITLE||5.019001| -toUPPER_uni||5.007003| -toUPPER_utf8||5.015007| -toUPPER||| -to_byte_substr||| -to_lower_latin1|||n -to_uni_fold||5.007003| -to_uni_lower_lc||5.006000| -to_uni_lower||5.007003| -to_uni_title_lc||5.006000| -to_uni_title||5.007003| -to_uni_upper_lc||5.006000| -to_uni_upper||5.007003| -to_utf8_case||5.007003| -to_utf8_fold||5.015007| -to_utf8_lower||5.015007| -to_utf8_substr||| -to_utf8_title||5.015007| -to_utf8_upper||5.015007| -tokenize_use||| -tokeq||| -tokereport||| -too_few_arguments_pv||| -too_many_arguments_pv||| -translate_substr_offsets|||n -try_amagic_bin||| -try_amagic_un||| -uiv_2buf|||n -unlnk||| -unpack_rec||| -unpack_str||5.007003| -unpackstring||5.008001| -unreferenced_to_tmp_stack||| -unshare_hek_or_pvn||| -unshare_hek||| -unsharepvn||5.003070| -unwind_handler_stack||| -update_debugger_info||| -upg_version||5.009005| -usage||| -utf16_textfilter||| -utf16_to_utf8_reversed||5.006001| -utf16_to_utf8||5.006001| -utf8_distance||5.006000| -utf8_hop||5.006000|n -utf8_length||5.007001| -utf8_mg_len_cache_update||| -utf8_mg_pos_cache_update||| -utf8_to_bytes||5.006001| -utf8_to_uvchr_buf||5.015009| -utf8_to_uvchr||5.007001| -utf8_to_uvuni_buf||5.015009| -utf8_to_uvuni||5.007001| -utf8n_to_uvchr||5.007001| -utf8n_to_uvuni||5.007001| -utilize||| -uvchr_to_utf8_flags||5.007003| -uvchr_to_utf8||5.007001| -uvoffuni_to_utf8_flags||5.019004| -uvuni_to_utf8_flags||5.007003| -uvuni_to_utf8||5.007001| -valid_utf8_to_uvchr||5.015009| -valid_utf8_to_uvuni||5.015009| -validate_proto||| -validate_suid||| -varname||| -vcmp||5.009000| -vcroak||5.006000| -vdeb||5.007003| -vform||5.006000| -visit||| -vivify_defelem||| -vivify_ref||| -vload_module|5.006000||p -vmess||5.006000| -vnewSVpvf|5.006000|5.004000|p -vnormal||5.009002| -vnumify||5.009000| -vstringify||5.009000| -vverify||5.009003| -vwarner||5.006000| -vwarn||5.006000| -wait4pid||| -warn_nocontext|||vn -warn_sv||5.013001| -warner_nocontext|||vn -warner|5.006000|5.004000|pv -warn|||v -was_lvalue_sub||| -watch||| -whichsig_pvn||5.015004| -whichsig_pv||5.015004| -whichsig_sv||5.015004| -whichsig||| -win32_croak_not_implemented|||n -with_queued_errors||| -wrap_op_checker||5.015008| -write_to_stderr||| -xs_boot_epilog||| -xs_handshake|||vn -xs_version_bootcheck||| -yyerror_pvn||| -yyerror_pv||| -yyerror||| -yylex||| -yyparse||| -yyunlex||| -yywarn||| -); - -if (exists $opt{'list-unsupported'}) { - my $f; - for $f (sort { lc $a cmp lc $b } keys %API) { - next unless $API{$f}{todo}; - print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n"; - } - exit 0; -} - -# Scan for possible replacement candidates - -my(%replace, %need, %hints, %warnings, %depends); -my $replace = 0; -my($hint, $define, $function); - -sub find_api -{ - my $code = shift; - $code =~ s{ - / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*) - | "[^"\\]*(?:\\.[^"\\]*)*" - | '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx; - grep { exists $API{$_} } $code =~ /(\w+)/mg; -} - -while () { - if ($hint) { - my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings; - if (m{^\s*\*\s(.*?)\s*$}) { - for (@{$hint->[1]}) { - $h->{$_} ||= ''; # suppress warning with older perls - $h->{$_} .= "$1\n"; - } - } - else { undef $hint } - } - - $hint = [$1, [split /,?\s+/, $2]] - if m{^\s*$rccs\s+(Hint|Warning):\s+(\w+(?:,?\s+\w+)*)\s*$}; - - if ($define) { - if ($define->[1] =~ /\\$/) { - $define->[1] .= $_; - } - else { - if (exists $API{$define->[0]} && $define->[1] !~ /^DPPP_\(/) { - my @n = find_api($define->[1]); - push @{$depends{$define->[0]}}, @n if @n - } - undef $define; - } - } - - $define = [$1, $2] if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(.*)}; - - if ($function) { - if (/^}/) { - if (exists $API{$function->[0]}) { - my @n = find_api($function->[1]); - push @{$depends{$function->[0]}}, @n if @n - } - undef $function; - } - else { - $function->[1] .= $_; - } - } - - $function = [$1, ''] if m{^DPPP_\(my_(\w+)\)}; - - $replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$}; - $replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)}; - $replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce}; - $replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$}; - - if (m{^\s*$rccs\s+(\w+(\s*,\s*\w+)*)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) { - my @deps = map { s/\s+//g; $_ } split /,/, $3; - my $d; - for $d (map { s/\s+//g; $_ } split /,/, $1) { - push @{$depends{$d}}, @deps; - } - } - - $need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)}; -} - -for (values %depends) { - my %s; - $_ = [sort grep !$s{$_}++, @$_]; -} - -if (exists $opt{'api-info'}) { - my $f; - my $count = 0; - my $match = $opt{'api-info'} =~ m!^/(.*)/$! ? $1 : "^\Q$opt{'api-info'}\E\$"; - for $f (sort { lc $a cmp lc $b } keys %API) { - next unless $f =~ /$match/; - print "\n=== $f ===\n\n"; - my $info = 0; - if ($API{$f}{base} || $API{$f}{todo}) { - my $base = format_version($API{$f}{base} || $API{$f}{todo}); - print "Supported at least starting from perl-$base.\n"; - $info++; - } - if ($API{$f}{provided}) { - my $todo = $API{$f}{todo} ? format_version($API{$f}{todo}) : "5.003"; - print "Support by $ppport provided back to perl-$todo.\n"; - print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f}; - print "Depends on: ", join(', ', @{$depends{$f}}), ".\n" if exists $depends{$f}; - print "\n$hints{$f}" if exists $hints{$f}; - print "\nWARNING:\n$warnings{$f}" if exists $warnings{$f}; - $info++; - } - print "No portability information available.\n" unless $info; - $count++; - } - $count or print "Found no API matching '$opt{'api-info'}'."; - print "\n"; - exit 0; -} - -if (exists $opt{'list-provided'}) { - my $f; - for $f (sort { lc $a cmp lc $b } keys %API) { - next unless $API{$f}{provided}; - my @flags; - push @flags, 'explicit' if exists $need{$f}; - push @flags, 'depend' if exists $depends{$f}; - push @flags, 'hint' if exists $hints{$f}; - push @flags, 'warning' if exists $warnings{$f}; - my $flags = @flags ? ' ['.join(', ', @flags).']' : ''; - print "$f$flags\n"; - } - exit 0; -} - -my @files; -my @srcext = qw( .xs .c .h .cc .cpp -c.inc -xs.inc ); -my $srcext = join '|', map { quotemeta $_ } @srcext; - -if (@ARGV) { - my %seen; - for (@ARGV) { - if (-e) { - if (-f) { - push @files, $_ unless $seen{$_}++; - } - else { warn "'$_' is not a file.\n" } - } - else { - my @new = grep { -f } glob $_ - or warn "'$_' does not exist.\n"; - push @files, grep { !$seen{$_}++ } @new; - } - } -} -else { - eval { - require File::Find; - File::Find::find(sub { - $File::Find::name =~ /($srcext)$/i - and push @files, $File::Find::name; - }, '.'); - }; - if ($@) { - @files = map { glob "*$_" } @srcext; - } -} - -if (!@ARGV || $opt{filter}) { - my(@in, @out); - my %xsc = map { /(.*)\.xs$/ ? ("$1.c" => 1, "$1.cc" => 1) : () } @files; - for (@files) { - my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/($srcext)$/i; - push @{ $out ? \@out : \@in }, $_; - } - if (@ARGV && @out) { - warning("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out); - } - @files = @in; -} - -die "No input files given!\n" unless @files; - -my(%files, %global, %revreplace); -%revreplace = reverse %replace; -my $filename; -my $patch_opened = 0; - -for $filename (@files) { - unless (open IN, "<$filename") { - warn "Unable to read from $filename: $!\n"; - next; - } - - info("Scanning $filename ..."); - - my $c = do { local $/; }; - close IN; - - my %file = (orig => $c, changes => 0); - - # Temporarily remove C/XS comments and strings from the code - my @ccom; - - $c =~ s{ - ( ^$HS*\#$HS*include\b[^\r\n]+\b(?:\Q$ppport\E|XSUB\.h)\b[^\r\n]* - | ^$HS*\#$HS*(?:define|elif|if(?:def)?)\b[^\r\n]* ) - | ( ^$HS*\#[^\r\n]* - | "[^"\\]*(?:\\.[^"\\]*)*" - | '[^'\\]*(?:\\.[^'\\]*)*' - | / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]* ) ) - }{ defined $2 and push @ccom, $2; - defined $1 ? $1 : "$ccs$#ccom$cce" }mgsex; - - $file{ccom} = \@ccom; - $file{code} = $c; - $file{has_inc_ppport} = $c =~ /^$HS*#$HS*include[^\r\n]+\b\Q$ppport\E\b/m; - - my $func; - - for $func (keys %API) { - my $match = $func; - $match .= "|$revreplace{$func}" if exists $revreplace{$func}; - if ($c =~ /\b(?:Perl_)?($match)\b/) { - $file{uses_replace}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func}; - $file{uses_Perl}{$func}++ if $c =~ /\bPerl_$func\b/; - if (exists $API{$func}{provided}) { - $file{uses_provided}{$func}++; - if (!exists $API{$func}{base} || $API{$func}{base} > $opt{'compat-version'}) { - $file{uses}{$func}++; - my @deps = rec_depend($func); - if (@deps) { - $file{uses_deps}{$func} = \@deps; - for (@deps) { - $file{uses}{$_} = 0 unless exists $file{uses}{$_}; - } - } - for ($func, @deps) { - $file{needs}{$_} = 'static' if exists $need{$_}; - } - } - } - if (exists $API{$func}{todo} && $API{$func}{todo} > $opt{'compat-version'}) { - if ($c =~ /\b$func\b/) { - $file{uses_todo}{$func}++; - } - } - } - } - - while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) { - if (exists $need{$2}) { - $file{defined $3 ? 'needed_global' : 'needed_static'}{$2}++; - } - else { warning("Possibly wrong #define $1 in $filename") } - } - - for (qw(uses needs uses_todo needed_global needed_static)) { - for $func (keys %{$file{$_}}) { - push @{$global{$_}{$func}}, $filename; - } - } - - $files{$filename} = \%file; -} - -# Globally resolve NEED_'s -my $need; -for $need (keys %{$global{needs}}) { - if (@{$global{needs}{$need}} > 1) { - my @targets = @{$global{needs}{$need}}; - my @t = grep $files{$_}{needed_global}{$need}, @targets; - @targets = @t if @t; - @t = grep /\.xs$/i, @targets; - @targets = @t if @t; - my $target = shift @targets; - $files{$target}{needs}{$need} = 'global'; - for (@{$global{needs}{$need}}) { - $files{$_}{needs}{$need} = 'extern' if $_ ne $target; - } - } -} - -for $filename (@files) { - exists $files{$filename} or next; - - info("=== Analyzing $filename ==="); - - my %file = %{$files{$filename}}; - my $func; - my $c = $file{code}; - my $warnings = 0; - - for $func (sort keys %{$file{uses_Perl}}) { - if ($API{$func}{varargs}) { - unless ($API{$func}{nothxarg}) { - my $changes = ($c =~ s{\b(Perl_$func\s*\(\s*)(?!aTHX_?)(\)|[^\s)]*\))} - { $1 . ($2 eq ')' ? 'aTHX' : 'aTHX_ ') . $2 }ge); - if ($changes) { - warning("Doesn't pass interpreter argument aTHX to Perl_$func"); - $file{changes} += $changes; - } - } - } - else { - warning("Uses Perl_$func instead of $func"); - $file{changes} += ($c =~ s{\bPerl_$func(\s*)\((\s*aTHX_?)?\s*} - {$func$1(}g); - } - } - - for $func (sort keys %{$file{uses_replace}}) { - warning("Uses $func instead of $replace{$func}"); - $file{changes} += ($c =~ s/\b$func\b/$replace{$func}/g); - } - - for $func (sort keys %{$file{uses_provided}}) { - if ($file{uses}{$func}) { - if (exists $file{uses_deps}{$func}) { - diag("Uses $func, which depends on ", join(', ', @{$file{uses_deps}{$func}})); - } - else { - diag("Uses $func"); - } - } - $warnings += hint($func); - } - - unless ($opt{quiet}) { - for $func (sort keys %{$file{uses_todo}}) { - print "*** WARNING: Uses $func, which may not be portable below perl ", - format_version($API{$func}{todo}), ", even with '$ppport'\n"; - $warnings++; - } - } - - for $func (sort keys %{$file{needed_static}}) { - my $message = ''; - if (not exists $file{uses}{$func}) { - $message = "No need to define NEED_$func if $func is never used"; - } - elsif (exists $file{needs}{$func} && $file{needs}{$func} ne 'static') { - $message = "No need to define NEED_$func when already needed globally"; - } - if ($message) { - diag($message); - $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg); - } - } - - for $func (sort keys %{$file{needed_global}}) { - my $message = ''; - if (not exists $global{uses}{$func}) { - $message = "No need to define NEED_${func}_GLOBAL if $func is never used"; - } - elsif (exists $file{needs}{$func}) { - if ($file{needs}{$func} eq 'extern') { - $message = "No need to define NEED_${func}_GLOBAL when already needed globally"; - } - elsif ($file{needs}{$func} eq 'static') { - $message = "No need to define NEED_${func}_GLOBAL when only used in this file"; - } - } - if ($message) { - diag($message); - $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg); - } - } - - $file{needs_inc_ppport} = keys %{$file{uses}}; - - if ($file{needs_inc_ppport}) { - my $pp = ''; - - for $func (sort keys %{$file{needs}}) { - my $type = $file{needs}{$func}; - next if $type eq 'extern'; - my $suffix = $type eq 'global' ? '_GLOBAL' : ''; - unless (exists $file{"needed_$type"}{$func}) { - if ($type eq 'global') { - diag("Files [@{$global{needs}{$func}}] need $func, adding global request"); - } - else { - diag("File needs $func, adding static request"); - } - $pp .= "#define NEED_$func$suffix\n"; - } - } - - if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) { - $pp = ''; - $file{changes}++; - } - - unless ($file{has_inc_ppport}) { - diag("Needs to include '$ppport'"); - $pp .= qq(#include "$ppport"\n) - } - - if ($pp) { - $file{changes} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms) - || ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m) - || ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m) - || ($c =~ s/^/$pp/); - } - } - else { - if ($file{has_inc_ppport}) { - diag("No need to include '$ppport'"); - $file{changes} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m); - } - } - - # put back in our C comments - my $ix; - my $cppc = 0; - my @ccom = @{$file{ccom}}; - for $ix (0 .. $#ccom) { - if (!$opt{cplusplus} && $ccom[$ix] =~ s!^//!!) { - $cppc++; - $file{changes} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/; - } - else { - $c =~ s/$rccs$ix$rcce/$ccom[$ix]/; - } - } - - if ($cppc) { - my $s = $cppc != 1 ? 's' : ''; - warning("Uses $cppc C++ style comment$s, which is not portable"); - } - - my $s = $warnings != 1 ? 's' : ''; - my $warn = $warnings ? " ($warnings warning$s)" : ''; - info("Analysis completed$warn"); - - if ($file{changes}) { - if (exists $opt{copy}) { - my $newfile = "$filename$opt{copy}"; - if (-e $newfile) { - error("'$newfile' already exists, refusing to write copy of '$filename'"); - } - else { - local *F; - if (open F, ">$newfile") { - info("Writing copy of '$filename' with changes to '$newfile'"); - print F $c; - close F; - } - else { - error("Cannot open '$newfile' for writing: $!"); - } - } - } - elsif (exists $opt{patch} || $opt{changes}) { - if (exists $opt{patch}) { - unless ($patch_opened) { - if (open PATCH, ">$opt{patch}") { - $patch_opened = 1; - } - else { - error("Cannot open '$opt{patch}' for writing: $!"); - delete $opt{patch}; - $opt{changes} = 1; - goto fallback; - } - } - mydiff(\*PATCH, $filename, $c); - } - else { -fallback: - info("Suggested changes:"); - mydiff(\*STDOUT, $filename, $c); - } - } - else { - my $s = $file{changes} == 1 ? '' : 's'; - info("$file{changes} potentially required change$s detected"); - } - } - else { - info("Looks good"); - } -} - -close PATCH if $patch_opened; - -exit 0; - - -sub try_use { eval "use @_;"; return $@ eq '' } - -sub mydiff -{ - local *F = shift; - my($file, $str) = @_; - my $diff; - - if (exists $opt{diff}) { - $diff = run_diff($opt{diff}, $file, $str); - } - - if (!defined $diff and try_use('Text::Diff')) { - $diff = Text::Diff::diff($file, \$str, { STYLE => 'Unified' }); - $diff = <
$tmp") { - print F $str; - close F; - - if (open F, "$prog $file $tmp |") { - while () { - s/\Q$tmp\E/$file.patched/; - $diff .= $_; - } - close F; - unlink $tmp; - return $diff; - } - - unlink $tmp; - } - else { - error("Cannot open '$tmp' for writing: $!"); - } - - return undef; -} - -sub rec_depend -{ - my($func, $seen) = @_; - return () unless exists $depends{$func}; - $seen = {%{$seen||{}}}; - return () if $seen->{$func}++; - my %s; - grep !$s{$_}++, map { ($_, rec_depend($_, $seen)) } @{$depends{$func}}; -} - -sub parse_version -{ - my $ver = shift; - - if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) { - return ($1, $2, $3); - } - elsif ($ver !~ /^\d+\.[\d_]+$/) { - die "cannot parse version '$ver'\n"; - } - - $ver =~ s/_//g; - $ver =~ s/$/000000/; - - my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; - - $v = int $v; - $s = int $s; - - if ($r < 5 || ($r == 5 && $v < 6)) { - if ($s % 10) { - die "cannot parse version '$ver'\n"; - } - } - - return ($r, $v, $s); -} - -sub format_version -{ - my $ver = shift; - - $ver =~ s/$/000000/; - my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; - - $v = int $v; - $s = int $s; - - if ($r < 5 || ($r == 5 && $v < 6)) { - if ($s % 10) { - die "invalid version '$ver'\n"; - } - $s /= 10; - - $ver = sprintf "%d.%03d", $r, $v; - $s > 0 and $ver .= sprintf "_%02d", $s; - - return $ver; - } - - return sprintf "%d.%d.%d", $r, $v, $s; -} - -sub info -{ - $opt{quiet} and return; - print @_, "\n"; -} - -sub diag -{ - $opt{quiet} and return; - $opt{diag} and print @_, "\n"; -} - -sub warning -{ - $opt{quiet} and return; - print "*** ", @_, "\n"; -} - -sub error -{ - print "*** ERROR: ", @_, "\n"; -} - -my %given_hints; -my %given_warnings; -sub hint -{ - $opt{quiet} and return; - my $func = shift; - my $rv = 0; - if (exists $warnings{$func} && !$given_warnings{$func}++) { - my $warn = $warnings{$func}; - $warn =~ s!^!*** !mg; - print "*** WARNING: $func\n", $warn; - $rv++; - } - if ($opt{hints} && exists $hints{$func} && !$given_hints{$func}++) { - my $hint = $hints{$func}; - $hint =~ s/^/ /mg; - print " --- hint for $func ---\n", $hint; - } - $rv; -} - -sub usage -{ - my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d$HS+SYNOPSIS\s*^(.*?)\s*^=/ms; - my %M = ( 'I' => '*' ); - $usage =~ s/^\s*perl\s+\S+/$^X $0/; - $usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g; - - print < }; - my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms; - $copy =~ s/^(?=\S+)/ /gms; - $self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms; - $self =~ s/^SKIP.*(?=^__DATA__)/SKIP -if (\@ARGV && \$ARGV[0] eq '--unstrip') { - eval { require Devel::PPPort }; - \$@ and die "Cannot require Devel::PPPort, please install.\\n"; - if (eval \$Devel::PPPort::VERSION < $VERSION) { - die "$0 was originally generated with Devel::PPPort $VERSION.\\n" - . "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n" - . "Please install a newer version, or --unstrip will not work.\\n"; - } - Devel::PPPort::WriteFile(\$0); - exit 0; -} -print <$0" or die "cannot strip $0: $!\n"; - print OUT "$pl$c\n"; - - exit 0; -} - -__DATA__ -*/ - -#ifndef _P_P_PORTABILITY_H_ -#define _P_P_PORTABILITY_H_ - -#ifndef DPPP_NAMESPACE -# define DPPP_NAMESPACE DPPP_ -#endif - -#define DPPP_CAT2(x,y) CAT2(x,y) -#define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name) - -#ifndef PERL_REVISION -# if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) -# define PERL_PATCHLEVEL_H_IMPLICIT -# include -# endif -# if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) -# include -# endif -# ifndef PERL_REVISION -# define PERL_REVISION (5) - /* Replace: 1 */ -# define PERL_VERSION PATCHLEVEL -# define PERL_SUBVERSION SUBVERSION - /* Replace PERL_PATCHLEVEL with PERL_VERSION */ - /* Replace: 0 */ -# endif -#endif - -#define _dpppDEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10)) -#define PERL_BCDVERSION ((_dpppDEC2BCD(PERL_REVISION)<<24)|(_dpppDEC2BCD(PERL_VERSION)<<12)|_dpppDEC2BCD(PERL_SUBVERSION)) - -/* It is very unlikely that anyone will try to use this with Perl 6 - (or greater), but who knows. - */ -#if PERL_REVISION != 5 -# error ppport.h only works with Perl version 5 -#endif /* PERL_REVISION != 5 */ -#ifndef dTHR -# define dTHR dNOOP -#endif -#ifndef dTHX -# define dTHX dNOOP -#endif - -#ifndef dTHXa -# define dTHXa(x) dNOOP -#endif -#ifndef pTHX -# define pTHX void -#endif - -#ifndef pTHX_ -# define pTHX_ -#endif - -#ifndef aTHX -# define aTHX -#endif - -#ifndef aTHX_ -# define aTHX_ -#endif - -#if (PERL_BCDVERSION < 0x5006000) -# ifdef USE_THREADS -# define aTHXR thr -# define aTHXR_ thr, -# else -# define aTHXR -# define aTHXR_ -# endif -# define dTHXR dTHR -#else -# define aTHXR aTHX -# define aTHXR_ aTHX_ -# define dTHXR dTHX -#endif -#ifndef dTHXoa -# define dTHXoa(x) dTHXa(x) -#endif - -#ifdef I_LIMITS -# include -#endif - -#ifndef PERL_UCHAR_MIN -# define PERL_UCHAR_MIN ((unsigned char)0) -#endif - -#ifndef PERL_UCHAR_MAX -# ifdef UCHAR_MAX -# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) -# else -# ifdef MAXUCHAR -# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR) -# else -# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0) -# endif -# endif -#endif - -#ifndef PERL_USHORT_MIN -# define PERL_USHORT_MIN ((unsigned short)0) -#endif - -#ifndef PERL_USHORT_MAX -# ifdef USHORT_MAX -# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX) -# else -# ifdef MAXUSHORT -# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT) -# else -# ifdef USHRT_MAX -# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) -# else -# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0) -# endif -# endif -# endif -#endif - -#ifndef PERL_SHORT_MAX -# ifdef SHORT_MAX -# define PERL_SHORT_MAX ((short)SHORT_MAX) -# else -# ifdef MAXSHORT /* Often used in */ -# define PERL_SHORT_MAX ((short)MAXSHORT) -# else -# ifdef SHRT_MAX -# define PERL_SHORT_MAX ((short)SHRT_MAX) -# else -# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1)) -# endif -# endif -# endif -#endif - -#ifndef PERL_SHORT_MIN -# ifdef SHORT_MIN -# define PERL_SHORT_MIN ((short)SHORT_MIN) -# else -# ifdef MINSHORT -# define PERL_SHORT_MIN ((short)MINSHORT) -# else -# ifdef SHRT_MIN -# define PERL_SHORT_MIN ((short)SHRT_MIN) -# else -# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) -# endif -# endif -# endif -#endif - -#ifndef PERL_UINT_MAX -# ifdef UINT_MAX -# define PERL_UINT_MAX ((unsigned int)UINT_MAX) -# else -# ifdef MAXUINT -# define PERL_UINT_MAX ((unsigned int)MAXUINT) -# else -# define PERL_UINT_MAX (~(unsigned int)0) -# endif -# endif -#endif - -#ifndef PERL_UINT_MIN -# define PERL_UINT_MIN ((unsigned int)0) -#endif - -#ifndef PERL_INT_MAX -# ifdef INT_MAX -# define PERL_INT_MAX ((int)INT_MAX) -# else -# ifdef MAXINT /* Often used in */ -# define PERL_INT_MAX ((int)MAXINT) -# else -# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1)) -# endif -# endif -#endif - -#ifndef PERL_INT_MIN -# ifdef INT_MIN -# define PERL_INT_MIN ((int)INT_MIN) -# else -# ifdef MININT -# define PERL_INT_MIN ((int)MININT) -# else -# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) -# endif -# endif -#endif - -#ifndef PERL_ULONG_MAX -# ifdef ULONG_MAX -# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) -# else -# ifdef MAXULONG -# define PERL_ULONG_MAX ((unsigned long)MAXULONG) -# else -# define PERL_ULONG_MAX (~(unsigned long)0) -# endif -# endif -#endif - -#ifndef PERL_ULONG_MIN -# define PERL_ULONG_MIN ((unsigned long)0L) -#endif - -#ifndef PERL_LONG_MAX -# ifdef LONG_MAX -# define PERL_LONG_MAX ((long)LONG_MAX) -# else -# ifdef MAXLONG -# define PERL_LONG_MAX ((long)MAXLONG) -# else -# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1)) -# endif -# endif -#endif - -#ifndef PERL_LONG_MIN -# ifdef LONG_MIN -# define PERL_LONG_MIN ((long)LONG_MIN) -# else -# ifdef MINLONG -# define PERL_LONG_MIN ((long)MINLONG) -# else -# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) -# endif -# endif -#endif - -#if defined(HAS_QUAD) && (defined(convex) || defined(uts)) -# ifndef PERL_UQUAD_MAX -# ifdef ULONGLONG_MAX -# define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX) -# else -# ifdef MAXULONGLONG -# define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG) -# else -# define PERL_UQUAD_MAX (~(unsigned long long)0) -# endif -# endif -# endif - -# ifndef PERL_UQUAD_MIN -# define PERL_UQUAD_MIN ((unsigned long long)0L) -# endif - -# ifndef PERL_QUAD_MAX -# ifdef LONGLONG_MAX -# define PERL_QUAD_MAX ((long long)LONGLONG_MAX) -# else -# ifdef MAXLONGLONG -# define PERL_QUAD_MAX ((long long)MAXLONGLONG) -# else -# define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1)) -# endif -# endif -# endif - -# ifndef PERL_QUAD_MIN -# ifdef LONGLONG_MIN -# define PERL_QUAD_MIN ((long long)LONGLONG_MIN) -# else -# ifdef MINLONGLONG -# define PERL_QUAD_MIN ((long long)MINLONGLONG) -# else -# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) -# endif -# endif -# endif -#endif - -/* This is based on code from 5.003 perl.h */ -#ifdef HAS_QUAD -# ifdef cray -#ifndef IVTYPE -# define IVTYPE int -#endif - -#ifndef IV_MIN -# define IV_MIN PERL_INT_MIN -#endif - -#ifndef IV_MAX -# define IV_MAX PERL_INT_MAX -#endif - -#ifndef UV_MIN -# define UV_MIN PERL_UINT_MIN -#endif - -#ifndef UV_MAX -# define UV_MAX PERL_UINT_MAX -#endif - -# ifdef INTSIZE -#ifndef IVSIZE -# define IVSIZE INTSIZE -#endif - -# endif -# else -# if defined(convex) || defined(uts) -#ifndef IVTYPE -# define IVTYPE long long -#endif - -#ifndef IV_MIN -# define IV_MIN PERL_QUAD_MIN -#endif - -#ifndef IV_MAX -# define IV_MAX PERL_QUAD_MAX -#endif - -#ifndef UV_MIN -# define UV_MIN PERL_UQUAD_MIN -#endif - -#ifndef UV_MAX -# define UV_MAX PERL_UQUAD_MAX -#endif - -# ifdef LONGLONGSIZE -#ifndef IVSIZE -# define IVSIZE LONGLONGSIZE -#endif - -# endif -# else -#ifndef IVTYPE -# define IVTYPE long -#endif - -#ifndef IV_MIN -# define IV_MIN PERL_LONG_MIN -#endif - -#ifndef IV_MAX -# define IV_MAX PERL_LONG_MAX -#endif - -#ifndef UV_MIN -# define UV_MIN PERL_ULONG_MIN -#endif - -#ifndef UV_MAX -# define UV_MAX PERL_ULONG_MAX -#endif - -# ifdef LONGSIZE -#ifndef IVSIZE -# define IVSIZE LONGSIZE -#endif - -# endif -# endif -# endif -#ifndef IVSIZE -# define IVSIZE 8 -#endif - -#ifndef LONGSIZE -# define LONGSIZE 8 -#endif - -#ifndef PERL_QUAD_MIN -# define PERL_QUAD_MIN IV_MIN -#endif - -#ifndef PERL_QUAD_MAX -# define PERL_QUAD_MAX IV_MAX -#endif - -#ifndef PERL_UQUAD_MIN -# define PERL_UQUAD_MIN UV_MIN -#endif - -#ifndef PERL_UQUAD_MAX -# define PERL_UQUAD_MAX UV_MAX -#endif - -#else -#ifndef IVTYPE -# define IVTYPE long -#endif - -#ifndef LONGSIZE -# define LONGSIZE 4 -#endif - -#ifndef IV_MIN -# define IV_MIN PERL_LONG_MIN -#endif - -#ifndef IV_MAX -# define IV_MAX PERL_LONG_MAX -#endif - -#ifndef UV_MIN -# define UV_MIN PERL_ULONG_MIN -#endif - -#ifndef UV_MAX -# define UV_MAX PERL_ULONG_MAX -#endif - -#endif - -#ifndef IVSIZE -# ifdef LONGSIZE -# define IVSIZE LONGSIZE -# else -# define IVSIZE 4 /* A bold guess, but the best we can make. */ -# endif -#endif -#ifndef UVTYPE -# define UVTYPE unsigned IVTYPE -#endif - -#ifndef UVSIZE -# define UVSIZE IVSIZE -#endif -#ifndef sv_setuv -# define sv_setuv(sv, uv) \ - STMT_START { \ - UV TeMpUv = uv; \ - if (TeMpUv <= IV_MAX) \ - sv_setiv(sv, TeMpUv); \ - else \ - sv_setnv(sv, (double)TeMpUv); \ - } STMT_END -#endif -#ifndef newSVuv -# define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv)) -#endif -#ifndef sv_2uv -# define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv))) -#endif - -#ifndef SvUVX -# define SvUVX(sv) ((UV)SvIVX(sv)) -#endif - -#ifndef SvUVXx -# define SvUVXx(sv) SvUVX(sv) -#endif - -#ifndef SvUV -# define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) -#endif - -#ifndef SvUVx -# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) -#endif - -/* Hint: sv_uv - * Always use the SvUVx() macro instead of sv_uv(). - */ -#ifndef sv_uv -# define sv_uv(sv) SvUVx(sv) -#endif - -#if !defined(SvUOK) && defined(SvIOK_UV) -# define SvUOK(sv) SvIOK_UV(sv) -#endif -#ifndef XST_mUV -# define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) -#endif - -#ifndef XSRETURN_UV -# define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END -#endif -#ifndef PUSHu -# define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END -#endif - -#ifndef XPUSHu -# define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END -#endif - -#ifdef HAS_MEMCMP -#ifndef memNE -# define memNE(s1,s2,l) (memcmp(s1,s2,l)) -#endif - -#ifndef memEQ -# define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) -#endif - -#else -#ifndef memNE -# define memNE(s1,s2,l) (bcmp(s1,s2,l)) -#endif - -#ifndef memEQ -# define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) -#endif - -#endif -#ifndef memEQs -# define memEQs(s1, l, s2) \ - (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) -#endif - -#ifndef memNEs -# define memNEs(s1, l, s2) !memEQs(s1, l, s2) -#endif -#ifndef MoveD -# define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) -#endif - -#ifndef CopyD -# define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) -#endif - -#ifdef HAS_MEMSET -#ifndef ZeroD -# define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) -#endif - -#else -#ifndef ZeroD -# define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) -#endif - -#endif -#ifndef PoisonWith -# define PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) -#endif - -#ifndef PoisonNew -# define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) -#endif - -#ifndef PoisonFree -# define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) -#endif - -#ifndef Poison -# define Poison(d,n,t) PoisonFree(d,n,t) -#endif -#ifndef Newx -# define Newx(v,n,t) New(0,v,n,t) -#endif - -#ifndef Newxc -# define Newxc(v,n,t,c) Newc(0,v,n,t,c) -#endif - -#ifndef Newxz -# define Newxz(v,n,t) Newz(0,v,n,t) -#endif - -#ifndef PERL_UNUSED_DECL -# ifdef HASATTRIBUTE -# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER) -# define PERL_UNUSED_DECL -# else -# define PERL_UNUSED_DECL __attribute__((unused)) -# endif -# else -# define PERL_UNUSED_DECL -# endif -#endif - -#ifndef PERL_UNUSED_ARG -# if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ -# include -# define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) -# else -# define PERL_UNUSED_ARG(x) ((void)x) -# endif -#endif - -#ifndef PERL_UNUSED_VAR -# define PERL_UNUSED_VAR(x) ((void)x) -#endif - -#ifndef PERL_UNUSED_CONTEXT -# ifdef USE_ITHREADS -# define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) -# else -# define PERL_UNUSED_CONTEXT -# endif -#endif -#ifndef NOOP -# define NOOP /*EMPTY*/(void)0 -#endif - -#ifndef dNOOP -# define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL -#endif - -#ifndef NVTYPE -# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) -# define NVTYPE long double -# else -# define NVTYPE double -# endif -typedef NVTYPE NV; -#endif - -#ifndef INT2PTR -# if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) -# define PTRV UV -# define INT2PTR(any,d) (any)(d) -# else -# if PTRSIZE == LONGSIZE -# define PTRV unsigned long -# else -# define PTRV unsigned -# endif -# define INT2PTR(any,d) (any)(PTRV)(d) -# endif -#endif - -#ifndef PTR2ul -# if PTRSIZE == LONGSIZE -# define PTR2ul(p) (unsigned long)(p) -# else -# define PTR2ul(p) INT2PTR(unsigned long,p) -# endif -#endif -#ifndef PTR2nat -# define PTR2nat(p) (PTRV)(p) -#endif - -#ifndef NUM2PTR -# define NUM2PTR(any,d) (any)PTR2nat(d) -#endif - -#ifndef PTR2IV -# define PTR2IV(p) INT2PTR(IV,p) -#endif - -#ifndef PTR2UV -# define PTR2UV(p) INT2PTR(UV,p) -#endif - -#ifndef PTR2NV -# define PTR2NV(p) NUM2PTR(NV,p) -#endif - -#undef START_EXTERN_C -#undef END_EXTERN_C -#undef EXTERN_C -#ifdef __cplusplus -# define START_EXTERN_C extern "C" { -# define END_EXTERN_C } -# define EXTERN_C extern "C" -#else -# define START_EXTERN_C -# define END_EXTERN_C -# define EXTERN_C extern -#endif - -#if defined(PERL_GCC_PEDANTIC) -# ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN -# define PERL_GCC_BRACE_GROUPS_FORBIDDEN -# endif -#endif - -#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) -# ifndef PERL_USE_GCC_BRACE_GROUPS -# define PERL_USE_GCC_BRACE_GROUPS -# endif -#endif - -#undef STMT_START -#undef STMT_END -#ifdef PERL_USE_GCC_BRACE_GROUPS -# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ -# define STMT_END ) -#else -# if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__) -# define STMT_START if (1) -# define STMT_END else (void)0 -# else -# define STMT_START do -# define STMT_END while (0) -# endif -#endif -#ifndef boolSV -# define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) -#endif - -/* DEFSV appears first in 5.004_56 */ -#ifndef DEFSV -# define DEFSV GvSV(PL_defgv) -#endif - -#ifndef SAVE_DEFSV -# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) -#endif - -#ifndef DEFSV_set -# define DEFSV_set(sv) (DEFSV = (sv)) -#endif - -/* Older perls (<=5.003) lack AvFILLp */ -#ifndef AvFILLp -# define AvFILLp AvFILL -#endif -#ifndef ERRSV -# define ERRSV get_sv("@",FALSE) -#endif - -/* Hint: gv_stashpvn - * This function's backport doesn't support the length parameter, but - * rather ignores it. Portability can only be ensured if the length - * parameter is used for speed reasons, but the length can always be - * correctly computed from the string argument. - */ -#ifndef gv_stashpvn -# define gv_stashpvn(str,len,create) gv_stashpv(str,create) -#endif - -/* Replace: 1 */ -#ifndef get_cv -# define get_cv perl_get_cv -#endif - -#ifndef get_sv -# define get_sv perl_get_sv -#endif - -#ifndef get_av -# define get_av perl_get_av -#endif - -#ifndef get_hv -# define get_hv perl_get_hv -#endif - -/* Replace: 0 */ -#ifndef dUNDERBAR -# define dUNDERBAR dNOOP -#endif - -#ifndef UNDERBAR -# define UNDERBAR DEFSV -#endif -#ifndef dAX -# define dAX I32 ax = MARK - PL_stack_base + 1 -#endif - -#ifndef dITEMS -# define dITEMS I32 items = SP - MARK -#endif -#ifndef dXSTARG -# define dXSTARG SV * targ = sv_newmortal() -#endif -#ifndef dAXMARK -# define dAXMARK I32 ax = POPMARK; \ - register SV ** const mark = PL_stack_base + ax++ -#endif -#ifndef XSprePUSH -# define XSprePUSH (sp = PL_stack_base + ax - 1) -#endif - -#if (PERL_BCDVERSION < 0x5005000) -# undef XSRETURN -# define XSRETURN(off) \ - STMT_START { \ - PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ - return; \ - } STMT_END -#endif -#ifndef XSPROTO -# define XSPROTO(name) void name(pTHX_ CV* cv) -#endif - -#ifndef SVfARG -# define SVfARG(p) ((void*)(p)) -#endif -#ifndef PERL_ABS -# define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) -#endif -#ifndef dVAR -# define dVAR dNOOP -#endif -#ifndef SVf -# define SVf "_" -#endif -#ifndef UTF8_MAXBYTES -# define UTF8_MAXBYTES UTF8_MAXLEN -#endif -#ifndef CPERLscope -# define CPERLscope(x) x -#endif -#ifndef PERL_HASH -# define PERL_HASH(hash,str,len) \ - STMT_START { \ - const char *s_PeRlHaSh = str; \ - I32 i_PeRlHaSh = len; \ - U32 hash_PeRlHaSh = 0; \ - while (i_PeRlHaSh--) \ - hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ - (hash) = hash_PeRlHaSh; \ - } STMT_END -#endif - -#ifndef PERLIO_FUNCS_DECL -# ifdef PERLIO_FUNCS_CONST -# define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs -# define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) -# else -# define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs -# define PERLIO_FUNCS_CAST(funcs) (funcs) -# endif -#endif - -/* provide these typedefs for older perls */ -#if (PERL_BCDVERSION < 0x5009003) - -# ifdef ARGSproto -typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto); -# else -typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX); -# endif - -typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*); - -#endif -#ifndef isPSXSPC -# define isPSXSPC(c) (isSPACE(c) || (c) == '\v') -#endif - -#ifndef isBLANK -# define isBLANK(c) ((c) == ' ' || (c) == '\t') -#endif - -#ifdef EBCDIC -#ifndef isALNUMC -# define isALNUMC(c) isalnum(c) -#endif - -#ifndef isASCII -# define isASCII(c) isascii(c) -#endif - -#ifndef isCNTRL -# define isCNTRL(c) iscntrl(c) -#endif - -#ifndef isGRAPH -# define isGRAPH(c) isgraph(c) -#endif - -#ifndef isPRINT -# define isPRINT(c) isprint(c) -#endif - -#ifndef isPUNCT -# define isPUNCT(c) ispunct(c) -#endif - -#ifndef isXDIGIT -# define isXDIGIT(c) isxdigit(c) -#endif - -#else -# if (PERL_BCDVERSION < 0x5010000) -/* Hint: isPRINT - * The implementation in older perl versions includes all of the - * isSPACE() characters, which is wrong. The version provided by - * Devel::PPPort always overrides a present buggy version. - */ -# undef isPRINT -# endif - -#ifdef HAS_QUAD -# ifdef U64TYPE -# define WIDEST_UTYPE U64TYPE -# else -# define WIDEST_UTYPE Quad_t -# endif -#else -# define WIDEST_UTYPE U32 -#endif -#ifndef isALNUMC -# define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) -#endif - -#ifndef isASCII -# define isASCII(c) ((WIDEST_UTYPE) (c) <= 127) -#endif - -#ifndef isCNTRL -# define isCNTRL(c) ((WIDEST_UTYPE) (c) < ' ' || (c) == 127) -#endif - -#ifndef isGRAPH -# define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) -#endif - -#ifndef isPRINT -# define isPRINT(c) (((c) >= 32 && (c) < 127)) -#endif - -#ifndef isPUNCT -# define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) -#endif - -#ifndef isXDIGIT -# define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#endif - -#endif - -/* Until we figure out how to support this in older perls... */ -#if (PERL_BCDVERSION >= 0x5008000) -#ifndef HeUTF8 -# define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \ - SvUTF8(HeKEY_sv(he)) : \ - (U32)HeKUTF8(he)) -#endif - -#endif - -#ifndef PERL_SIGNALS_UNSAFE_FLAG - -#define PERL_SIGNALS_UNSAFE_FLAG 0x0001 - -#if (PERL_BCDVERSION < 0x5008000) -# define D_PPP_PERL_SIGNALS_INIT PERL_SIGNALS_UNSAFE_FLAG -#else -# define D_PPP_PERL_SIGNALS_INIT 0 -#endif - -#if defined(NEED_PL_signals) -static U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; -#elif defined(NEED_PL_signals_GLOBAL) -U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; -#else -extern U32 DPPP_(my_PL_signals); -#endif -#define PL_signals DPPP_(my_PL_signals) - -#endif - -/* Hint: PL_ppaddr - * Calling an op via PL_ppaddr requires passing a context argument - * for threaded builds. Since the context argument is different for - * 5.005 perls, you can use aTHXR (supplied by ppport.h), which will - * automatically be defined as the correct argument. - */ - -#if (PERL_BCDVERSION <= 0x5005005) -/* Replace: 1 */ -# define PL_ppaddr ppaddr -# define PL_no_modify no_modify -/* Replace: 0 */ -#endif - -#if (PERL_BCDVERSION <= 0x5004005) -/* Replace: 1 */ -# define PL_DBsignal DBsignal -# define PL_DBsingle DBsingle -# define PL_DBsub DBsub -# define PL_DBtrace DBtrace -# define PL_Sv Sv -# define PL_bufend bufend -# define PL_bufptr bufptr -# define PL_compiling compiling -# define PL_copline copline -# define PL_curcop curcop -# define PL_curstash curstash -# define PL_debstash debstash -# define PL_defgv defgv -# define PL_diehook diehook -# define PL_dirty dirty -# define PL_dowarn dowarn -# define PL_errgv errgv -# define PL_error_count error_count -# define PL_expect expect -# define PL_hexdigit hexdigit -# define PL_hints hints -# define PL_in_my in_my -# define PL_laststatval laststatval -# define PL_lex_state lex_state -# define PL_lex_stuff lex_stuff -# define PL_linestr linestr -# define PL_na na -# define PL_perl_destruct_level perl_destruct_level -# define PL_perldb perldb -# define PL_rsfp_filters rsfp_filters -# define PL_rsfp rsfp -# define PL_stack_base stack_base -# define PL_stack_sp stack_sp -# define PL_statcache statcache -# define PL_stdingv stdingv -# define PL_sv_arenaroot sv_arenaroot -# define PL_sv_no sv_no -# define PL_sv_undef sv_undef -# define PL_sv_yes sv_yes -# define PL_tainted tainted -# define PL_tainting tainting -# define PL_tokenbuf tokenbuf -/* Replace: 0 */ -#endif - -/* Warning: PL_parser - * For perl versions earlier than 5.9.5, this is an always - * non-NULL dummy. Also, it cannot be dereferenced. Don't - * use it if you can avoid is and unless you absolutely know - * what you're doing. - * If you always check that PL_parser is non-NULL, you can - * define DPPP_PL_parser_NO_DUMMY to avoid the creation of - * a dummy parser structure. - */ - -#if (PERL_BCDVERSION >= 0x5009005) -# ifdef DPPP_PL_parser_NO_DUMMY -# define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ - (croak("panic: PL_parser == NULL in %s:%d", \ - __FILE__, __LINE__), (yy_parser *) NULL))->var) -# else -# ifdef DPPP_PL_parser_NO_DUMMY_WARNING -# define D_PPP_parser_dummy_warning(var) -# else -# define D_PPP_parser_dummy_warning(var) \ - warn("warning: dummy PL_" #var " used in %s:%d", __FILE__, __LINE__), -# endif -# define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ - (D_PPP_parser_dummy_warning(var) &DPPP_(dummy_PL_parser)))->var) -#if defined(NEED_PL_parser) -static yy_parser DPPP_(dummy_PL_parser); -#elif defined(NEED_PL_parser_GLOBAL) -yy_parser DPPP_(dummy_PL_parser); -#else -extern yy_parser DPPP_(dummy_PL_parser); -#endif - -# endif - -/* PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf depends on PL_parser */ -/* Warning: PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf - * Do not use this variable unless you know exactly what you're - * doint. It is internal to the perl parser and may change or even - * be removed in the future. As of perl 5.9.5, you have to check - * for (PL_parser != NULL) for this variable to have any effect. - * An always non-NULL PL_parser dummy is provided for earlier - * perl versions. - * If PL_parser is NULL when you try to access this variable, a - * dummy is being accessed instead and a warning is issued unless - * you define DPPP_PL_parser_NO_DUMMY_WARNING. - * If DPPP_PL_parser_NO_DUMMY is defined, the code trying to access - * this variable will croak with a panic message. - */ - -# define PL_expect D_PPP_my_PL_parser_var(expect) -# define PL_copline D_PPP_my_PL_parser_var(copline) -# define PL_rsfp D_PPP_my_PL_parser_var(rsfp) -# define PL_rsfp_filters D_PPP_my_PL_parser_var(rsfp_filters) -# define PL_linestr D_PPP_my_PL_parser_var(linestr) -# define PL_bufptr D_PPP_my_PL_parser_var(bufptr) -# define PL_bufend D_PPP_my_PL_parser_var(bufend) -# define PL_lex_state D_PPP_my_PL_parser_var(lex_state) -# define PL_lex_stuff D_PPP_my_PL_parser_var(lex_stuff) -# define PL_tokenbuf D_PPP_my_PL_parser_var(tokenbuf) -# define PL_in_my D_PPP_my_PL_parser_var(in_my) -# define PL_in_my_stash D_PPP_my_PL_parser_var(in_my_stash) -# define PL_error_count D_PPP_my_PL_parser_var(error_count) - - -#else - -/* ensure that PL_parser != NULL and cannot be dereferenced */ -# define PL_parser ((void *) 1) - -#endif -#ifndef mPUSHs -# define mPUSHs(s) PUSHs(sv_2mortal(s)) -#endif - -#ifndef PUSHmortal -# define PUSHmortal PUSHs(sv_newmortal()) -#endif - -#ifndef mPUSHp -# define mPUSHp(p,l) sv_setpvn(PUSHmortal, (p), (l)) -#endif - -#ifndef mPUSHn -# define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) -#endif - -#ifndef mPUSHi -# define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) -#endif - -#ifndef mPUSHu -# define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) -#endif -#ifndef mXPUSHs -# define mXPUSHs(s) XPUSHs(sv_2mortal(s)) -#endif - -#ifndef XPUSHmortal -# define XPUSHmortal XPUSHs(sv_newmortal()) -#endif - -#ifndef mXPUSHp -# define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn(PUSHmortal, (p), (l)); } STMT_END -#endif - -#ifndef mXPUSHn -# define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END -#endif - -#ifndef mXPUSHi -# define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END -#endif - -#ifndef mXPUSHu -# define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END -#endif - -/* Replace: 1 */ -#ifndef call_sv -# define call_sv perl_call_sv -#endif - -#ifndef call_pv -# define call_pv perl_call_pv -#endif - -#ifndef call_argv -# define call_argv perl_call_argv -#endif - -#ifndef call_method -# define call_method perl_call_method -#endif -#ifndef eval_sv -# define eval_sv perl_eval_sv -#endif - -/* Replace: 0 */ -#ifndef PERL_LOADMOD_DENY -# define PERL_LOADMOD_DENY 0x1 -#endif - -#ifndef PERL_LOADMOD_NOIMPORT -# define PERL_LOADMOD_NOIMPORT 0x2 -#endif - -#ifndef PERL_LOADMOD_IMPORT_OPS -# define PERL_LOADMOD_IMPORT_OPS 0x4 -#endif - -#ifndef G_METHOD -# define G_METHOD 64 -# ifdef call_sv -# undef call_sv -# endif -# if (PERL_BCDVERSION < 0x5006000) -# define call_sv(sv, flags) ((flags) & G_METHOD ? perl_call_method((char *) SvPV_nolen_const(sv), \ - (flags) & ~G_METHOD) : perl_call_sv(sv, flags)) -# else -# define call_sv(sv, flags) ((flags) & G_METHOD ? Perl_call_method(aTHX_ (char *) SvPV_nolen_const(sv), \ - (flags) & ~G_METHOD) : Perl_call_sv(aTHX_ sv, flags)) -# endif -#endif - -/* Replace perl_eval_pv with eval_pv */ - -#ifndef eval_pv -#if defined(NEED_eval_pv) -static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); -static -#else -extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); -#endif - -#ifdef eval_pv -# undef eval_pv -#endif -#define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b) -#define Perl_eval_pv DPPP_(my_eval_pv) - -#if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL) - -SV* -DPPP_(my_eval_pv)(char *p, I32 croak_on_error) -{ - dSP; - SV* sv = newSVpv(p, 0); - - PUSHMARK(sp); - eval_sv(sv, G_SCALAR); - SvREFCNT_dec(sv); - - SPAGAIN; - sv = POPs; - PUTBACK; - - if (croak_on_error && SvTRUE(GvSV(errgv))) - croak(SvPVx(GvSV(errgv), na)); - - return sv; -} - -#endif -#endif - -#ifndef vload_module -#if defined(NEED_vload_module) -static void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); -static -#else -extern void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); -#endif - -#ifdef vload_module -# undef vload_module -#endif -#define vload_module(a,b,c,d) DPPP_(my_vload_module)(aTHX_ a,b,c,d) -#define Perl_vload_module DPPP_(my_vload_module) - -#if defined(NEED_vload_module) || defined(NEED_vload_module_GLOBAL) - -void -DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args) -{ - dTHR; - dVAR; - OP *veop, *imop; - - OP * const modname = newSVOP(OP_CONST, 0, name); - /* 5.005 has a somewhat hacky force_normal that doesn't croak on - SvREADONLY() if PL_compling is true. Current perls take care in - ck_require() to correctly turn off SvREADONLY before calling - force_normal_flags(). This seems a better fix than fudging PL_compling - */ - SvREADONLY_off(((SVOP*)modname)->op_sv); - modname->op_private |= OPpCONST_BARE; - if (ver) { - veop = newSVOP(OP_CONST, 0, ver); - } - else - veop = NULL; - if (flags & PERL_LOADMOD_NOIMPORT) { - imop = sawparens(newNULLLIST()); - } - else if (flags & PERL_LOADMOD_IMPORT_OPS) { - imop = va_arg(*args, OP*); - } - else { - SV *sv; - imop = NULL; - sv = va_arg(*args, SV*); - while (sv) { - imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); - sv = va_arg(*args, SV*); - } - } - { - const line_t ocopline = PL_copline; - COP * const ocurcop = PL_curcop; - const int oexpect = PL_expect; - -#if (PERL_BCDVERSION >= 0x5004000) - utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), - veop, modname, imop); -#elif (PERL_BCDVERSION > 0x5003000) - utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), - veop, modname, imop); -#else - utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), - modname, imop); -#endif - PL_expect = oexpect; - PL_copline = ocopline; - PL_curcop = ocurcop; - } -} - -#endif -#endif - -#ifndef load_module -#if defined(NEED_load_module) -static void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); -static -#else -extern void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); -#endif - -#ifdef load_module -# undef load_module -#endif -#define load_module DPPP_(my_load_module) -#define Perl_load_module DPPP_(my_load_module) - -#if defined(NEED_load_module) || defined(NEED_load_module_GLOBAL) - -void -DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...) -{ - va_list args; - va_start(args, ver); - vload_module(flags, name, ver, &args); - va_end(args); -} - -#endif -#endif -#ifndef newRV_inc -# define newRV_inc(sv) newRV(sv) /* Replace */ -#endif - -#ifndef newRV_noinc -#if defined(NEED_newRV_noinc) -static SV * DPPP_(my_newRV_noinc)(SV *sv); -static -#else -extern SV * DPPP_(my_newRV_noinc)(SV *sv); -#endif - -#ifdef newRV_noinc -# undef newRV_noinc -#endif -#define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a) -#define Perl_newRV_noinc DPPP_(my_newRV_noinc) - -#if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL) -SV * -DPPP_(my_newRV_noinc)(SV *sv) -{ - SV *rv = (SV *)newRV(sv); - SvREFCNT_dec(sv); - return rv; -} -#endif -#endif - -/* Hint: newCONSTSUB - * Returns a CV* as of perl-5.7.1. This return value is not supported - * by Devel::PPPort. - */ - -/* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */ -#if (PERL_BCDVERSION < 0x5004063) && (PERL_BCDVERSION != 0x5004005) -#if defined(NEED_newCONSTSUB) -static void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); -static -#else -extern void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); -#endif - -#ifdef newCONSTSUB -# undef newCONSTSUB -#endif -#define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c) -#define Perl_newCONSTSUB DPPP_(my_newCONSTSUB) - -#if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL) - -/* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */ -/* (There's no PL_parser in perl < 5.005, so this is completely safe) */ -#define D_PPP_PL_copline PL_copline - -void -DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv) -{ - U32 oldhints = PL_hints; - HV *old_cop_stash = PL_curcop->cop_stash; - HV *old_curstash = PL_curstash; - line_t oldline = PL_curcop->cop_line; - PL_curcop->cop_line = D_PPP_PL_copline; - - PL_hints &= ~HINT_BLOCK_SCOPE; - if (stash) - PL_curstash = PL_curcop->cop_stash = stash; - - newSUB( - -#if (PERL_BCDVERSION < 0x5003022) - start_subparse(), -#elif (PERL_BCDVERSION == 0x5003022) - start_subparse(0), -#else /* 5.003_23 onwards */ - start_subparse(FALSE, 0), -#endif - - newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)), - newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ - newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) - ); - - PL_hints = oldhints; - PL_curcop->cop_stash = old_cop_stash; - PL_curstash = old_curstash; - PL_curcop->cop_line = oldline; -} -#endif -#endif - -/* - * Boilerplate macros for initializing and accessing interpreter-local - * data from C. All statics in extensions should be reworked to use - * this, if you want to make the extension thread-safe. See ext/re/re.xs - * for an example of the use of these macros. - * - * Code that uses these macros is responsible for the following: - * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts" - * 2. Declare a typedef named my_cxt_t that is a structure that contains - * all the data that needs to be interpreter-local. - * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. - * 4. Use the MY_CXT_INIT macro such that it is called exactly once - * (typically put in the BOOT: section). - * 5. Use the members of the my_cxt_t structure everywhere as - * MY_CXT.member. - * 6. Use the dMY_CXT macro (a declaration) in all the functions that - * access MY_CXT. - */ - -#if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \ - defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT) - -#ifndef START_MY_CXT - -/* This must appear in all extensions that define a my_cxt_t structure, - * right after the definition (i.e. at file scope). The non-threads - * case below uses it to declare the data as static. */ -#define START_MY_CXT - -#if (PERL_BCDVERSION < 0x5004068) -/* Fetches the SV that keeps the per-interpreter data. */ -#define dMY_CXT_SV \ - SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE) -#else /* >= perl5.004_68 */ -#define dMY_CXT_SV \ - SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \ - sizeof(MY_CXT_KEY)-1, TRUE) -#endif /* < perl5.004_68 */ - -/* This declaration should be used within all functions that use the - * interpreter-local data. */ -#define dMY_CXT \ - dMY_CXT_SV; \ - my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv)) - -/* Creates and zeroes the per-interpreter data. - * (We allocate my_cxtp in a Perl SV so that it will be released when - * the interpreter goes away.) */ -#define MY_CXT_INIT \ - dMY_CXT_SV; \ - /* newSV() allocates one more than needed */ \ - my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ - Zero(my_cxtp, 1, my_cxt_t); \ - sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) - -/* This macro must be used to access members of the my_cxt_t structure. - * e.g. MYCXT.some_data */ -#define MY_CXT (*my_cxtp) - -/* Judicious use of these macros can reduce the number of times dMY_CXT - * is used. Use is similar to pTHX, aTHX etc. */ -#define pMY_CXT my_cxt_t *my_cxtp -#define pMY_CXT_ pMY_CXT, -#define _pMY_CXT ,pMY_CXT -#define aMY_CXT my_cxtp -#define aMY_CXT_ aMY_CXT, -#define _aMY_CXT ,aMY_CXT - -#endif /* START_MY_CXT */ - -#ifndef MY_CXT_CLONE -/* Clones the per-interpreter data. */ -#define MY_CXT_CLONE \ - dMY_CXT_SV; \ - my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ - Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\ - sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) -#endif - -#else /* single interpreter */ - -#ifndef START_MY_CXT - -#define START_MY_CXT static my_cxt_t my_cxt; -#define dMY_CXT_SV dNOOP -#define dMY_CXT dNOOP -#define MY_CXT_INIT NOOP -#define MY_CXT my_cxt - -#define pMY_CXT void -#define pMY_CXT_ -#define _pMY_CXT -#define aMY_CXT -#define aMY_CXT_ -#define _aMY_CXT - -#endif /* START_MY_CXT */ - -#ifndef MY_CXT_CLONE -#define MY_CXT_CLONE NOOP -#endif - -#endif - -#ifndef IVdf -# if IVSIZE == LONGSIZE -# define IVdf "ld" -# define UVuf "lu" -# define UVof "lo" -# define UVxf "lx" -# define UVXf "lX" -# elif IVSIZE == INTSIZE -# define IVdf "d" -# define UVuf "u" -# define UVof "o" -# define UVxf "x" -# define UVXf "X" -# else -# error "cannot define IV/UV formats" -# endif -#endif - -#ifndef NVef -# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \ - defined(PERL_PRIfldbl) && (PERL_BCDVERSION != 0x5006000) - /* Not very likely, but let's try anyway. */ -# define NVef PERL_PRIeldbl -# define NVff PERL_PRIfldbl -# define NVgf PERL_PRIgldbl -# else -# define NVef "e" -# define NVff "f" -# define NVgf "g" -# endif -#endif - -#ifndef SvREFCNT_inc -# ifdef PERL_USE_GCC_BRACE_GROUPS -# define SvREFCNT_inc(sv) \ - ({ \ - SV * const _sv = (SV*)(sv); \ - if (_sv) \ - (SvREFCNT(_sv))++; \ - _sv; \ - }) -# else -# define SvREFCNT_inc(sv) \ - ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) -# endif -#endif - -#ifndef SvREFCNT_inc_simple -# ifdef PERL_USE_GCC_BRACE_GROUPS -# define SvREFCNT_inc_simple(sv) \ - ({ \ - if (sv) \ - (SvREFCNT(sv))++; \ - (SV *)(sv); \ - }) -# else -# define SvREFCNT_inc_simple(sv) \ - ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) -# endif -#endif - -#ifndef SvREFCNT_inc_NN -# ifdef PERL_USE_GCC_BRACE_GROUPS -# define SvREFCNT_inc_NN(sv) \ - ({ \ - SV * const _sv = (SV*)(sv); \ - SvREFCNT(_sv)++; \ - _sv; \ - }) -# else -# define SvREFCNT_inc_NN(sv) \ - (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) -# endif -#endif - -#ifndef SvREFCNT_inc_void -# ifdef PERL_USE_GCC_BRACE_GROUPS -# define SvREFCNT_inc_void(sv) \ - ({ \ - SV * const _sv = (SV*)(sv); \ - if (_sv) \ - (void)(SvREFCNT(_sv)++); \ - }) -# else -# define SvREFCNT_inc_void(sv) \ - (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) -# endif -#endif -#ifndef SvREFCNT_inc_simple_void -# define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END -#endif - -#ifndef SvREFCNT_inc_simple_NN -# define SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) -#endif - -#ifndef SvREFCNT_inc_void_NN -# define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) -#endif - -#ifndef SvREFCNT_inc_simple_void_NN -# define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) -#endif - -#ifndef newSV_type - -#if defined(NEED_newSV_type) -static SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); -static -#else -extern SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); -#endif - -#ifdef newSV_type -# undef newSV_type -#endif -#define newSV_type(a) DPPP_(my_newSV_type)(aTHX_ a) -#define Perl_newSV_type DPPP_(my_newSV_type) - -#if defined(NEED_newSV_type) || defined(NEED_newSV_type_GLOBAL) - -SV* -DPPP_(my_newSV_type)(pTHX_ svtype const t) -{ - SV* const sv = newSV(0); - sv_upgrade(sv, t); - return sv; -} - -#endif - -#endif - -#if (PERL_BCDVERSION < 0x5006000) -# define D_PPP_CONSTPV_ARG(x) ((char *) (x)) -#else -# define D_PPP_CONSTPV_ARG(x) (x) -#endif -#ifndef newSVpvn -# define newSVpvn(data,len) ((data) \ - ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ - : newSV(0)) -#endif -#ifndef newSVpvn_utf8 -# define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) -#endif -#ifndef SVf_UTF8 -# define SVf_UTF8 0 -#endif - -#ifndef newSVpvn_flags - -#if defined(NEED_newSVpvn_flags) -static SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); -static -#else -extern SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); -#endif - -#ifdef newSVpvn_flags -# undef newSVpvn_flags -#endif -#define newSVpvn_flags(a,b,c) DPPP_(my_newSVpvn_flags)(aTHX_ a,b,c) -#define Perl_newSVpvn_flags DPPP_(my_newSVpvn_flags) - -#if defined(NEED_newSVpvn_flags) || defined(NEED_newSVpvn_flags_GLOBAL) - -SV * -DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags) -{ - SV *sv = newSVpvn(D_PPP_CONSTPV_ARG(s), len); - SvFLAGS(sv) |= (flags & SVf_UTF8); - return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; -} - -#endif - -#endif - -/* Backwards compatibility stuff... :-( */ -#if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen) -# define NEED_sv_2pv_flags -#endif -#if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL) -# define NEED_sv_2pv_flags_GLOBAL -#endif - -/* Hint: sv_2pv_nolen - * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen(). - */ -#ifndef sv_2pv_nolen -# define sv_2pv_nolen(sv) SvPV_nolen(sv) -#endif - -#ifdef SvPVbyte - -/* Hint: SvPVbyte - * Does not work in perl-5.6.1, ppport.h implements a version - * borrowed from perl-5.7.3. - */ - -#if (PERL_BCDVERSION < 0x5007000) - -#if defined(NEED_sv_2pvbyte) -static char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); -static -#else -extern char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); -#endif - -#ifdef sv_2pvbyte -# undef sv_2pvbyte -#endif -#define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b) -#define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte) - -#if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL) - -char * -DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp) -{ - sv_utf8_downgrade(sv,0); - return SvPV(sv,*lp); -} - -#endif - -/* Hint: sv_2pvbyte - * Use the SvPVbyte() macro instead of sv_2pvbyte(). - */ - -#undef SvPVbyte - -#define SvPVbyte(sv, lp) \ - ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ - ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) - -#endif - -#else - -# define SvPVbyte SvPV -# define sv_2pvbyte sv_2pv - -#endif -#ifndef sv_2pvbyte_nolen -# define sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv) -#endif - -/* Hint: sv_pvn - * Always use the SvPV() macro instead of sv_pvn(). - */ - -/* Hint: sv_pvn_force - * Always use the SvPV_force() macro instead of sv_pvn_force(). - */ - -/* If these are undefined, they're not handled by the core anyway */ -#ifndef SV_IMMEDIATE_UNREF -# define SV_IMMEDIATE_UNREF 0 -#endif - -#ifndef SV_GMAGIC -# define SV_GMAGIC 0 -#endif - -#ifndef SV_COW_DROP_PV -# define SV_COW_DROP_PV 0 -#endif - -#ifndef SV_UTF8_NO_ENCODING -# define SV_UTF8_NO_ENCODING 0 -#endif - -#ifndef SV_NOSTEAL -# define SV_NOSTEAL 0 -#endif - -#ifndef SV_CONST_RETURN -# define SV_CONST_RETURN 0 -#endif - -#ifndef SV_MUTABLE_RETURN -# define SV_MUTABLE_RETURN 0 -#endif - -#ifndef SV_SMAGIC -# define SV_SMAGIC 0 -#endif - -#ifndef SV_HAS_TRAILING_NUL -# define SV_HAS_TRAILING_NUL 0 -#endif - -#ifndef SV_COW_SHARED_HASH_KEYS -# define SV_COW_SHARED_HASH_KEYS 0 -#endif - -#if (PERL_BCDVERSION < 0x5007002) - -#if defined(NEED_sv_2pv_flags) -static char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); -static -#else -extern char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); -#endif - -#ifdef sv_2pv_flags -# undef sv_2pv_flags -#endif -#define sv_2pv_flags(a,b,c) DPPP_(my_sv_2pv_flags)(aTHX_ a,b,c) -#define Perl_sv_2pv_flags DPPP_(my_sv_2pv_flags) - -#if defined(NEED_sv_2pv_flags) || defined(NEED_sv_2pv_flags_GLOBAL) - -char * -DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) -{ - STRLEN n_a = (STRLEN) flags; - return sv_2pv(sv, lp ? lp : &n_a); -} - -#endif - -#if defined(NEED_sv_pvn_force_flags) -static char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); -static -#else -extern char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); -#endif - -#ifdef sv_pvn_force_flags -# undef sv_pvn_force_flags -#endif -#define sv_pvn_force_flags(a,b,c) DPPP_(my_sv_pvn_force_flags)(aTHX_ a,b,c) -#define Perl_sv_pvn_force_flags DPPP_(my_sv_pvn_force_flags) - -#if defined(NEED_sv_pvn_force_flags) || defined(NEED_sv_pvn_force_flags_GLOBAL) - -char * -DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) -{ - STRLEN n_a = (STRLEN) flags; - return sv_pvn_force(sv, lp ? lp : &n_a); -} - -#endif - -#endif - -#if (PERL_BCDVERSION < 0x5008008) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5009003) ) -# define DPPP_SVPV_NOLEN_LP_ARG &PL_na -#else -# define DPPP_SVPV_NOLEN_LP_ARG 0 -#endif -#ifndef SvPV_const -# define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) -#endif - -#ifndef SvPV_mutable -# define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) -#endif -#ifndef SvPV_flags -# define SvPV_flags(sv, lp, flags) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) -#endif -#ifndef SvPV_flags_const -# define SvPV_flags_const(sv, lp, flags) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ - (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) -#endif -#ifndef SvPV_flags_const_nolen -# define SvPV_flags_const_nolen(sv, flags) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? SvPVX_const(sv) : \ - (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN)) -#endif -#ifndef SvPV_flags_mutable -# define SvPV_flags_mutable(sv, lp, flags) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ - sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) -#endif -#ifndef SvPV_force -# define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) -#endif - -#ifndef SvPV_force_nolen -# define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) -#endif - -#ifndef SvPV_force_mutable -# define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) -#endif - -#ifndef SvPV_force_nomg -# define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) -#endif - -#ifndef SvPV_force_nomg_nolen -# define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) -#endif -#ifndef SvPV_force_flags -# define SvPV_force_flags(sv, lp, flags) \ - ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ - ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) -#endif -#ifndef SvPV_force_flags_nolen -# define SvPV_force_flags_nolen(sv, flags) \ - ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ - ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags)) -#endif -#ifndef SvPV_force_flags_mutable -# define SvPV_force_flags_mutable(sv, lp, flags) \ - ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ - ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ - : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) -#endif -#ifndef SvPV_nolen -# define SvPV_nolen(sv) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC)) -#endif -#ifndef SvPV_nolen_const -# define SvPV_nolen_const(sv) \ - ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN)) -#endif -#ifndef SvPV_nomg -# define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) -#endif - -#ifndef SvPV_nomg_const -# define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) -#endif - -#ifndef SvPV_nomg_const_nolen -# define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) -#endif - -#ifndef SvPV_nomg_nolen -# define SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ - ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, 0)) -#endif -#ifndef SvPV_renew -# define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \ - SvPV_set((sv), (char *) saferealloc( \ - (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \ - } STMT_END -#endif -#ifndef SvMAGIC_set -# define SvMAGIC_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ - (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END -#endif - -#if (PERL_BCDVERSION < 0x5009003) -#ifndef SvPVX_const -# define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) -#endif - -#ifndef SvPVX_mutable -# define SvPVX_mutable(sv) (0 + SvPVX(sv)) -#endif -#ifndef SvRV_set -# define SvRV_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ - (((XRV*) SvANY(sv))->xrv_rv = (val)); } STMT_END -#endif - -#else -#ifndef SvPVX_const -# define SvPVX_const(sv) ((const char*)((sv)->sv_u.svu_pv)) -#endif - -#ifndef SvPVX_mutable -# define SvPVX_mutable(sv) ((sv)->sv_u.svu_pv) -#endif -#ifndef SvRV_set -# define SvRV_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ - ((sv)->sv_u.svu_rv = (val)); } STMT_END -#endif - -#endif -#ifndef SvSTASH_set -# define SvSTASH_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ - (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END -#endif - -#if (PERL_BCDVERSION < 0x5004000) -#ifndef SvUV_set -# define SvUV_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ - (((XPVIV*) SvANY(sv))->xiv_iv = (IV) (val)); } STMT_END -#endif - -#else -#ifndef SvUV_set -# define SvUV_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ - (((XPVUV*) SvANY(sv))->xuv_uv = (val)); } STMT_END -#endif - -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(vnewSVpvf) -#if defined(NEED_vnewSVpvf) -static SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); -static -#else -extern SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); -#endif - -#ifdef vnewSVpvf -# undef vnewSVpvf -#endif -#define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b) -#define Perl_vnewSVpvf DPPP_(my_vnewSVpvf) - -#if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL) - -SV * -DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args) -{ - register SV *sv = newSV(0); - sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); - return sv; -} - -#endif -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf) -# define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf) -# define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg) -#if defined(NEED_sv_catpvf_mg) -static void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); -static -#else -extern void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); -#endif - -#define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg) - -#if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL) - -void -DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...) -{ - va_list args; - va_start(args, pat); - sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); - SvSETMAGIC(sv); - va_end(args); -} - -#endif -#endif - -#ifdef PERL_IMPLICIT_CONTEXT -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg_nocontext) -#if defined(NEED_sv_catpvf_mg_nocontext) -static void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); -static -#else -extern void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); -#endif - -#define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) -#define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) - -#if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL) - -void -DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...) -{ - dTHX; - va_list args; - va_start(args, pat); - sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); - SvSETMAGIC(sv); - va_end(args); -} - -#endif -#endif -#endif - -/* sv_catpvf_mg depends on sv_catpvf_mg_nocontext */ -#ifndef sv_catpvf_mg -# ifdef PERL_IMPLICIT_CONTEXT -# define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext -# else -# define sv_catpvf_mg Perl_sv_catpvf_mg -# endif -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf_mg) -# define sv_vcatpvf_mg(sv, pat, args) \ - STMT_START { \ - sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ - SvSETMAGIC(sv); \ - } STMT_END -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg) -#if defined(NEED_sv_setpvf_mg) -static void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); -static -#else -extern void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); -#endif - -#define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg) - -#if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL) - -void -DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...) -{ - va_list args; - va_start(args, pat); - sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); - SvSETMAGIC(sv); - va_end(args); -} - -#endif -#endif - -#ifdef PERL_IMPLICIT_CONTEXT -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg_nocontext) -#if defined(NEED_sv_setpvf_mg_nocontext) -static void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); -static -#else -extern void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); -#endif - -#define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) -#define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) - -#if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL) - -void -DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...) -{ - dTHX; - va_list args; - va_start(args, pat); - sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); - SvSETMAGIC(sv); - va_end(args); -} - -#endif -#endif -#endif - -/* sv_setpvf_mg depends on sv_setpvf_mg_nocontext */ -#ifndef sv_setpvf_mg -# ifdef PERL_IMPLICIT_CONTEXT -# define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext -# else -# define sv_setpvf_mg Perl_sv_setpvf_mg -# endif -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf_mg) -# define sv_vsetpvf_mg(sv, pat, args) \ - STMT_START { \ - sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ - SvSETMAGIC(sv); \ - } STMT_END -#endif - -/* Hint: newSVpvn_share - * The SVs created by this function only mimic the behaviour of - * shared PVs without really being shared. Only use if you know - * what you're doing. - */ - -#ifndef newSVpvn_share - -#if defined(NEED_newSVpvn_share) -static SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); -static -#else -extern SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); -#endif - -#ifdef newSVpvn_share -# undef newSVpvn_share -#endif -#define newSVpvn_share(a,b,c) DPPP_(my_newSVpvn_share)(aTHX_ a,b,c) -#define Perl_newSVpvn_share DPPP_(my_newSVpvn_share) - -#if defined(NEED_newSVpvn_share) || defined(NEED_newSVpvn_share_GLOBAL) - -SV * -DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash) -{ - SV *sv; - if (len < 0) - len = -len; - if (!hash) - PERL_HASH(hash, (char*) src, len); - sv = newSVpvn((char *) src, len); - sv_upgrade(sv, SVt_PVIV); - SvIVX(sv) = hash; - SvREADONLY_on(sv); - SvPOK_on(sv); - return sv; -} - -#endif - -#endif -#ifndef SvSHARED_HASH -# define SvSHARED_HASH(sv) (0 + SvUVX(sv)) -#endif -#ifndef HvNAME_get -# define HvNAME_get(hv) HvNAME(hv) -#endif -#ifndef HvNAMELEN_get -# define HvNAMELEN_get(hv) (HvNAME_get(hv) ? (I32)strlen(HvNAME_get(hv)) : 0) -#endif -#ifndef GvSVn -# define GvSVn(gv) GvSV(gv) -#endif - -#ifndef isGV_with_GP -# define isGV_with_GP(gv) isGV(gv) -#endif - -#ifndef gv_fetchpvn_flags -# define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt) -#endif - -#ifndef gv_fetchsv -# define gv_fetchsv(name, flags, svt) gv_fetchpv(SvPV_nolen_const(name), flags, svt) -#endif -#ifndef get_cvn_flags -# define get_cvn_flags(name, namelen, flags) get_cv(name, flags) -#endif -#ifndef WARN_ALL -# define WARN_ALL 0 -#endif - -#ifndef WARN_CLOSURE -# define WARN_CLOSURE 1 -#endif - -#ifndef WARN_DEPRECATED -# define WARN_DEPRECATED 2 -#endif - -#ifndef WARN_EXITING -# define WARN_EXITING 3 -#endif - -#ifndef WARN_GLOB -# define WARN_GLOB 4 -#endif - -#ifndef WARN_IO -# define WARN_IO 5 -#endif - -#ifndef WARN_CLOSED -# define WARN_CLOSED 6 -#endif - -#ifndef WARN_EXEC -# define WARN_EXEC 7 -#endif - -#ifndef WARN_LAYER -# define WARN_LAYER 8 -#endif - -#ifndef WARN_NEWLINE -# define WARN_NEWLINE 9 -#endif - -#ifndef WARN_PIPE -# define WARN_PIPE 10 -#endif - -#ifndef WARN_UNOPENED -# define WARN_UNOPENED 11 -#endif - -#ifndef WARN_MISC -# define WARN_MISC 12 -#endif - -#ifndef WARN_NUMERIC -# define WARN_NUMERIC 13 -#endif - -#ifndef WARN_ONCE -# define WARN_ONCE 14 -#endif - -#ifndef WARN_OVERFLOW -# define WARN_OVERFLOW 15 -#endif - -#ifndef WARN_PACK -# define WARN_PACK 16 -#endif - -#ifndef WARN_PORTABLE -# define WARN_PORTABLE 17 -#endif - -#ifndef WARN_RECURSION -# define WARN_RECURSION 18 -#endif - -#ifndef WARN_REDEFINE -# define WARN_REDEFINE 19 -#endif - -#ifndef WARN_REGEXP -# define WARN_REGEXP 20 -#endif - -#ifndef WARN_SEVERE -# define WARN_SEVERE 21 -#endif - -#ifndef WARN_DEBUGGING -# define WARN_DEBUGGING 22 -#endif - -#ifndef WARN_INPLACE -# define WARN_INPLACE 23 -#endif - -#ifndef WARN_INTERNAL -# define WARN_INTERNAL 24 -#endif - -#ifndef WARN_MALLOC -# define WARN_MALLOC 25 -#endif - -#ifndef WARN_SIGNAL -# define WARN_SIGNAL 26 -#endif - -#ifndef WARN_SUBSTR -# define WARN_SUBSTR 27 -#endif - -#ifndef WARN_SYNTAX -# define WARN_SYNTAX 28 -#endif - -#ifndef WARN_AMBIGUOUS -# define WARN_AMBIGUOUS 29 -#endif - -#ifndef WARN_BAREWORD -# define WARN_BAREWORD 30 -#endif - -#ifndef WARN_DIGIT -# define WARN_DIGIT 31 -#endif - -#ifndef WARN_PARENTHESIS -# define WARN_PARENTHESIS 32 -#endif - -#ifndef WARN_PRECEDENCE -# define WARN_PRECEDENCE 33 -#endif - -#ifndef WARN_PRINTF -# define WARN_PRINTF 34 -#endif - -#ifndef WARN_PROTOTYPE -# define WARN_PROTOTYPE 35 -#endif - -#ifndef WARN_QW -# define WARN_QW 36 -#endif - -#ifndef WARN_RESERVED -# define WARN_RESERVED 37 -#endif - -#ifndef WARN_SEMICOLON -# define WARN_SEMICOLON 38 -#endif - -#ifndef WARN_TAINT -# define WARN_TAINT 39 -#endif - -#ifndef WARN_THREADS -# define WARN_THREADS 40 -#endif - -#ifndef WARN_UNINITIALIZED -# define WARN_UNINITIALIZED 41 -#endif - -#ifndef WARN_UNPACK -# define WARN_UNPACK 42 -#endif - -#ifndef WARN_UNTIE -# define WARN_UNTIE 43 -#endif - -#ifndef WARN_UTF8 -# define WARN_UTF8 44 -#endif - -#ifndef WARN_VOID -# define WARN_VOID 45 -#endif - -#ifndef WARN_ASSERTIONS -# define WARN_ASSERTIONS 46 -#endif -#ifndef packWARN -# define packWARN(a) (a) -#endif - -#ifndef ckWARN -# ifdef G_WARN_ON -# define ckWARN(a) (PL_dowarn & G_WARN_ON) -# else -# define ckWARN(a) PL_dowarn -# endif -#endif - -#if (PERL_BCDVERSION >= 0x5004000) && !defined(warner) -#if defined(NEED_warner) -static void DPPP_(my_warner)(U32 err, const char *pat, ...); -static -#else -extern void DPPP_(my_warner)(U32 err, const char *pat, ...); -#endif - -#define Perl_warner DPPP_(my_warner) - -#if defined(NEED_warner) || defined(NEED_warner_GLOBAL) - -void -DPPP_(my_warner)(U32 err, const char *pat, ...) -{ - SV *sv; - va_list args; - - PERL_UNUSED_ARG(err); - - va_start(args, pat); - sv = vnewSVpvf(pat, &args); - va_end(args); - sv_2mortal(sv); - warn("%s", SvPV_nolen(sv)); -} - -#define warner Perl_warner - -#define Perl_warner_nocontext Perl_warner - -#endif -#endif - -/* concatenating with "" ensures that only literal strings are accepted as argument - * note that STR_WITH_LEN() can't be used as argument to macros or functions that - * under some configurations might be macros - */ -#ifndef STR_WITH_LEN -# define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) -#endif -#ifndef newSVpvs -# define newSVpvs(str) newSVpvn(str "", sizeof(str) - 1) -#endif - -#ifndef newSVpvs_flags -# define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags) -#endif - -#ifndef newSVpvs_share -# define newSVpvs_share(str) newSVpvn_share(str "", sizeof(str) - 1, 0) -#endif - -#ifndef sv_catpvs -# define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1) -#endif - -#ifndef sv_setpvs -# define sv_setpvs(sv, str) sv_setpvn(sv, str "", sizeof(str) - 1) -#endif - -#ifndef hv_fetchs -# define hv_fetchs(hv, key, lval) hv_fetch(hv, key "", sizeof(key) - 1, lval) -#endif - -#ifndef hv_stores -# define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0) -#endif -#ifndef gv_fetchpvs -# define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt) -#endif - -#ifndef gv_stashpvs -# define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags) -#endif -#ifndef get_cvs -# define get_cvs(name, flags) get_cvn_flags(name "", sizeof(name)-1, flags) -#endif -#ifndef SvGETMAGIC -# define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END -#endif - -/* Some random bits for sv_unmagicext. These should probably be pulled in for - real and organized at some point */ -#ifndef HEf_SVKEY -# define HEf_SVKEY -2 -#endif - -#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) -# define MUTABLE_PTR(p) ({ void *_p = (p); _p; }) -#else -# define MUTABLE_PTR(p) ((void *) (p)) -#endif - -#define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p)) - -/* end of random bits */ -#ifndef PERL_MAGIC_sv -# define PERL_MAGIC_sv '\0' -#endif - -#ifndef PERL_MAGIC_overload -# define PERL_MAGIC_overload 'A' -#endif - -#ifndef PERL_MAGIC_overload_elem -# define PERL_MAGIC_overload_elem 'a' -#endif - -#ifndef PERL_MAGIC_overload_table -# define PERL_MAGIC_overload_table 'c' -#endif - -#ifndef PERL_MAGIC_bm -# define PERL_MAGIC_bm 'B' -#endif - -#ifndef PERL_MAGIC_regdata -# define PERL_MAGIC_regdata 'D' -#endif - -#ifndef PERL_MAGIC_regdatum -# define PERL_MAGIC_regdatum 'd' -#endif - -#ifndef PERL_MAGIC_env -# define PERL_MAGIC_env 'E' -#endif - -#ifndef PERL_MAGIC_envelem -# define PERL_MAGIC_envelem 'e' -#endif - -#ifndef PERL_MAGIC_fm -# define PERL_MAGIC_fm 'f' -#endif - -#ifndef PERL_MAGIC_regex_global -# define PERL_MAGIC_regex_global 'g' -#endif - -#ifndef PERL_MAGIC_isa -# define PERL_MAGIC_isa 'I' -#endif - -#ifndef PERL_MAGIC_isaelem -# define PERL_MAGIC_isaelem 'i' -#endif - -#ifndef PERL_MAGIC_nkeys -# define PERL_MAGIC_nkeys 'k' -#endif - -#ifndef PERL_MAGIC_dbfile -# define PERL_MAGIC_dbfile 'L' -#endif - -#ifndef PERL_MAGIC_dbline -# define PERL_MAGIC_dbline 'l' -#endif - -#ifndef PERL_MAGIC_mutex -# define PERL_MAGIC_mutex 'm' -#endif - -#ifndef PERL_MAGIC_shared -# define PERL_MAGIC_shared 'N' -#endif - -#ifndef PERL_MAGIC_shared_scalar -# define PERL_MAGIC_shared_scalar 'n' -#endif - -#ifndef PERL_MAGIC_collxfrm -# define PERL_MAGIC_collxfrm 'o' -#endif - -#ifndef PERL_MAGIC_tied -# define PERL_MAGIC_tied 'P' -#endif - -#ifndef PERL_MAGIC_tiedelem -# define PERL_MAGIC_tiedelem 'p' -#endif - -#ifndef PERL_MAGIC_tiedscalar -# define PERL_MAGIC_tiedscalar 'q' -#endif - -#ifndef PERL_MAGIC_qr -# define PERL_MAGIC_qr 'r' -#endif - -#ifndef PERL_MAGIC_sig -# define PERL_MAGIC_sig 'S' -#endif - -#ifndef PERL_MAGIC_sigelem -# define PERL_MAGIC_sigelem 's' -#endif - -#ifndef PERL_MAGIC_taint -# define PERL_MAGIC_taint 't' -#endif - -#ifndef PERL_MAGIC_uvar -# define PERL_MAGIC_uvar 'U' -#endif - -#ifndef PERL_MAGIC_uvar_elem -# define PERL_MAGIC_uvar_elem 'u' -#endif - -#ifndef PERL_MAGIC_vstring -# define PERL_MAGIC_vstring 'V' -#endif - -#ifndef PERL_MAGIC_vec -# define PERL_MAGIC_vec 'v' -#endif - -#ifndef PERL_MAGIC_utf8 -# define PERL_MAGIC_utf8 'w' -#endif - -#ifndef PERL_MAGIC_substr -# define PERL_MAGIC_substr 'x' -#endif - -#ifndef PERL_MAGIC_defelem -# define PERL_MAGIC_defelem 'y' -#endif - -#ifndef PERL_MAGIC_glob -# define PERL_MAGIC_glob '*' -#endif - -#ifndef PERL_MAGIC_arylen -# define PERL_MAGIC_arylen '#' -#endif - -#ifndef PERL_MAGIC_pos -# define PERL_MAGIC_pos '.' -#endif - -#ifndef PERL_MAGIC_backref -# define PERL_MAGIC_backref '<' -#endif - -#ifndef PERL_MAGIC_ext -# define PERL_MAGIC_ext '~' -#endif - -/* That's the best we can do... */ -#ifndef sv_catpvn_nomg -# define sv_catpvn_nomg sv_catpvn -#endif - -#ifndef sv_catsv_nomg -# define sv_catsv_nomg sv_catsv -#endif - -#ifndef sv_setsv_nomg -# define sv_setsv_nomg sv_setsv -#endif - -#ifndef sv_pvn_nomg -# define sv_pvn_nomg sv_pvn -#endif - -#ifndef SvIV_nomg -# define SvIV_nomg SvIV -#endif - -#ifndef SvUV_nomg -# define SvUV_nomg SvUV -#endif - -#ifndef sv_catpv_mg -# define sv_catpv_mg(sv, ptr) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_catpv(TeMpSv,ptr); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_catpvn_mg -# define sv_catpvn_mg(sv, ptr, len) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_catpvn(TeMpSv,ptr,len); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_catsv_mg -# define sv_catsv_mg(dsv, ssv) \ - STMT_START { \ - SV *TeMpSv = dsv; \ - sv_catsv(TeMpSv,ssv); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setiv_mg -# define sv_setiv_mg(sv, i) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_setiv(TeMpSv,i); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setnv_mg -# define sv_setnv_mg(sv, num) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_setnv(TeMpSv,num); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setpv_mg -# define sv_setpv_mg(sv, ptr) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_setpv(TeMpSv,ptr); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setpvn_mg -# define sv_setpvn_mg(sv, ptr, len) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_setpvn(TeMpSv,ptr,len); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setsv_mg -# define sv_setsv_mg(dsv, ssv) \ - STMT_START { \ - SV *TeMpSv = dsv; \ - sv_setsv(TeMpSv,ssv); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_setuv_mg -# define sv_setuv_mg(sv, i) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_setuv(TeMpSv,i); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif - -#ifndef sv_usepvn_mg -# define sv_usepvn_mg(sv, ptr, len) \ - STMT_START { \ - SV *TeMpSv = sv; \ - sv_usepvn(TeMpSv,ptr,len); \ - SvSETMAGIC(TeMpSv); \ - } STMT_END -#endif -#ifndef SvVSTRING_mg -# define SvVSTRING_mg(sv) (SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_vstring) : NULL) -#endif - -/* Hint: sv_magic_portable - * This is a compatibility function that is only available with - * Devel::PPPort. It is NOT in the perl core. - * Its purpose is to mimic the 5.8.0 behaviour of sv_magic() when - * it is being passed a name pointer with namlen == 0. In that - * case, perl 5.8.0 and later store the pointer, not a copy of it. - * The compatibility can be provided back to perl 5.004. With - * earlier versions, the code will not compile. - */ - -#if (PERL_BCDVERSION < 0x5004000) - - /* code that uses sv_magic_portable will not compile */ - -#elif (PERL_BCDVERSION < 0x5008000) - -# define sv_magic_portable(sv, obj, how, name, namlen) \ - STMT_START { \ - SV *SvMp_sv = (sv); \ - char *SvMp_name = (char *) (name); \ - I32 SvMp_namlen = (namlen); \ - if (SvMp_name && SvMp_namlen == 0) \ - { \ - MAGIC *mg; \ - sv_magic(SvMp_sv, obj, how, 0, 0); \ - mg = SvMAGIC(SvMp_sv); \ - mg->mg_len = -42; /* XXX: this is the tricky part */ \ - mg->mg_ptr = SvMp_name; \ - } \ - else \ - { \ - sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \ - } \ - } STMT_END - -#else - -# define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e) - -#endif - -#if !defined(mg_findext) -#if defined(NEED_mg_findext) -static MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); -static -#else -extern MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); -#endif - -#define mg_findext DPPP_(my_mg_findext) -#define Perl_mg_findext DPPP_(my_mg_findext) - -#if defined(NEED_mg_findext) || defined(NEED_mg_findext_GLOBAL) - -MAGIC * -DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl) { - if (sv) { - MAGIC *mg; - -#ifdef AvPAD_NAMELIST - assert(!(SvTYPE(sv) == SVt_PVAV && AvPAD_NAMELIST(sv))); -#endif - - for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) { - if (mg->mg_type == type && mg->mg_virtual == vtbl) - return mg; - } - } - - return NULL; -} - -#endif -#endif - -#if !defined(sv_unmagicext) -#if defined(NEED_sv_unmagicext) -static int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); -static -#else -extern int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); -#endif - -#ifdef sv_unmagicext -# undef sv_unmagicext -#endif -#define sv_unmagicext(a,b,c) DPPP_(my_sv_unmagicext)(aTHX_ a,b,c) -#define Perl_sv_unmagicext DPPP_(my_sv_unmagicext) - -#if defined(NEED_sv_unmagicext) || defined(NEED_sv_unmagicext_GLOBAL) - -int -DPPP_(my_sv_unmagicext)(pTHX_ SV *const sv, const int type, MGVTBL *vtbl) -{ - MAGIC* mg; - MAGIC** mgp; - - if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv)) - return 0; - mgp = &(SvMAGIC(sv)); - for (mg = *mgp; mg; mg = *mgp) { - const MGVTBL* const virt = mg->mg_virtual; - if (mg->mg_type == type && virt == vtbl) { - *mgp = mg->mg_moremagic; - if (virt && virt->svt_free) - virt->svt_free(aTHX_ sv, mg); - if (mg->mg_ptr && mg->mg_type != PERL_MAGIC_regex_global) { - if (mg->mg_len > 0) - Safefree(mg->mg_ptr); - else if (mg->mg_len == HEf_SVKEY) /* Questionable on older perls... */ - SvREFCNT_dec(MUTABLE_SV(mg->mg_ptr)); - else if (mg->mg_type == PERL_MAGIC_utf8) - Safefree(mg->mg_ptr); - } - if (mg->mg_flags & MGf_REFCOUNTED) - SvREFCNT_dec(mg->mg_obj); - Safefree(mg); - } - else - mgp = &mg->mg_moremagic; - } - if (SvMAGIC(sv)) { - if (SvMAGICAL(sv)) /* if we're under save_magic, wait for restore_magic; */ - mg_magical(sv); /* else fix the flags now */ - } - else { - SvMAGICAL_off(sv); - SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT; - } - return 0; -} - -#endif -#endif - -#ifdef USE_ITHREADS -#ifndef CopFILE -# define CopFILE(c) ((c)->cop_file) -#endif - -#ifndef CopFILEGV -# define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv) -#endif - -#ifndef CopFILE_set -# define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) -#endif - -#ifndef CopFILESV -# define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv) -#endif - -#ifndef CopFILEAV -# define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav) -#endif - -#ifndef CopSTASHPV -# define CopSTASHPV(c) ((c)->cop_stashpv) -#endif - -#ifndef CopSTASHPV_set -# define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch)) -#endif - -#ifndef CopSTASH -# define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv) -#endif - -#ifndef CopSTASH_set -# define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch) -#endif - -#ifndef CopSTASH_eq -# define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \ - || (CopSTASHPV(c) && HvNAME(hv) \ - && strEQ(CopSTASHPV(c), HvNAME(hv))))) -#endif - -#else -#ifndef CopFILEGV -# define CopFILEGV(c) ((c)->cop_filegv) -#endif - -#ifndef CopFILEGV_set -# define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) -#endif - -#ifndef CopFILE_set -# define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) -#endif - -#ifndef CopFILESV -# define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv) -#endif - -#ifndef CopFILEAV -# define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav) -#endif - -#ifndef CopFILE -# define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch) -#endif - -#ifndef CopSTASH -# define CopSTASH(c) ((c)->cop_stash) -#endif - -#ifndef CopSTASH_set -# define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) -#endif - -#ifndef CopSTASHPV -# define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch) -#endif - -#ifndef CopSTASHPV_set -# define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) -#endif - -#ifndef CopSTASH_eq -# define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) -#endif - -#endif /* USE_ITHREADS */ - -#if (PERL_BCDVERSION >= 0x5006000) -#ifndef caller_cx - -# if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) -static I32 -DPPP_dopoptosub_at(const PERL_CONTEXT *cxstk, I32 startingblock) -{ - I32 i; - - for (i = startingblock; i >= 0; i--) { - register const PERL_CONTEXT * const cx = &cxstk[i]; - switch (CxTYPE(cx)) { - default: - continue; - case CXt_EVAL: - case CXt_SUB: - case CXt_FORMAT: - return i; - } - } - return i; -} -# endif - -# if defined(NEED_caller_cx) -static const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); -static -#else -extern const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); -#endif - -#ifdef caller_cx -# undef caller_cx -#endif -#define caller_cx(a,b) DPPP_(my_caller_cx)(aTHX_ a,b) -#define Perl_caller_cx DPPP_(my_caller_cx) - -#if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) - -const PERL_CONTEXT * -DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp) -{ - register I32 cxix = DPPP_dopoptosub_at(cxstack, cxstack_ix); - register const PERL_CONTEXT *cx; - register const PERL_CONTEXT *ccstack = cxstack; - const PERL_SI *top_si = PL_curstackinfo; - - for (;;) { - /* we may be in a higher stacklevel, so dig down deeper */ - while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { - top_si = top_si->si_prev; - ccstack = top_si->si_cxstack; - cxix = DPPP_dopoptosub_at(ccstack, top_si->si_cxix); - } - if (cxix < 0) - return NULL; - /* caller() should not report the automatic calls to &DB::sub */ - if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && - ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) - count++; - if (!count--) - break; - cxix = DPPP_dopoptosub_at(ccstack, cxix - 1); - } - - cx = &ccstack[cxix]; - if (dbcxp) *dbcxp = cx; - - if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { - const I32 dbcxix = DPPP_dopoptosub_at(ccstack, cxix - 1); - /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the - field below is defined for any cx. */ - /* caller() should not report the automatic calls to &DB::sub */ - if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) - cx = &ccstack[dbcxix]; - } - - return cx; -} - -# endif -#endif /* caller_cx */ -#endif /* 5.6.0 */ -#ifndef IN_PERL_COMPILETIME -# define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) -#endif - -#ifndef IN_LOCALE_RUNTIME -# define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE) -#endif - -#ifndef IN_LOCALE_COMPILETIME -# define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) -#endif - -#ifndef IN_LOCALE -# define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) -#endif -#ifndef IS_NUMBER_IN_UV -# define IS_NUMBER_IN_UV 0x01 -#endif - -#ifndef IS_NUMBER_GREATER_THAN_UV_MAX -# define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 -#endif - -#ifndef IS_NUMBER_NOT_INT -# define IS_NUMBER_NOT_INT 0x04 -#endif - -#ifndef IS_NUMBER_NEG -# define IS_NUMBER_NEG 0x08 -#endif - -#ifndef IS_NUMBER_INFINITY -# define IS_NUMBER_INFINITY 0x10 -#endif - -#ifndef IS_NUMBER_NAN -# define IS_NUMBER_NAN 0x20 -#endif -#ifndef GROK_NUMERIC_RADIX -# define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) -#endif -#ifndef PERL_SCAN_GREATER_THAN_UV_MAX -# define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 -#endif - -#ifndef PERL_SCAN_SILENT_ILLDIGIT -# define PERL_SCAN_SILENT_ILLDIGIT 0x04 -#endif - -#ifndef PERL_SCAN_ALLOW_UNDERSCORES -# define PERL_SCAN_ALLOW_UNDERSCORES 0x01 -#endif - -#ifndef PERL_SCAN_DISALLOW_PREFIX -# define PERL_SCAN_DISALLOW_PREFIX 0x02 -#endif - -#ifndef grok_numeric_radix -#if defined(NEED_grok_numeric_radix) -static bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); -static -#else -extern bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); -#endif - -#ifdef grok_numeric_radix -# undef grok_numeric_radix -#endif -#define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b) -#define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix) - -#if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL) -bool -DPPP_(my_grok_numeric_radix)(pTHX_ const char **sp, const char *send) -{ -#ifdef USE_LOCALE_NUMERIC -#ifdef PL_numeric_radix_sv - if (PL_numeric_radix_sv && IN_LOCALE) { - STRLEN len; - char* radix = SvPV(PL_numeric_radix_sv, len); - if (*sp + len <= send && memEQ(*sp, radix, len)) { - *sp += len; - return TRUE; - } - } -#else - /* older perls don't have PL_numeric_radix_sv so the radix - * must manually be requested from locale.h - */ -#include - dTHR; /* needed for older threaded perls */ - struct lconv *lc = localeconv(); - char *radix = lc->decimal_point; - if (radix && IN_LOCALE) { - STRLEN len = strlen(radix); - if (*sp + len <= send && memEQ(*sp, radix, len)) { - *sp += len; - return TRUE; - } - } -#endif -#endif /* USE_LOCALE_NUMERIC */ - /* always try "." if numeric radix didn't match because - * we may have data from different locales mixed */ - if (*sp < send && **sp == '.') { - ++*sp; - return TRUE; - } - return FALSE; -} -#endif -#endif - -#ifndef grok_number -#if defined(NEED_grok_number) -static int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); -static -#else -extern int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); -#endif - -#ifdef grok_number -# undef grok_number -#endif -#define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c) -#define Perl_grok_number DPPP_(my_grok_number) - -#if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL) -int -DPPP_(my_grok_number)(pTHX_ const char *pv, STRLEN len, UV *valuep) -{ - const char *s = pv; - const char *send = pv + len; - const UV max_div_10 = UV_MAX / 10; - const char max_mod_10 = UV_MAX % 10; - int numtype = 0; - int sawinf = 0; - int sawnan = 0; - - while (s < send && isSPACE(*s)) - s++; - if (s == send) { - return 0; - } else if (*s == '-') { - s++; - numtype = IS_NUMBER_NEG; - } - else if (*s == '+') - s++; - - if (s == send) - return 0; - - /* next must be digit or the radix separator or beginning of infinity */ - if (isDIGIT(*s)) { - /* UVs are at least 32 bits, so the first 9 decimal digits cannot - overflow. */ - UV value = *s - '0'; - /* This construction seems to be more optimiser friendly. - (without it gcc does the isDIGIT test and the *s - '0' separately) - With it gcc on arm is managing 6 instructions (6 cycles) per digit. - In theory the optimiser could deduce how far to unroll the loop - before checking for overflow. */ - if (++s < send) { - int digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - digit = *s - '0'; - if (digit >= 0 && digit <= 9) { - value = value * 10 + digit; - if (++s < send) { - /* Now got 9 digits, so need to check - each time for overflow. */ - digit = *s - '0'; - while (digit >= 0 && digit <= 9 - && (value < max_div_10 - || (value == max_div_10 - && digit <= max_mod_10))) { - value = value * 10 + digit; - if (++s < send) - digit = *s - '0'; - else - break; - } - if (digit >= 0 && digit <= 9 - && (s < send)) { - /* value overflowed. - skip the remaining digits, don't - worry about setting *valuep. */ - do { - s++; - } while (s < send && isDIGIT(*s)); - numtype |= - IS_NUMBER_GREATER_THAN_UV_MAX; - goto skip_value; - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - numtype |= IS_NUMBER_IN_UV; - if (valuep) - *valuep = value; - - skip_value: - if (GROK_NUMERIC_RADIX(&s, send)) { - numtype |= IS_NUMBER_NOT_INT; - while (s < send && isDIGIT(*s)) /* optional digits after the radix */ - s++; - } - } - else if (GROK_NUMERIC_RADIX(&s, send)) { - numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */ - /* no digits before the radix means we need digits after it */ - if (s < send && isDIGIT(*s)) { - do { - s++; - } while (s < send && isDIGIT(*s)); - if (valuep) { - /* integer approximation is valid - it's 0. */ - *valuep = 0; - } - } - else - return 0; - } else if (*s == 'I' || *s == 'i') { - s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; - s++; if (s == send || (*s != 'F' && *s != 'f')) return 0; - s++; if (s < send && (*s == 'I' || *s == 'i')) { - s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; - s++; if (s == send || (*s != 'I' && *s != 'i')) return 0; - s++; if (s == send || (*s != 'T' && *s != 't')) return 0; - s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0; - s++; - } - sawinf = 1; - } else if (*s == 'N' || *s == 'n') { - /* XXX TODO: There are signaling NaNs and quiet NaNs. */ - s++; if (s == send || (*s != 'A' && *s != 'a')) return 0; - s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; - s++; - sawnan = 1; - } else - return 0; - - if (sawinf) { - numtype &= IS_NUMBER_NEG; /* Keep track of sign */ - numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT; - } else if (sawnan) { - numtype &= IS_NUMBER_NEG; /* Keep track of sign */ - numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT; - } else if (s < send) { - /* we can have an optional exponent part */ - if (*s == 'e' || *s == 'E') { - /* The only flag we keep is sign. Blow away any "it's UV" */ - numtype &= IS_NUMBER_NEG; - numtype |= IS_NUMBER_NOT_INT; - s++; - if (s < send && (*s == '-' || *s == '+')) - s++; - if (s < send && isDIGIT(*s)) { - do { - s++; - } while (s < send && isDIGIT(*s)); - } - else - return 0; - } - } - while (s < send && isSPACE(*s)) - s++; - if (s >= send) - return numtype; - if (len == 10 && memEQ(pv, "0 but true", 10)) { - if (valuep) - *valuep = 0; - return IS_NUMBER_IN_UV; - } - return 0; -} -#endif -#endif - -/* - * The grok_* routines have been modified to use warn() instead of - * Perl_warner(). Also, 'hexdigit' was the former name of PL_hexdigit, - * which is why the stack variable has been renamed to 'xdigit'. - */ - -#ifndef grok_bin -#if defined(NEED_grok_bin) -static UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -static -#else -extern UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -#endif - -#ifdef grok_bin -# undef grok_bin -#endif -#define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d) -#define Perl_grok_bin DPPP_(my_grok_bin) - -#if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL) -UV -DPPP_(my_grok_bin)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) -{ - const char *s = start; - STRLEN len = *len_p; - UV value = 0; - NV value_nv = 0; - - const UV max_div_2 = UV_MAX / 2; - bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; - bool overflowed = FALSE; - - if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { - /* strip off leading b or 0b. - for compatibility silently suffer "b" and "0b" as valid binary - numbers. */ - if (len >= 1) { - if (s[0] == 'b') { - s++; - len--; - } - else if (len >= 2 && s[0] == '0' && s[1] == 'b') { - s+=2; - len-=2; - } - } - } - - for (; len-- && *s; s++) { - char bit = *s; - if (bit == '0' || bit == '1') { - /* Write it in this wonky order with a goto to attempt to get the - compiler to make the common case integer-only loop pretty tight. - With gcc seems to be much straighter code than old scan_bin. */ - redo: - if (!overflowed) { - if (value <= max_div_2) { - value = (value << 1) | (bit - '0'); - continue; - } - /* Bah. We're just overflowed. */ - warn("Integer overflow in binary number"); - overflowed = TRUE; - value_nv = (NV) value; - } - value_nv *= 2.0; - /* If an NV has not enough bits in its mantissa to - * represent a UV this summing of small low-order numbers - * is a waste of time (because the NV cannot preserve - * the low-order bits anyway): we could just remember when - * did we overflow and in the end just multiply value_nv by the - * right amount. */ - value_nv += (NV)(bit - '0'); - continue; - } - if (bit == '_' && len && allow_underscores && (bit = s[1]) - && (bit == '0' || bit == '1')) - { - --len; - ++s; - goto redo; - } - if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) - warn("Illegal binary digit '%c' ignored", *s); - break; - } - - if ( ( overflowed && value_nv > 4294967295.0) -#if UVSIZE > 4 - || (!overflowed && value > 0xffffffff ) -#endif - ) { - warn("Binary number > 0b11111111111111111111111111111111 non-portable"); - } - *len_p = s - start; - if (!overflowed) { - *flags = 0; - return value; - } - *flags = PERL_SCAN_GREATER_THAN_UV_MAX; - if (result) - *result = value_nv; - return UV_MAX; -} -#endif -#endif - -#ifndef grok_hex -#if defined(NEED_grok_hex) -static UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -static -#else -extern UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -#endif - -#ifdef grok_hex -# undef grok_hex -#endif -#define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d) -#define Perl_grok_hex DPPP_(my_grok_hex) - -#if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL) -UV -DPPP_(my_grok_hex)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) -{ - const char *s = start; - STRLEN len = *len_p; - UV value = 0; - NV value_nv = 0; - - const UV max_div_16 = UV_MAX / 16; - bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; - bool overflowed = FALSE; - const char *xdigit; - - if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { - /* strip off leading x or 0x. - for compatibility silently suffer "x" and "0x" as valid hex numbers. - */ - if (len >= 1) { - if (s[0] == 'x') { - s++; - len--; - } - else if (len >= 2 && s[0] == '0' && s[1] == 'x') { - s+=2; - len-=2; - } - } - } - - for (; len-- && *s; s++) { - xdigit = strchr((char *) PL_hexdigit, *s); - if (xdigit) { - /* Write it in this wonky order with a goto to attempt to get the - compiler to make the common case integer-only loop pretty tight. - With gcc seems to be much straighter code than old scan_hex. */ - redo: - if (!overflowed) { - if (value <= max_div_16) { - value = (value << 4) | ((xdigit - PL_hexdigit) & 15); - continue; - } - warn("Integer overflow in hexadecimal number"); - overflowed = TRUE; - value_nv = (NV) value; - } - value_nv *= 16.0; - /* If an NV has not enough bits in its mantissa to - * represent a UV this summing of small low-order numbers - * is a waste of time (because the NV cannot preserve - * the low-order bits anyway): we could just remember when - * did we overflow and in the end just multiply value_nv by the - * right amount of 16-tuples. */ - value_nv += (NV)((xdigit - PL_hexdigit) & 15); - continue; - } - if (*s == '_' && len && allow_underscores && s[1] - && (xdigit = strchr((char *) PL_hexdigit, s[1]))) - { - --len; - ++s; - goto redo; - } - if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) - warn("Illegal hexadecimal digit '%c' ignored", *s); - break; - } - - if ( ( overflowed && value_nv > 4294967295.0) -#if UVSIZE > 4 - || (!overflowed && value > 0xffffffff ) -#endif - ) { - warn("Hexadecimal number > 0xffffffff non-portable"); - } - *len_p = s - start; - if (!overflowed) { - *flags = 0; - return value; - } - *flags = PERL_SCAN_GREATER_THAN_UV_MAX; - if (result) - *result = value_nv; - return UV_MAX; -} -#endif -#endif - -#ifndef grok_oct -#if defined(NEED_grok_oct) -static UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -static -#else -extern UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); -#endif - -#ifdef grok_oct -# undef grok_oct -#endif -#define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d) -#define Perl_grok_oct DPPP_(my_grok_oct) - -#if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL) -UV -DPPP_(my_grok_oct)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) -{ - const char *s = start; - STRLEN len = *len_p; - UV value = 0; - NV value_nv = 0; - - const UV max_div_8 = UV_MAX / 8; - bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; - bool overflowed = FALSE; - - for (; len-- && *s; s++) { - /* gcc 2.95 optimiser not smart enough to figure that this subtraction - out front allows slicker code. */ - int digit = *s - '0'; - if (digit >= 0 && digit <= 7) { - /* Write it in this wonky order with a goto to attempt to get the - compiler to make the common case integer-only loop pretty tight. - */ - redo: - if (!overflowed) { - if (value <= max_div_8) { - value = (value << 3) | digit; - continue; - } - /* Bah. We're just overflowed. */ - warn("Integer overflow in octal number"); - overflowed = TRUE; - value_nv = (NV) value; - } - value_nv *= 8.0; - /* If an NV has not enough bits in its mantissa to - * represent a UV this summing of small low-order numbers - * is a waste of time (because the NV cannot preserve - * the low-order bits anyway): we could just remember when - * did we overflow and in the end just multiply value_nv by the - * right amount of 8-tuples. */ - value_nv += (NV)digit; - continue; - } - if (digit == ('_' - '0') && len && allow_underscores - && (digit = s[1] - '0') && (digit >= 0 && digit <= 7)) - { - --len; - ++s; - goto redo; - } - /* Allow \octal to work the DWIM way (that is, stop scanning - * as soon as non-octal characters are seen, complain only iff - * someone seems to want to use the digits eight and nine). */ - if (digit == 8 || digit == 9) { - if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) - warn("Illegal octal digit '%c' ignored", *s); - } - break; - } - - if ( ( overflowed && value_nv > 4294967295.0) -#if UVSIZE > 4 - || (!overflowed && value > 0xffffffff ) -#endif - ) { - warn("Octal number > 037777777777 non-portable"); - } - *len_p = s - start; - if (!overflowed) { - *flags = 0; - return value; - } - *flags = PERL_SCAN_GREATER_THAN_UV_MAX; - if (result) - *result = value_nv; - return UV_MAX; -} -#endif -#endif - -#if !defined(my_snprintf) -#if defined(NEED_my_snprintf) -static int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); -static -#else -extern int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); -#endif - -#define my_snprintf DPPP_(my_my_snprintf) -#define Perl_my_snprintf DPPP_(my_my_snprintf) - -#if defined(NEED_my_snprintf) || defined(NEED_my_snprintf_GLOBAL) - -int -DPPP_(my_my_snprintf)(char *buffer, const Size_t len, const char *format, ...) -{ - dTHX; - int retval; - va_list ap; - va_start(ap, format); -#ifdef HAS_VSNPRINTF - retval = vsnprintf(buffer, len, format, ap); -#else - retval = vsprintf(buffer, format, ap); -#endif - va_end(ap); - if (retval < 0 || (len > 0 && (Size_t)retval >= len)) - Perl_croak(aTHX_ "panic: my_snprintf buffer overflow"); - return retval; -} - -#endif -#endif - -#if !defined(my_sprintf) -#if defined(NEED_my_sprintf) -static int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); -static -#else -extern int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); -#endif - -#define my_sprintf DPPP_(my_my_sprintf) -#define Perl_my_sprintf DPPP_(my_my_sprintf) - -#if defined(NEED_my_sprintf) || defined(NEED_my_sprintf_GLOBAL) - -int -DPPP_(my_my_sprintf)(char *buffer, const char* pat, ...) -{ - va_list args; - va_start(args, pat); - vsprintf(buffer, pat, args); - va_end(args); - return strlen(buffer); -} - -#endif -#endif - -#ifdef NO_XSLOCKS -# ifdef dJMPENV -# define dXCPT dJMPENV; int rEtV = 0 -# define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) -# define XCPT_TRY_END JMPENV_POP; -# define XCPT_CATCH if (rEtV != 0) -# define XCPT_RETHROW JMPENV_JUMP(rEtV) -# else -# define dXCPT Sigjmp_buf oldTOP; int rEtV = 0 -# define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0) -# define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf); -# define XCPT_CATCH if (rEtV != 0) -# define XCPT_RETHROW Siglongjmp(top_env, rEtV) -# endif -#endif - -#if !defined(my_strlcat) -#if defined(NEED_my_strlcat) -static Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); -static -#else -extern Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); -#endif - -#define my_strlcat DPPP_(my_my_strlcat) -#define Perl_my_strlcat DPPP_(my_my_strlcat) - -#if defined(NEED_my_strlcat) || defined(NEED_my_strlcat_GLOBAL) - -Size_t -DPPP_(my_my_strlcat)(char *dst, const char *src, Size_t size) -{ - Size_t used, length, copy; - - used = strlen(dst); - length = strlen(src); - if (size > 0 && used < size - 1) { - copy = (length >= size - used) ? size - used - 1 : length; - memcpy(dst + used, src, copy); - dst[used + copy] = '\0'; - } - return used + length; -} -#endif -#endif - -#if !defined(my_strlcpy) -#if defined(NEED_my_strlcpy) -static Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); -static -#else -extern Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); -#endif - -#define my_strlcpy DPPP_(my_my_strlcpy) -#define Perl_my_strlcpy DPPP_(my_my_strlcpy) - -#if defined(NEED_my_strlcpy) || defined(NEED_my_strlcpy_GLOBAL) - -Size_t -DPPP_(my_my_strlcpy)(char *dst, const char *src, Size_t size) -{ - Size_t length, copy; - - length = strlen(src); - if (size > 0) { - copy = (length >= size) ? size - 1 : length; - memcpy(dst, src, copy); - dst[copy] = '\0'; - } - return length; -} - -#endif -#endif -#ifndef PERL_PV_ESCAPE_QUOTE -# define PERL_PV_ESCAPE_QUOTE 0x0001 -#endif - -#ifndef PERL_PV_PRETTY_QUOTE -# define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE -#endif - -#ifndef PERL_PV_PRETTY_ELLIPSES -# define PERL_PV_PRETTY_ELLIPSES 0x0002 -#endif - -#ifndef PERL_PV_PRETTY_LTGT -# define PERL_PV_PRETTY_LTGT 0x0004 -#endif - -#ifndef PERL_PV_ESCAPE_FIRSTCHAR -# define PERL_PV_ESCAPE_FIRSTCHAR 0x0008 -#endif - -#ifndef PERL_PV_ESCAPE_UNI -# define PERL_PV_ESCAPE_UNI 0x0100 -#endif - -#ifndef PERL_PV_ESCAPE_UNI_DETECT -# define PERL_PV_ESCAPE_UNI_DETECT 0x0200 -#endif - -#ifndef PERL_PV_ESCAPE_ALL -# define PERL_PV_ESCAPE_ALL 0x1000 -#endif - -#ifndef PERL_PV_ESCAPE_NOBACKSLASH -# define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 -#endif - -#ifndef PERL_PV_ESCAPE_NOCLEAR -# define PERL_PV_ESCAPE_NOCLEAR 0x4000 -#endif - -#ifndef PERL_PV_ESCAPE_RE -# define PERL_PV_ESCAPE_RE 0x8000 -#endif - -#ifndef PERL_PV_PRETTY_NOCLEAR -# define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR -#endif -#ifndef PERL_PV_PRETTY_DUMP -# define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE -#endif - -#ifndef PERL_PV_PRETTY_REGPROP -# define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE -#endif - -/* Hint: pv_escape - * Note that unicode functionality is only backported to - * those perl versions that support it. For older perl - * versions, the implementation will fall back to bytes. - */ - -#ifndef pv_escape -#if defined(NEED_pv_escape) -static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); -static -#else -extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); -#endif - -#ifdef pv_escape -# undef pv_escape -#endif -#define pv_escape(a,b,c,d,e,f) DPPP_(my_pv_escape)(aTHX_ a,b,c,d,e,f) -#define Perl_pv_escape DPPP_(my_pv_escape) - -#if defined(NEED_pv_escape) || defined(NEED_pv_escape_GLOBAL) - -char * -DPPP_(my_pv_escape)(pTHX_ SV *dsv, char const * const str, - const STRLEN count, const STRLEN max, - STRLEN * const escaped, const U32 flags) -{ - const char esc = flags & PERL_PV_ESCAPE_RE ? '%' : '\\'; - const char dq = flags & PERL_PV_ESCAPE_QUOTE ? '"' : esc; - char octbuf[32] = "%123456789ABCDF"; - STRLEN wrote = 0; - STRLEN chsize = 0; - STRLEN readsize = 1; -#if defined(is_utf8_string) && defined(utf8_to_uvchr) - bool isuni = flags & PERL_PV_ESCAPE_UNI ? 1 : 0; -#endif - const char *pv = str; - const char * const end = pv + count; - octbuf[0] = esc; - - if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) - sv_setpvs(dsv, ""); - -#if defined(is_utf8_string) && defined(utf8_to_uvchr) - if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count)) - isuni = 1; -#endif - - for (; pv < end && (!max || wrote < max) ; pv += readsize) { - const UV u = -#if defined(is_utf8_string) && defined(utf8_to_uvchr) - isuni ? utf8_to_uvchr((U8*)pv, &readsize) : -#endif - (U8)*pv; - const U8 c = (U8)u & 0xFF; - - if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) { - if (flags & PERL_PV_ESCAPE_FIRSTCHAR) - chsize = my_snprintf(octbuf, sizeof octbuf, - "%" UVxf, u); - else - chsize = my_snprintf(octbuf, sizeof octbuf, - "%cx{%" UVxf "}", esc, u); - } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) { - chsize = 1; - } else { - if (c == dq || c == esc || !isPRINT(c)) { - chsize = 2; - switch (c) { - case '\\' : /* fallthrough */ - case '%' : if (c == esc) - octbuf[1] = esc; - else - chsize = 1; - break; - case '\v' : octbuf[1] = 'v'; break; - case '\t' : octbuf[1] = 't'; break; - case '\r' : octbuf[1] = 'r'; break; - case '\n' : octbuf[1] = 'n'; break; - case '\f' : octbuf[1] = 'f'; break; - case '"' : if (dq == '"') - octbuf[1] = '"'; - else - chsize = 1; - break; - default: chsize = my_snprintf(octbuf, sizeof octbuf, - pv < end && isDIGIT((U8)*(pv+readsize)) - ? "%c%03o" : "%c%o", esc, c); - } - } else { - chsize = 1; - } - } - if (max && wrote + chsize > max) { - break; - } else if (chsize > 1) { - sv_catpvn(dsv, octbuf, chsize); - wrote += chsize; - } else { - char tmp[2]; - my_snprintf(tmp, sizeof tmp, "%c", c); - sv_catpvn(dsv, tmp, 1); - wrote++; - } - if (flags & PERL_PV_ESCAPE_FIRSTCHAR) - break; - } - if (escaped != NULL) - *escaped= pv - str; - return SvPVX(dsv); -} - -#endif -#endif - -#ifndef pv_pretty -#if defined(NEED_pv_pretty) -static char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); -static -#else -extern char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); -#endif - -#ifdef pv_pretty -# undef pv_pretty -#endif -#define pv_pretty(a,b,c,d,e,f,g) DPPP_(my_pv_pretty)(aTHX_ a,b,c,d,e,f,g) -#define Perl_pv_pretty DPPP_(my_pv_pretty) - -#if defined(NEED_pv_pretty) || defined(NEED_pv_pretty_GLOBAL) - -char * -DPPP_(my_pv_pretty)(pTHX_ SV *dsv, char const * const str, const STRLEN count, - const STRLEN max, char const * const start_color, char const * const end_color, - const U32 flags) -{ - const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%'; - STRLEN escaped; - - if (!(flags & PERL_PV_PRETTY_NOCLEAR)) - sv_setpvs(dsv, ""); - - if (dq == '"') - sv_catpvs(dsv, "\""); - else if (flags & PERL_PV_PRETTY_LTGT) - sv_catpvs(dsv, "<"); - - if (start_color != NULL) - sv_catpv(dsv, D_PPP_CONSTPV_ARG(start_color)); - - pv_escape(dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR); - - if (end_color != NULL) - sv_catpv(dsv, D_PPP_CONSTPV_ARG(end_color)); - - if (dq == '"') - sv_catpvs(dsv, "\""); - else if (flags & PERL_PV_PRETTY_LTGT) - sv_catpvs(dsv, ">"); - - if ((flags & PERL_PV_PRETTY_ELLIPSES) && escaped < count) - sv_catpvs(dsv, "..."); - - return SvPVX(dsv); -} - -#endif -#endif - -#ifndef pv_display -#if defined(NEED_pv_display) -static char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); -static -#else -extern char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); -#endif - -#ifdef pv_display -# undef pv_display -#endif -#define pv_display(a,b,c,d,e) DPPP_(my_pv_display)(aTHX_ a,b,c,d,e) -#define Perl_pv_display DPPP_(my_pv_display) - -#if defined(NEED_pv_display) || defined(NEED_pv_display_GLOBAL) - -char * -DPPP_(my_pv_display)(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) -{ - pv_pretty(dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP); - if (len > cur && pv[cur] == '\0') - sv_catpvs(dsv, "\\0"); - return SvPVX(dsv); -} - -#endif -#endif - -#endif /* _P_P_PORTABILITY_H_ */ - -/* End of File ppport.h */ diff -Nru liblist-moreutils-perl-0.416/README.md liblist-moreutils-perl-0.430/README.md --- liblist-moreutils-perl-0.416/README.md 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/README.md 2020-10-02 06:22:44.000000000 +0000 @@ -27,7 +27,7 @@ # DESCRIPTION -__List::MoreUtils__ provides some trivial but commonly needed functionality on +**List::MoreUtils** provides some trivial but commonly needed functionality on lists which is not going to go into [List::Util](https://metacpan.org/pod/List::Util). All of the below functions are implementable in only a couple of lines of Perl @@ -129,7 +129,7 @@ Thus, `all_u(@list)` is equivalent to `@list ? all(@list) : undef`. -__Note__: because Perl treats `undef` as false, you must check the return value +**Note**: because Perl treats `undef` as false, you must check the return value of `all_u` with `defined` or you will get the opposite result of what you expect. @@ -162,7 +162,7 @@ Thus, `none_u(@list)` is equivalent to `@list ? none(@list) : undef`. -__Note__: because Perl treats `undef` as false, you must check the return value +**Note**: because Perl treats `undef` as false, you must check the return value of `none_u` with `defined` or you will get the opposite result of what you expect. @@ -181,6 +181,24 @@ Thus, `notall_u(@list)` is equivalent to `@list ? notall(@list) : undef`. +### one BLOCK LIST + +### one\_u BLOCK LIST + +Returns a true value if precisely one item in LIST meets the criterion +given through BLOCK. Sets `$_` for each item in LIST in turn: + + print "Precisely one value defined" + if one { defined($_) } @list; + +Returns false otherwise. + +For an empty LIST, `one` returns false and `one_u` returns `undef`. + +The expression `one BLOCK LIST` is almost equivalent to +`1 == true BLOCK LIST`, except for short-cutting. +Evaluation of BLOCK will immediately stop at the second true value. + ## Transformation ### apply BLOCK LIST @@ -259,19 +277,115 @@ `zip` is an alias for `mesh`. +### zip6 + +### zip\_unflatten + +Returns a list of arrays consisting of the first elements of each array, +then the second, then the third, etc, until all arrays are exhausted. + + @x = qw/a b c d/; + @y = qw/1 2 3 4/; + @z = zip6 @x, @y; # returns [a, 1], [b, 2], [c, 3], [d, 4] + + @a = ('x'); + @b = ('1', '2'); + @c = qw/zip zap zot/; + @d = zip6 @a, @b, @c; # [x, 1, zip], [undef, 2, zap], [undef, undef, zot] + +`zip_unflatten` is an alias for `zip6`. + +### listcmp ARRAY0 ARRAY1 \[ ARRAY2 ... \] + +Returns an associative list of elements and every _id_ of the list it +was found in. Allowes easy implementation of @a & @b, @a | @b, @a ^ @b and +so on. +Undefined entries in any given array are skipped. + + my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen); + my @b = qw(two three five seven eleven thirteen seventeen); + my @c = qw(one one two three five eight thirteen twentyone); + my %cmp = listcmp @a, @b, @c; # returns (one => [0, 2], two => [0, 1, 2], three => [0, 1, 2], four => [0], ...) + + my @seq = (1, 2, 3); + my @prim = (undef, 2, 3, 5); + my @fib = (1, 1, 2); + my $cmp = listcmp @seq, @prim, @fib; + # returns { 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] } + +### arrayify LIST\[,LIST\[,LIST...\]\] + +Returns a list costisting of each element of given arrays. Recursive arrays +are flattened, too. + + @a = (1, [[2], 3], 4, [5], 6, [7], 8, 9); + @l = arrayify @a; # returns 1, 2, 3, 4, 5, 6, 7, 8, 9 + ### uniq LIST ### distinct LIST -Returns a new list by stripping duplicate values in LIST. The order of -elements in the returned list is the same as in LIST. In scalar context, -returns the number of unique elements in LIST. +Returns a new list by stripping duplicate values in LIST by comparing +the values as hash keys, except that undef is considered separate from ''. +The order of elements in the returned list is the same as in LIST. In +scalar context, returns the number of unique elements in LIST. my @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4 my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5 + # returns "Mike", "Michael", "Richard", "Rick" + my @n = distinct "Mike", "Michael", "Richard", "Rick", "Michael", "Rick" + # returns "A8", "", undef, "A5", "S1" + my @s = distinct "A8", "", undef, "A5", "S1", "A5", "A8" + # returns "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C" + my @w = uniq "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C", "Giulietta", "Giulia" `distinct` is an alias for `uniq`. +**RT#49800** can be used to give feedback about this behavior. + +### singleton LIST + +Returns a new list by stripping values in LIST occurring more than once by +comparing the values as hash keys, except that undef is considered separate +from ''. The order of elements in the returned list is the same as in LIST. +In scalar context, returns the number of elements occurring only once in LIST. + + my @x = singleton 1,1,2,2,3,4,5 # returns 3 4 5 + +### duplicates LIST + +Returns a new list by stripping values in LIST occuring less than twice by +comparing the values as hash keys, except that undef is considered separate +from ''. The order of elements in the returned list is the same as in LIST. +In scalar context, returns the number of elements occurring only once in LIST. + + my @y = duplicates 1,1,2,4,7,2,3,4,6,9; #returns 1,2,4 + +### frequency LIST + +Returns an associative list of distinct values and the corresponding frequency. + + my @f = frequency values %radio_nrw; # returns ( + # 'Deutschlandfunk (DLF)' => 9, 'WDR 3' => 10, + # 'WDR 4' => 11, 'WDR 5' => 14, 'WDR Eins Live' => 14, + # 'Deutschlandradio Kultur' => 8,...) + +### occurrences LIST + +Returns a new list of frequencies and the corresponding values from LIST. + + my @o = occurrences ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + # @o = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]); + +### mode LIST + +Returns the modal value of LIST. In scalar context, just the modal value +is returned, in list context all probes occuring _modal_ times are returned, +too. + + my @m = mode ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + # @m = (7, 4, 8) - bimodal LIST + ## Partitioning ### after BLOCK LIST @@ -322,6 +436,14 @@ my $i = 0; my @part = part { $idx[$++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8] +### samples COUNT LIST + +Returns a new list containing COUNT random samples from LIST. Is similar to +["shuffle" in List::Util](https://metacpan.org/pod/List::Util#shuffle), but stops after COUNT. + + @r = samples 10, 1..10; # same as shuffle + @r2 = samples 5, 1..10; # gives 5 values from 1..10; + ## Iteration ### each\_array ARRAY1 ARRAY2 ... @@ -369,15 +491,6 @@ ## Searching -### bsearch BLOCK LIST - -Performs a binary search on LIST which must be a sorted list of values. BLOCK -must return a negative value if the current element (stored in `$_`) is smaller, -a positive value if it is bigger and zero if it matches. - -Returns a boolean value in scalar context. In list context, it returns the element -if it was found, otherwise the empty list. - ### firstval BLOCK LIST ### first\_value BLOCK LIST @@ -388,6 +501,16 @@ `first_value` is an alias for `firstval`. +### onlyval BLOCK LIST + +### only\_value BLOCK LIST + +Returns the only element in LIST for which BLOCK evaluates to true. Sets +`$_` for each item in LIST in turn. Returns `undef` if no such element +has been found. + +`only_value` is an alias for `onlyval`. + ### lastval BLOCK LIST ### last\_value BLOCK LIST @@ -398,6 +521,36 @@ `last_value` is an alias for `lastval`. +### firstres BLOCK LIST + +### first\_result BLOCK LIST + +Returns the result of BLOCK for the first element in LIST for which BLOCK +evaluates to true. Each element of LIST is set to `$_` in turn. Returns +`undef` if no such element has been found. + +`first_result` is an alias for `firstres`. + +### onlyres BLOCK LIST + +### only\_result BLOCK LIST + +Returns the result of BLOCK for the first element in LIST for which BLOCK +evaluates to true. Sets `$_` for each item in LIST in turn. Returns +`undef` if no such element has been found. + +`only_result` is an alias for `onlyres`. + +### lastres BLOCK LIST + +### last\_result BLOCK LIST + +Returns the result of BLOCK for the last element in LIST for which BLOCK +evaluates to true. Each element of LIST is set to `$_` in turn. Returns +`undef` if no such element has been found. + +`last_result` is an alias for `lastres`. + ### indexes BLOCK LIST Evaluates BLOCK for each element in LIST (assigned to `$_`) and returns a list @@ -417,12 +570,28 @@ printf "item with index %i in list is 4", firstidx { $_ == 4 } @list; __END__ item with index 1 in list is 4 - Returns `-1` if no such item could be found. `first_index` is an alias for `firstidx`. +### onlyidx BLOCK LIST + +### only\_index BLOCK LIST + +Returns the index of the only element in LIST for which the criterion +in BLOCK is true. Sets `$_` for each item in LIST in turn: + + my @list = (1, 3, 4, 3, 2, 4); + printf "uniqe index of item 2 in list is %i", onlyidx { $_ == 2 } @list; + __END__ + unique index of item 2 in list is 4 + +Returns `-1` if either no such item or more than one of these +has been found. + +`only_index` is an alias for `onlyidx`. + ### lastidx BLOCK LIST ### last\_index BLOCK LIST @@ -470,6 +639,149 @@ Similar to sort\_by but compares its key values numerically. +### qsort BLOCK ARRAY + +This sorts the given array **in place** using the given compare code. Except for +tiny compare code like `$a <=> $b`, qsort is much faster than Perl's `sort` +depending on the version. + +Compared 5.8 and 5.26: + + my @rl; + for(my $i = 0; $i < 1E6; ++$i) { push @rl, rand(1E5) } + my $idx; + + sub ext_cmp { $_[0] <=> $_[1] } + + cmpthese( -60, { + 'qsort' => sub { + my @qrl = @rl; + qsort { ext_cmp($a, $b) } @qrl; + $idx = bsearchidx { ext_cmp($_, $rl[0]) } @qrl + }, + 'reverse qsort' => sub { + my @qrl = @rl; + qsort { ext_cmp($b, $a) } @qrl; + $idx = bsearchidx { ext_cmp($rl[0], $_) } @qrl + }, + 'sort' => sub { + my @srl = @rl; + @srl = sort { ext_cmp($a, $b) } @srl; + $idx = bsearchidx { ext_cmp($_, $rl[0]) } @srl + }, + 'reverse sort' => sub { + my @srl = @rl; + @srl = sort { ext_cmp($b, $a) } @srl; + $idx = bsearchidx { ext_cmp($rl[0], $_) } @srl + }, + }); + +5.8 results + + s/iter reverse sort sort reverse qsort qsort + reverse sort 6.21 -- -0% -8% -10% + sort 6.19 0% -- -7% -10% + reverse qsort 5.73 8% 8% -- -2% + qsort 5.60 11% 11% 2% -- + +5.26 results + + s/iter reverse sort sort reverse qsort qsort + reverse sort 4.54 -- -0% -96% -96% + sort 4.52 0% -- -96% -96% + reverse qsort 0.203 2139% 2131% -- -19% + qsort 0.164 2666% 2656% 24% -- + +Use it where external data sources might have to be compared (think of [Unix::Statgrab](https://metacpan.org/pod/Unix::Statgrab) +"tables"). + +`qsort` is available from List::MoreUtils::XS only. It's insane to maintain +a wrapper around Perl's sort nor having a pure Perl implementation. One could +create a flip-book in same speed as PP runs a qsort. + +## Searching in sorted Lists + +### bsearch BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in `$_`) is smaller, +a positive value if it is bigger and zero if it matches. + +Returns a boolean value in scalar context. In list context, it returns the element +if it was found, otherwise the empty list. + +### bsearchidx BLOCK LIST + +### bsearch\_index BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in `$_`) is smaller, +a positive value if it is bigger and zero if it matches. + +Returns the index of found element, otherwise `-1`. + +`bsearch_index` is an alias for `bsearchidx`. + +### lower\_bound BLOCK LIST + +Returns the index of the first element in LIST which does not compare +_less than val_. Technically it's the first element in LIST which does +not return a value below zero when passed to BLOCK. + + @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); + $lb = lower_bound { $_ <=> 2 } @ids; # returns 2 + $lb = lower_bound { $_ <=> 4 } @ids; # returns 10 + +lower\_bound has a complexity of O(log n). + +### upper\_bound BLOCK LIST + +Returns the index of the first element in LIST which does not compare +_greater than val_. Technically it's the first element in LIST which does +not return a value below or equal to zero when passed to BLOCK. + + @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); + $lb = upper_bound { $_ <=> 2 } @ids; # returns 4 + $lb = upper_bound { $_ <=> 4 } @ids; # returns 14 + +upper\_bound has a complexity of O(log n). + +### equal\_range BLOCK LIST + +Returns a pair of indices containing the lower\_bound and the upper\_bound. + +## Operations on sorted Lists + +### binsert BLOCK ITEM LIST + +### bsearch\_insert BLOCK ITEM LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in `$_`) is smaller, +a positive value if it is bigger and zero if it matches. + +ITEM is inserted at the index where the ITEM should be placed (based on above +search). That means, it's inserted before the next bigger element. + + @l = (2,3,5,7); + binsert { $_ <=> 4 } 4, @l; # @l = (2,3,4,5,7) + binsert { $_ <=> 6 } 42, @l; # @l = (2,3,4,42,7) + +You take care that the inserted element matches the compare result. + +### bremove BLOCK LIST + +### bsearch\_remove BLOCK LIST + +Performs a binary search on LIST which must be a sorted list of values. BLOCK +must return a negative value if the current element (stored in `$_`) is smaller, +a positive value if it is bigger and zero if it matches. + +The item at the found position is removed and returned. + + @l = (2,3,4,5,7); + bremove { $_ <=> 4 }, @l; # @l = (2,3,5,7); + ## Counting and calculation ### true BLOCK LIST @@ -486,6 +798,37 @@ printf "%i item(s) are not defined", false { defined($_) } @list; +### reduce\_0 BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +`$a` contains the progressional result and is initialized with 0. +`$b` contains the current processed element of LIST and `$_` contains the +index of the element in `$b`. + +The idea behind reduce\_0 is **summation** (addition of a sequence of numbers). + +### reduce\_1 BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +`$a` contains the progressional result and is initialized with 1. +`$b` contains the current processed element of LIST and `$_` contains the +index of the element in `$b`. + +The idea behind reduce\_1 is product of a sequence of numbers. + +### reduce\_u BLOCK LIST + +Reduce LIST by calling BLOCK in scalar context for each element of LIST. +`$a` contains the progressional result and is initialized with 1. +`$b` contains the current processed element of LIST and `$_` contains the +index of the element in `$b`. + +This function has been added if one might need the extra of the index +value but need an individual initialization. + +**Use with caution**: In most cases ["reduce" in List::Util](https://metacpan.org/pod/List::Util#reduce) will do the +job better. + ### minmax LIST Calculates the minimum and maximum of LIST and returns a two element list with @@ -502,6 +845,14 @@ fairly big in order for `minmax` to win over a naive implementation. This limitation does not apply to the XS version. +### minmaxstr LIST + +Computes the minimum and maximum of LIST using string compare and returns a +two element list with the first element being the minimum and the second the +maximum. Returns the empty list if LIST was empty. + +The implementation is similar to `minmax`. + # ENVIRONMENT When `LIST_MOREUTILS_PP` is set, the module will always use the pure-Perl @@ -523,6 +874,14 @@ run-time dependencies will be added only if they deliver substantial benefit. +# CONTRIBUTING + +While contributions are appreciated, a contribution should not cause more +effort for the maintainer than the contribution itself saves (see +[Open Source Contribution Etiquette](http://tirania.org/blog/archive/2010/Dec-31.html)). + +To get more familiar where help could be needed - see [List::MoreUtils::Contributing](https://metacpan.org/pod/List::MoreUtils::Contributing). + # BUGS There is a problem with a bug in 5.6.x perls. It is a syntax error to write @@ -561,7 +920,7 @@ - RT: CPAN's request tracker - [http://rt.cpan.org/NoAuth/Bugs.html?Dist=List-MoreUtils](http://rt.cpan.org/NoAuth/Bugs.html?Dist=List-MoreUtils) + [https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils](https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils) - AnnoCPAN: Annotated CPAN documentation @@ -569,7 +928,11 @@ - CPAN Ratings - [http://cpanratings.perl.org/l/List-MoreUtils](http://cpanratings.perl.org/l/List-MoreUtils) + [http://cpanratings.perl.org/dist/List-MoreUtils](http://cpanratings.perl.org/dist/List-MoreUtils) + +- MetaCPAN + + [https://metacpan.org/release/List-MoreUtils](https://metacpan.org/release/List-MoreUtils) - CPAN Search @@ -672,16 +1035,6 @@ A pile of requests from other people is still pending further processing in my mailbox. This includes: -- List::Util export pass-through - - Allow __List::MoreUtils__ to pass-through the regular [List::Util](https://metacpan.org/pod/List::Util) - functions to end users only need to `use` the one module. - -- uniq\_by(&@) - - Use code-reference to extract a key based on which the uniqueness is - determined. Suggested by Aaron Crane. - - delete\_index - random\_item - random\_item\_delete\_index @@ -703,11 +1056,11 @@ # AUTHOR -Jens Rehsack +Jens Rehsack <rehsack AT cpan.org> -Adam Kennedy +Adam Kennedy <adamk@cpan.org> -Tassilo von Parseval +Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de> # COPYRIGHT AND LICENSE @@ -715,8 +1068,20 @@ Copyright 2004 - 2010 by Tassilo von Parseval -Copyright 2013 - 2015 by Jens Rehsack +Copyright 2013 - 2017 by Jens Rehsack -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.8.4 or, -at your option, any later version of Perl 5 you may have available. +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. diff -Nru liblist-moreutils-perl-0.416/t/inline/after_incl.pm liblist-moreutils-perl-0.430/t/inline/after_incl.pm --- liblist-moreutils-perl-0.416/t/inline/after_incl.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/after_incl.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,21 @@ + +use Test::More; +use Test::LMU; + +my @x = after_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [5, 6, 7, 8, 9], "after 5, included"); + +@x = after_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after_incl { /b/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "after /b/, included"); + +leak_free_ok( + after_incl => sub { + @x = after_incl { /z/ } qw{bar baz foo}; + } +); +is_dying('after_incl without sub' => sub { &after_incl(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/after.pm liblist-moreutils-perl-0.430/t/inline/after.pm --- liblist-moreutils-perl-0.416/t/inline/after.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/after.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,24 @@ + +use Test::More; +use Test::LMU; + +my @x = after { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [6, 7, 8, 9], "after 5"); + +@x = after { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after { /b/ } qw{bar baz foo }; +is_deeply(\@x, [qw{baz foo }], "after /b/"); + +leak_free_ok( + after => sub { + @x = after { /z/ } qw{bar baz foo}; + } +); +is_dying('after without sub' => sub { &after(42, 4711); }); + +@x = (1, after { /foo/ } qw(abc def)); +is_deeply(\@x, [1], "check XS implementation doesn't mess up stack"); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/all.pm liblist-moreutils-perl-0.430/t/inline/all.pm --- liblist-moreutils-perl-0.416/t/inline/all.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/all.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all { defined } @list); +is_true(all { $_ > 0 } @list); +is_false(all { $_ < 5000 } @list); +is_true(all {}); + +leak_free_ok( + all => sub { + my $ok = all { $_ == 5000 } @list; + my $ok2 = all { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all without sub' => sub { &all(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/all_u.pm liblist-moreutils-perl-0.430/t/inline/all_u.pm --- liblist-moreutils-perl-0.416/t/inline/all_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/all_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all_u { defined } @list); +is_true(all_u { $_ > 0 } @list); +is_false(all_u { $_ < 5000 } @list); +is_undef(all_u {}); + +leak_free_ok( + all_u => sub { + my $ok = all_u { $_ == 5000 } @list; + my $ok2 = all_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all_u without sub' => sub { &all_u(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/any.pm liblist-moreutils-perl-0.430/t/inline/any.pm --- liblist-moreutils-perl-0.416/t/inline/any.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/any.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,30 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any { $_ == 5000 } @list); +is_true(any { $_ == 5000 } 1 .. 10000); +is_true(any { defined } @list); +is_false(any { not defined } @list); +is_true(any { not defined } undef); +is_false(any {}); + +leak_free_ok( + any => sub { + my $ok = any { $_ == 5000 } @list; + my $ok2 = any { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any { die } 1; + }; + } +); +is_dying('any without sub' => sub { &any(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/any_u.pm liblist-moreutils-perl-0.430/t/inline/any_u.pm --- liblist-moreutils-perl-0.416/t/inline/any_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/any_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,30 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any_u { $_ == 5000 } @list); +is_true(any_u { $_ == 5000 } 1 .. 10000); +is_true(any_u { defined } @list); +is_false(any_u { not defined } @list); +is_true(any_u { not defined } undef); +is_undef(any_u {}); + +leak_free_ok( + any_u => sub { + my $ok = any_u { $_ == 5000 } @list; + my $ok2 = any_u { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any_u { die } 1; + }; + } +); +is_dying('any_u without sub' => sub { &any_u(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/apply.pm liblist-moreutils-perl-0.430/t/inline/apply.pm --- liblist-moreutils-perl-0.416/t/inline/apply.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/apply.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,69 @@ + +use Test::More; +use Test::LMU; + +# Test the null case +my $null_scalar = apply {}; +is($null_scalar, undef, 'apply(null) returns undef'); + +my @null_list = apply {}; +is_deeply(\@null_list, [], 'apply(null) returns null list'); + +# Normal cases +my @list = (0 .. 9); +my @list1 = apply { $_++ } @list; +is_deeply(\@list, [0 .. 9], "original numbers untouched"); +is_deeply(\@list1, [1 .. 10], "returned numbers increased"); +@list = (" foo ", " bar ", " ", "foobar"); +@list1 = apply { s/^\s+|\s+$//g } @list; +is_deeply(\@list, [" foo ", " bar ", " ", "foobar"], "original strings untouched"); +is_deeply(\@list1, ["foo", "bar", "", "foobar"], "returned strings stripped"); +my $item = apply { s/^\s+|\s+$//g } @list; +is($item, "foobar"); + +# RT 96596 +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + eval { my @a = \&apply(1, 2); }; + my $err = $@; + like($err, qr/\QList::MoreUtils::XS::apply(code, ...)\E/, "apply must be reasonable invoked"); +} + +# RT 38630 +SCOPE: +{ + # wrong results from apply() [XS] + @list = (1 .. 4); + @list1 = apply { grow_stack(); $_ = 5; } @list; + is_deeply(\@list, [1 .. 4]); + is_deeply(\@list1, [(5) x 4]); +} + +leak_free_ok( + apply => sub { + @list = (1 .. 4); + @list1 = apply + { + grow_stack(); + $_ = 5; + } + @list; + } +); + +SCOPE: +{ + leak_free_ok( + 'dying callback during apply' => sub { + my @l = (1 .. 4); + eval { + my @l1 = apply { $_ % 2 or die "Even!"; $_ %= 2; } @l; + }; + } + ); +} + +is_dying('apply without sub' => sub { &apply(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/arrayify.pm liblist-moreutils-perl-0.430/t/inline/arrayify.pm --- liblist-moreutils-perl-0.416/t/inline/arrayify.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/arrayify.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,114 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]], 18); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 18], "linear flattened int mix i"); +} + +SCOPE: +{ + my @in = (1 .. 4, [[5 .. 11]], 12, [[13 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened int mix ii"); +} + +SCOPE: +{ + # typical structure when parsing XML using XML::Hash::XS + my %src = ( + root => { + foo_list => {foo_elem => {attr => 42}}, + bar_list => {bar_elem => [{hummel => 2}, {hummel => 3}, {hummel => 5}]} + } + ); + my @foo_elems = arrayify $src{root}->{foo_list}->{foo_elem}; + is_deeply(\@foo_elems, [{attr => 42}], "arrayified struct with one element"); + my @bar_elems = arrayify $src{root}->{bar_list}->{bar_elem}; + is_deeply(\@bar_elems, [{hummel => 2}, {hummel => 3}, {hummel => 5}], "arrayified struct with three elements"); +} + +SCOPE: +{ + my @in; + tie @in, "Tie::StdArray"; + @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mix"); +} + +SCOPE: +{ + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mixture"); +} + +SCOPE: +{ + my @in = (qw(av_make av_undef av_clear), [qw(av_push av_pop)], qw(av_fetch av_store), [['av_shift'], ['av_unshift']]); + my @out = arrayify @in; + is_deeply( + \@out, + [qw(av_make av_undef av_clear av_push av_pop av_fetch av_store av_shift av_unshift)], + "linear flattened string mix i" + ); +} + +leak_free_ok( + arrayify => sub { + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + }, + 'arrayify magic' => sub { + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + } +); + +SKIP: +{ + leak_free_ok( + 'arrayify with exception in overloading stringify at begin' => sub { + my @in = ( + DieOnStringify->new, qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']] + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + }, + ); + leak_free_ok( + 'arrayify with exception in overloading stringify at end' => sub { + my @in = ( + qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']], + DieOnStringify->new + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + } + ); +} + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/before_incl.pm liblist-moreutils-perl-0.430/t/inline/before_incl.pm --- liblist-moreutils-perl-0.416/t/inline/before_incl.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/before_incl.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,21 @@ + +use Test::More; +use Test::LMU; + +my @x = before_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4, 5], "before 5, included"); + +@x = before_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [qw{bar baz}]); + +@x = before_incl { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "before /f/, included"); + +leak_free_ok( + before_incl => sub { + @x = before_incl { /z/ } qw{ bar baz foo }; + } +); +is_dying('before_incl without sub' => sub { &before_incl(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/before.pm liblist-moreutils-perl-0.430/t/inline/before.pm --- liblist-moreutils-perl-0.416/t/inline/before.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/before.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,21 @@ + +use Test::More; +use Test::LMU; + +my @x = before { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4], "before 5"); + +@x = before { /b/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = before { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz}], "before /f/"); + +leak_free_ok( + before => sub { + @x = before { /f/ } qw{ bar baz foo }; + } +); +is_dying('before without sub' => sub { &before(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/binsert.pm liblist-moreutils-perl-0.430/t/inline/binsert.pm --- liblist-moreutils-perl-0.416/t/inline/binsert.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/binsert.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,137 @@ + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @list = (); + is(0, (binsert { $_ cmp "Hello" } "Hello", @list), "Inserting into empty list"); + is(1, (binsert { $_ cmp "world" } "world", @list), "Inserting into one-item list"); +} + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (@odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements into even list succeeded"); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements reversely into even list succeeded"); + +@in = @odd; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements into odd list succeeded"); + +@in = @odd; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements reversely into odd list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements into even list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements reversely into even list succeeded"); + +leak_free_ok( + 'binsert random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert existing random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = 2 * (int(rand(100)) + 1); + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert odd into even' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into odd' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert odd into odd' => sub { + my @list = @odd; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into even' => sub { + my @list = @even; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert random with stack-growing' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + }, + 'binsert odd with stack-growing' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, + 'binsert even with stack-growing' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert with stack-growing and exception' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + eval { + binsert { grow_stack(); $_ <=> $elem or die "Goal!"; $_ <=> $elem } $elem, @list; + }; + } +); + +is_dying('binsert without sub' => sub { &binsert(42, @even); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/bremove.pm liblist-moreutils-perl-0.430/t/inline/bremove.pm --- liblist-moreutils-perl-0.416/t/inline/bremove.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/bremove.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,108 @@ + +use Test::More; +use Test::LMU; + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@expected = @even; +@in = mesh @odd, @even; +foreach my $v (@odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements reversely succeeded"); + +@expected = @odd; +@in = mesh @odd, @even; +foreach my $v (@even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements reversely succeeded"); + +# test from shawnlaffan from GH issue #2 of List-MoreUtils-XS +SCOPE: +{ + my @list = ('somestring'); + my $target = $list[0]; + is($target, (bremove { $_ cmp $target } @list), 'removed from single item list'); +} + +leak_free_ok( + 'bremove first' => sub { + my @list = (1 .. 100); + my $v = $list[0]; + bremove { $_ <=> $v } @list; + }, + 'bremove last' => sub { + my @list = (1 .. 100); + my $v = $list[-1]; + bremove { $_ <=> $v } @list; + }, + 'bremove middle' => sub { + my @list = (1 .. 100); + my $v = $list[int($#list / 2)]; + bremove { $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove last with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove middle with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + bremove { grow_stack(); $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove last with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove middle with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, +); +is_dying('bremove without sub' => sub { &bremove(42, @even); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/bsearchidx.pm liblist-moreutils-perl-0.430/t/inline/bsearchidx.pm --- liblist-moreutils-perl-0.416/t/inline/bsearchidx.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/bsearchidx.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,41 @@ + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $i (0 .. $#in) +{ + is($i, bsearchidx { $_ - $in[$i] } @list); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearchidx { $_ - $elem } @list; + is(-1, $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + bsearchidx { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + bsearchidx { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + bsearchidx { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearchidx without sub' => sub { &bsearchidx(42, (1 .. 100)); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/bsearch.pm liblist-moreutils-perl-0.430/t/inline/bsearch.pm --- liblist-moreutils-perl-0.416/t/inline/bsearch.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/bsearch.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,46 @@ + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $elem (@in) +{ + ok(scalar bsearch { $_ - $elem } @list); +} +for my $elem (@in) +{ + my ($e) = bsearch { $_ - $elem } @list; + ok($e == $elem); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearch { $_ - $elem } @list; + ok(!defined $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + scalar bsearch { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + scalar bsearch { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + scalar bsearch { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearch without sub' => sub { &bsearch(42, (1 .. 100)); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/duplicates.pm liblist-moreutils-perl-0.430/t/inline/duplicates.pm --- liblist-moreutils-perl-0.416/t/inline/duplicates.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/duplicates.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,110 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my $fd = freeze(\@d); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@d], "duplicates of numbers/strings mixture"); + is($fd, freeze(\@d), "frozen duplicates of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + is($fu, $fd); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is_deeply(\@u, [@d], "duplicates of tied array of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + @a = (@u, @d); + $fa = freeze(\@a); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of tied array of numbers/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my @dfoo = ('b', '', undef); + is_deeply([duplicates @foo], \@dfoo, "two undef's are supported correctly by duplicates"); + @foo = ('a', undef, 'b', '', 'b', 'c', ''); + @dfoo = ('b', ''); + is_deeply([duplicates @foo], \@dfoo, 'one undef is ignored correctly by duplicates'); + is((scalar duplicates @foo), scalar @dfoo, 'scalar one undef is ignored correctly by duplicates'); +} + +leak_free_ok( + duplicates => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = duplicates @a; + scalar duplicates @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'duplicates with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my @u = duplicates @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $u = duplicates 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; + diff -Nru liblist-moreutils-perl-0.416/t/inline/each_array.pm liblist-moreutils-perl-0.430/t/inline/each_array.pm --- liblist-moreutils-perl-0.416/t/inline/each_array.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/each_array.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,127 @@ + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw{ a 2 -1 x }; + my $it = each_array @a, @b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); + + # This used to give "semi-panic: attempt to dup freed string" + # See: + my $ea = each_arrayref([1 .. 26], ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@b, ['A' .. 'Z']); + + # And this even used to dump core + my @nums = 1 .. 26; + $ea = each_arrayref(\@nums, ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@a, \@nums); + is_deeply(\@b, ['A' .. 'Z']); +} + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw/a 2 -1 x/; + + my $it = each_arrayref \@a, \@b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); +} + +# Note that the leak_free_ok tests for each_array and each_arrayref +# should not be run until either of them has been called at least once +# in the current perl. That's because calling them the first time +# causes the runtime to allocate some memory used for the OO structures +# that their implementation uses internally. +leak_free_ok( + each_array => sub { + my @a = (1); + my $it = each_array @a; + while (my ($a) = $it->()) + { + } + } +); +leak_free_ok( + each_arrayref => sub { + my @a = (1); + my $it = each_arrayref \@a; + while (my ($a) = $it->()) + { + } + } +); +is_dying('each_array without sub' => sub { &each_array(42, 4711); }); +is_dying('each_arrayref without sub' => sub { &each_arrayref(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/equal_range.pm liblist-moreutils-perl-0.430/t/inline/equal_range.pm --- liblist-moreutils-perl-0.416/t/inline/equal_range.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/equal_range.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,37 @@ + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is_deeply([0, 0], [equal_range { $_ <=> 0 } @list], "equal range 0"); +is_deeply([0, 2], [equal_range { $_ <=> 1 } @list], "equal range 1"); +is_deeply([2, 4], [equal_range { $_ <=> 2 } @list], "equal range 2"); +is_deeply([10, 14], [equal_range { $_ <=> 4 } @list], "equal range 4"); +is_deeply([(scalar @list) x 2], [equal_range { $_ <=> 19 } @list], "equal range 19"); + +my @in = @list = 1 .. 100; +leak_free_ok( + equal_range => sub { + my $elem = int(rand(101)) + 1; + equal_range { $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing' => sub { + my $elem = int(rand(101)); + equal_range { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing and exception' => sub { + my $elem = int(rand(101)); + eval { + equal_range { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('equal_range without sub' => sub { &equal_range(42, (1 .. 100)); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/false.pm liblist-moreutils-perl-0.430/t/inline/false.pm --- liblist-moreutils-perl-0.416/t/inline/false.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/false.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,25 @@ + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = false {}; +my @null_list = false {}; +is($null_scalar, 0, 'false(null) returns undef'); +is_deeply(\@null_list, [0], 'false(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, false { not defined } @list); +is(0, false { defined } @list); +is(1, false { $_ > 1 } @list); + +leak_free_ok( + false => sub { + my $n = false { $_ == 5000 } @list; + my $n2 = false { $_ == 5000 } 1 .. 10000; + } +); +is_dying('false without sub' => sub { &false(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/firstidx.pm liblist-moreutils-perl-0.430/t/inline/firstidx.pm --- liblist-moreutils-perl-0.416/t/inline/firstidx.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/firstidx.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,32 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_index = __PACKAGE__->can("firstidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(4999, (firstidx { $_ >= 5000 } @list), "firstidx"); +is(-1, (firstidx { not defined } @list), "invalid firstidx"); +is(0, (firstidx { defined } @list), "real firstidx"); +is(-1, (firstidx {}), "empty firstidx"); + +SKIP: +{ + # Test the alias + is(4999, first_index { $_ >= 5000 } @list); + is(-1, first_index { not defined } @list); + is(0, first_index { defined } @list); + is(-1, first_index {}); +} + +leak_free_ok( + firstidx => sub { + my $i = firstidx { $_ >= 5000 } @list; + my $i2 = firstidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('firstidx without sub' => sub { &firstidx(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/firstres.pm liblist-moreutils-perl-0.430/t/inline/firstres.pm --- liblist-moreutils-perl-0.416/t/inline/firstres.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/firstres.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,27 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_result = __PACKAGE__->can("firstres"); +} + +use Test::More; +use Test::LMU; + +my $x = firstres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = firstres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = first_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = first_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstres => sub { + $x = firstres { $_ > 5 } 4 .. 9; + } +); +is_dying('firstres without sub' => sub { &firstres(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/firstval.pm liblist-moreutils-perl-0.430/t/inline/firstval.pm --- liblist-moreutils-perl-0.416/t/inline/firstval.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/firstval.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,28 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_value = __PACKAGE__->can("firstval"); +} + +use Test::More; +use Test::LMU; + +my $x = firstval { $_ > 5 } 4 .. 9; +is($x, 6); +$x = firstval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(firstval { $_ > 5 }); + +# Test aliases +$x = first_value { $_ > 5 } 4 .. 9; +is($x, 6); +$x = first_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstval => sub { + $x = firstval { $_ > 5 } 4 .. 9; + } +); +is_dying('firstval without sub' => sub { &firstval(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/frequency.pm liblist-moreutils-perl-0.430/t/inline/frequency.pm --- liblist-moreutils-perl-0.416/t/inline/frequency.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/frequency.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,117 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves numbers untouched"); + is_deeply(\%f, {%e}, "frequency of numbers"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G:SCALAR leaves numbers untouched"); + is(scalar keys %e, $f, "scalar result of frequency of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves strings untouched"); + is_deeply(\%f, {%e}, "frequency of strings"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves strings untouched"); + is(scalar keys %e, $f, "scalar result of frequency of strings"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of number/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves tied array of number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of tied array of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves tied array of number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of tied array of number/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my %e = ( + a => 1, + b => 2, + '' => 2, + c => 1 + ); + my @f = frequency @foo; + my $seen_undef; + ref $f[-2] and ref $f[-2] eq "SCALAR" and not defined ${$f[-2]} and (undef, $seen_undef) = splice @f, -2, 2, (); + my %f = @f; + is_deeply(\%f, \%e, "stuff around undef's is supported correctly by frequency"); + is($seen_undef, 2, "two undef's are supported correctly by frequency"); +} + +leak_free_ok( + frequency => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my %f = frequency @a; + }, + 'scalar frequency' => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $f = frequency @a; + } +); + +leak_free_ok( + 'frequency with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my %f = frequency @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $f = frequency 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/Import.pm liblist-moreutils-perl-0.430/t/inline/Import.pm --- liblist-moreutils-perl-0.416/t/inline/Import.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/Import.pm 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,81 @@ + +use Test::More; +use Test::LMU; + +my @pure_funcs = qw(any all none notall one + any_u all_u none_u notall_u one_u + true false + insert_after insert_after_string + apply indexes + after after_incl before before_incl + firstidx lastidx onlyidx + firstval lastval onlyval + firstres lastres onlyres + singleton + each_array each_arrayref + pairwise natatime + mesh uniq + minmax part + bsearch bsearchidx); +my @v0_33 = qw(sort_by nsort_by); +my %alias_list = ( + v0_22 => { + first_index => "firstidx", + last_index => "lastidx", + first_value => "firstval", + last_value => "lastval", + zip => "mesh", + }, + v0_33 => { + distinct => "uniq", + }, + v0_400 => { + first_result => "firstres", + only_index => "onlyidx", + only_value => "onlyval", + only_result => "onlyres", + last_result => "lastres", + bsearch_index => "bsearchidx", + }, +); + +can_ok(__PACKAGE__, $_) for @pure_funcs; + +SKIP: +{ + $INC{'List/MoreUtils.pm'} or skip "List::MoreUtils::XS doesn't alias", 1; + can_ok(__PACKAGE__, $_) for @v0_33; + can_ok(__PACKAGE__, $_) for map { keys %$_ } values %alias_list; +} + +done_testing; + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. + +=cut diff -Nru liblist-moreutils-perl-0.416/t/inline/indexes.pm liblist-moreutils-perl-0.430/t/inline/indexes.pm --- liblist-moreutils-perl-0.416/t/inline/indexes.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/indexes.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,66 @@ + +use Test::More; +use Test::LMU; + +my @x = indexes { $_ > 5 } (4 .. 9); +is_deeply(\@x, [2 .. 5], "indexes > 5 ..."); +@x = indexes { $_ > 5 } (1 .. 4); +is_deeply(\@x, [], 'Got the null list'); + +my ($lr, @s, @n, @o, @e); +leak_free_ok( + indexes => sub { + $lr = 1; + @s = indexes { $_ > 5 } (4 .. 9); + @n = indexes { $_ > 5 } (1 .. 5); + @o = indexes { $_ & 1 } (10 .. 15); + @e = indexes { !($_ & 1) } (10 .. 15); + } +); +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +@n = map { $_ + 1 } @o = (0 .. 9); +@x = indexes { ++$_ > 7 } @o; +is_deeply(\@o, \@n, "indexes behaves like grep on modified \$_"); +is_deeply(\@x, [7 .. 9], "indexes/modify"); + +not_dying( + 'indexes_on_set' => sub { + @x = indexes { ++$_ > 7 } (0 .. 9); + } +); +is_deeply(\@x, [7 .. 9], "indexes/modify set"); + +leak_free_ok( + indexes => sub { + @s = indexes { grow_stack; $_ > 5 } (4 .. 9); + @n = indexes { grow_stack; $_ > 5 } (1 .. 4); + @o = indexes { grow_stack; $_ & 1 } (10 .. 15); + @e = indexes { grow_stack; !($_ & 1) } (10 .. 15); + }, + 'indexes interrupted by exception' => sub { + eval { + @s = indexes { $_ > 10 and die "range exceeded"; $_ > 5 } (1 .. 15); + }; + }, +); + +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +my $have_scalar_util = eval { require Scalar::Util; 1 }; + +if ($have_scalar_util) +{ + my $ref = \(indexes(sub { 1 }, 123)); + Scalar::Util::weaken($ref); + is($ref, undef, "weakened away"); +} +is_dying('indexes without sub' => sub { &indexes(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/insert_after.pm liblist-moreutils-perl-0.430/t/inline/insert_after.pm --- liblist-moreutils-perl-0.416/t/inline/insert_after.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/insert_after.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,39 @@ + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after { $_ eq "a" } "longer" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { 0 } "bla" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { $_ eq "list" } "!" => @list; +is(join(' ', @list), "This is a longer list !"); +@list = (qw{This is}, undef, qw{list}); +insert_after { not defined($_) } "longer" => @list; +$list[2] = "a"; +is(join(' ', @list), "This is a longer list"); + +leak_free_ok( + insert_after => sub { + @list = qw{This is a list}; + insert_after { $_ eq 'a' } "longer" => @list; + } +); +leak_free_ok( + 'insert_after with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after { $_ eq 'a' } "longer" => @list; + }; + } +); +is_dying('insert_after without sub' => sub { &insert_after(42, 4711, [qw(die bart die)]); }); +is_dying('insert_after without sub and array' => sub { &insert_after(42, 4711, "13"); }); +is_dying( + 'insert_after without array' => sub { + &insert_after(sub { }, 4711, "13"); + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/insert_after_string.pm liblist-moreutils-perl-0.430/t/inline/insert_after_string.pm --- liblist-moreutils-perl-0.416/t/inline/insert_after_string.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/insert_after_string.pm 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,32 @@ + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after_string "a", "longer" => @list; +is(join(' ', @list), "This is a longer list"); +@list = (undef, qw{This is a list}); +insert_after_string "a", "longer", @list; +shift @list; +is(join(' ', @list), "This is a longer list"); +@list = ("This\0", "is\0", "a\0", "list\0"); +insert_after_string "a\0", "longer\0", @list; +is(join(' ', @list), "This\0 is\0 a\0 longer\0 list\0"); + +leak_free_ok( + insert_after_string => sub { + @list = qw{This is a list}; + insert_after_string "a", "longer", @list; + } +); +leak_free_ok( + 'insert_after_string with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after_string "a", "longer", @list; + }; + } +); +is_dying('insert_after_string without array' => sub { &insert_after_string(42, 4711, "13"); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/lastidx.pm liblist-moreutils-perl-0.430/t/inline/lastidx.pm --- liblist-moreutils-perl-0.416/t/inline/lastidx.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/lastidx.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,29 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_index = __PACKAGE__->can("lastidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(9999, lastidx { $_ >= 5000 } @list); +is(-1, lastidx { not defined } @list); +is(9999, lastidx { defined } @list); +is(-1, lastidx {}); + +# Test aliases +is(9999, last_index { $_ >= 5000 } @list); +is(-1, last_index { not defined } @list); +is(9999, last_index { defined } @list); +is(-1, last_index {}); + +leak_free_ok( + lastidx => sub { + my $i = lastidx { $_ >= 5000 } @list; + my $i2 = lastidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('lastidx without sub' => sub { &lastidx(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/lastres.pm liblist-moreutils-perl-0.430/t/inline/lastres.pm --- liblist-moreutils-perl-0.416/t/inline/lastres.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/lastres.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,27 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_result = __PACKAGE__->can("lastres"); +} + +use Test::More; +use Test::LMU; + +my $x = lastres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = lastres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = last_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = last_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastres => sub { + $x = lastres { $_ > 5 } 4 .. 9; + } +); +is_dying('lastres without sub' => sub { &lastres(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/lastval.pm liblist-moreutils-perl-0.430/t/inline/lastval.pm --- liblist-moreutils-perl-0.416/t/inline/lastval.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/lastval.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,28 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_value = __PACKAGE__->can("lastval"); +} + +use Test::More; +use Test::LMU; + +my $x = lastval { $_ > 5 } 4 .. 9; +is($x, 9); +$x = lastval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(lastval { $_ > 5 }); + +# Test aliases +$x = last_value { $_ > 5 } 4 .. 9; +is($x, 9); +$x = last_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastval => sub { + $x = lastval { $_ > 5 } 4 .. 9; + } +); +is_dying('lastval without sub' => sub { &lastval(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/listcmp.pm liblist-moreutils-perl-0.430/t/inline/listcmp.pm --- liblist-moreutils-perl-0.416/t/inline/listcmp.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/listcmp.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,116 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen); + my @b = qw(two three five seven eleven thirteen seventeen); + my @c = qw(one one two three five eight thirteen twentyone); + + my %expected = ( + one => [0, 2], + two => [0, 1, 2], + three => [0, 1, 2], + four => [0], + five => [0, 1, 2], + six => [0], + seven => [0, 1], + eight => [0, 2], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1, 2], + seventeen => [1], + twentyone => [2], + ); + + my %cmped = listcmp @a, @b, @c; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime vs. Fibonacci sorted out correctly"); +} + +SCOPE: +{ + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime filled with undef sorted out correctly"); +} + +leak_free_ok( + listcmp => sub { + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'listcmp with exception in overloading stringify at begin' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = (DieOnStringify->new, "two", "three"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + }, + 'listcmp with exception in overloading stringify at end' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = ("two", "three", DieOnStringify->new); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/lower_bound.pm liblist-moreutils-perl-0.430/t/inline/lower_bound.pm --- liblist-moreutils-perl-0.416/t/inline/lower_bound.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/lower_bound.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,54 @@ + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (lower_bound { $_ <=> 0 } @list), "lower bound 0"); +is(0, (lower_bound { $_ <=> 1 } @list), "lower bound 1"); +is(2, (lower_bound { $_ <=> 2 } @list), "lower bound 2"); +is(10, (lower_bound { $_ <=> 4 } @list), "lower bound 4"); +is(scalar @list, (lower_bound { $_ <=> 19 } @list), "lower bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i ? $i - 1 : 0, (lower_bound { $_ - $j } @list), "placed $j"); + is($i, (lower_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (lower_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (lower_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + lower_bound => sub { + my $elem = int(rand(1000)) + 1; + lower_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + lower_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + lower_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('lower_bound without sub' => sub { &lower_bound(42, (1 .. 100)); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/mesh.pm liblist-moreutils-perl-0.430/t/inline/mesh.pm --- liblist-moreutils-perl-0.416/t/inline/mesh.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/mesh.pm 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,68 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *zip = __PACKAGE__->can("mesh"); +} + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "mesh two list with same count of elements"); +} + +SCOPE: +{ + # alias check + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "zip two list with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = mesh @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "mesh three list with increasing count of elements"); +} + +SCOPE: +{ + # alias check + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "zip three list with increasing count of elements"); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = mesh @a, @d; + is_deeply( + \@z, + [1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef,], + "mesh one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + mesh => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + } +); +is_dying('mesh with a list, not at least two arrays' => sub { &mesh(1, 2); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/minmax.pm liblist-moreutils-perl-0.430/t/inline/minmax.pm --- liblist-moreutils-perl-0.416/t/inline/minmax.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/minmax.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,78 @@ + +use Test::More; +use Test::LMU; + +my @list = reverse 0 .. 10000; +my ($min, $max) = minmax @list; +is($min, 0); +is($max, 10000); + +# Even number of elements +push @list, 10001; +($min, $max) = minmax @list; +is($min, 0); +is($max, 10001); +$list[0] = 17; + +# Some floats +@list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); +($min, $max) = minmax @list; + +# Floating-point comparison cunningly avoided +is(sprintf("%.2f", $min), "-3.33"); +is($max, 10000); + +# Test with a single negative list value +my $input = -1; +($min, $max) = minmax $input; +is($min, -1); +is($max, -1); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmax(sprintf("%.3g", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmax swallows max on COW"); + +# Confirm output are independant copies of input +$input = 1; +is($min, -1); +is($max, -1); +$min = 2; +is($max, -1); + +# prove overrun +my $uvmax = ~0; +my $ivmax = $uvmax >> 1; +my $ivmin = (0 - $ivmax) - 1; +my @low_ints = map { $ivmin + $_ } (0 .. 10); +($min, $max) = minmax @low_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmin + 10, "minmax finds ivmin + 10"); + +my @high_ints = map { $ivmax - $_ } (0 .. 10); +($min, $max) = minmax @high_ints; +is($min, $ivmax - 10, "minmax finds ivmax-10"); +is($max, $ivmax, "minmax finds ivmax"); + +my @mixed_ints = map { ($ivmin + $_, $ivmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmax, "minmax finds ivmax"); + +my @high_uints = map { $uvmax - $_ } (0 .. 10); +($min, $max) = minmax @high_uints; +is($min, $uvmax - 10, "minmax finds uvmax-10"); +is($max, $uvmax, "minmax finds uvmax"); + +my @mixed_nums = map { ($ivmin + $_, $uvmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_nums; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $uvmax, "minmax finds uvmax"); + +leak_free_ok( + minmax => sub { + @list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); + ($min, $max) = minmax @list; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/minmaxstr.pm liblist-moreutils-perl-0.430/t/inline/minmaxstr.pm --- liblist-moreutils-perl-0.416/t/inline/minmaxstr.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/minmaxstr.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,42 @@ +use Test::More; +use Test::LMU; + +use POSIX qw(setlocale LC_COLLATE); +setlocale(LC_COLLATE, "C"); + +my @list = reverse 'AA' .. 'ZZ'; +my ($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ'); + +# Odd number of elements +push @list, 'ZZ Top'; +($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ Top'); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmaxstr(sprintf("%s", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmaxstr swallows max on COW"); + +# Test with a single list value +my $input = 'foo'; +($min, $max) = minmaxstr $input; +is($min, 'foo'); +is($max, 'foo'); + +# Confirm output are independant copies of input +$input = 'bar'; +is($min, 'foo'); +is($max, 'foo'); +$min = 'bar'; +is($max, 'foo'); + +leak_free_ok( + minmaxstr => sub { + @list = reverse 'AA' .. 'ZZ', 'ZZ Top'; + ($min, $max) = minmaxstr @list; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/mode.pm liblist-moreutils-perl-0.430/t/inline/mode.pm --- liblist-moreutils-perl-0.416/t/inline/mode.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/mode.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,441 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + my $fl = freeze(\@lorem); + + my $n_comma = scalar(split /,/, $lorem) - 1; + + my @m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_ARRAY lorem untouched"); + is_deeply([$n_comma, ','], \@m, "lorem mode as list"); + my $m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_SCALAR lorem untouched"); + is($n_comma, $m, "lorem mode as scalar"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "mode:G_ARRAY probes untouched"); + is_deeply([7, 4], \@m, "unimodal result in list context"); + my $m = mode @probes; + is($fp, freeze(\@probes), "mode:G_SCALAR probes untouched"); + is(7, $m, "unimodal result in scalar context"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_ARRAY probes untouched"); + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([7, 4, 8], \@m, "bimodal result in list context"); + $m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_SCALAR probes untouched"); + is(7, $m, "bimodal result in scalar context"); +} + +SCOPE: +{ + my %radio_ukw_nrw = ( + "87,6" => "WDR Eins Live", + "87,7" => "WDR 5", + "87,7" => "Welle Niederrhein", + "87,7" => "WDR 5", + "87,8" => "Welle West", + "87,8" => "WDR 4", + "87,8" => "WDR 2 Dortmund", + "87,9" => "Radio HERTZ", + "88,0" => "WDR 5", + "88,1" => "Radio Hochstift", + "88,2" => "Radio Kiepenkerl", + "88,2" => "Radio Siegen", + "88,3" => "WDR 5", + "88,3" => "Radio MK", + "88,4" => "WDR 2 Köln", + "88,4" => "Radio WMW", + "88,4" => "WDR 5", + "88,5" => "WDR 5", + "88,5" => "Werrepark Radio", + "88,5" => "WDR 5", + "88,6" => "WDR 5", + "88,7" => "WDR 3", + "88,8" => "WDR 5", + "88,9" => "Deutschlandradio Kultur", + "89,0" => "Lokalradio Olpe", + "89,1" => "Deutschlandfunk (DLF)", + "89,1" => "Radio Sauerland", + "89,2" => "WDR (Test)", + "89,3" => "Antenne Unna", + "89,4" => "NE-WS 89,4", + "89,4" => "L`UniCo FM", + "89,6" => "WDR 5", + "89,7" => "WDR 3", + "90,0" => "CT das radio", + "90,0" => "WDR 5", + "90,1" => "WDR 4", + "90,1" => "Deutschlandradio Kultur", + "90,1" => "Radio 90,1", + "90,3" => "WDR 5", + "90,6" => "WDR 5", + "90,7" => "WDR 4", + "90,8" => "Radio Herne", + "90,8" => "Radio MK", + "90,9" => "Radio Q", + "91,0" => "Deutschlandradio Kultur", + "91,0" => "Deutschlandfunk (DLF)", + "91,2" => "WDR (Test)", + "91,2" => "Radio 91,2", + "91,2" => "Radio Bonn/Rhein-Sieg", + "91,3" => "Radio Lippe (geplant)", + "91,3" => "Deutschlandfunk (DLF)", + "91,3" => "BFBS Radio 1", + "91,4" => "Radio Erft", + "91,5" => "Radio MK", + "91,5" => "Deutschlandfunk (DLF)", + "91,5" => "Radio Ennepe Ruhr", + "91,7" => "WDR 4", + "91,7" => "BFBS Radio 2", + "91,7" => "WDR 3", + "91,7" => "Radio K.W.", + "91,7" => "Radio Herford", + "91,8" => "WDR 2 Wuppertal", + "91,8" => "WDR 2 Bielefeld", + "91,9" => "WDR 4", + "92,0" => "WDR 5", + "92,0" => "domradio", + "92,1" => "Radius 92,1", + "92,2" => "Radio Duisburg", + "92,2" => "Deutschlandfunk (DLF)", + "92,2" => "Radio RSG", + "92,3" => "WDR 2 Siegen", + "92,5" => "BFBS Radio 1", + "92,5" => "Radio MK", + "92,6" => "Radio WAF", + "92,7" => "WDR 3", + "92,7" => "Radio Rur", + "92,7" => "Radio Ennepe Ruhr", + "92,9" => "Radio Mülheim", + "93,0" => "Radio WMW", + "93,0" => "elDOradio", + "93,1" => "WDR 3", + "93,2" => "WDR 2 Bielefeld", + "93,3" => "WDR 2 Rhein-Ruhr", + "93,5" => "WDR 2 Siegen", + "93,6" => "WDR Eins Live", + "93,7" => "Radio Hochstift", + "93,8" => "WDR 2 Siegen", + "93,9" => "WDR 4", + "93,9" => "Deutschlandfunk (DLF)", + "93,9" => "WDR 5", + "94,1" => "WDR 2 Münster", + "94,2" => "Radio Bonn/Rhein-Sieg", + "94,2" => "WDR 2 Aachen", + "94,2" => "Deutschlandfunk (DLF)", + "94,3" => "Antenne Bethel", + "94,3" => "Radio RSG", + "94,3" => "WDR 3", + "94,5" => "Deutschlandfunk (DLF)", + "94,6" => "Radio MK", + "94,6" => "Test FM", + "94,6" => "Deutschlandradio Kultur", + "94,6" => "Radio Vest", + "94,7" => "Radio FH", + "94,7" => "Radio WAF", + "94,8" => "WDR (Test)", + "94,8" => "Radio Sauerland", + "94,9" => "Radio Herford", + "95,1" => "WDR 3", + "95,1" => "Radio Westfalica", + "95,2" => "WDR 3", + "95,4" => "Antenne Münster", + "95,5" => "Deutschlandfunk (DLF)", + "95,6" => "Radio Vest", + "95,7" => "Radio WAF", + "95,7" => "Radio Westfalica", + "95,7" => "WDR 2 Wuppertal", + "95,8" => "WDR 5", + "95,9" => "WDR 3", + "95,9" => "Triquency", + "95,9" => "Radio Gütersloh", + "96,0" => "WDR Eins Live", + "96,0" => "WDR 2 Münster", + "96,0" => "WDR 2 Bielefeld", + "96,1" => "Radio Emscher Lippe", + "96,1" => "WDR 4", + "96,1" => "Triquency", + "96,2" => "Radio Sauerland", + "96,3" => "WDR 3", + "96,3" => "Radio WAF", + "96,3" => "Deutschlandradio Kultur", + "96,4" => "Radio Siegen (geplant)", + "96,4" => "WDR 2 Bielefeld", + "96,5" => "Deutschlandradio Kultur", + "96,8" => "bonn FM", + "96,9" => "Deutschlandradio Kultur", + "96,9" => "Radio Berg", + "97,0" => "WDR 3", + "97,1" => "Antenne GL", + "97,1" => "Hochschulradio Düsseldorf", + "97,1" => "WDR 2 Siegen", + "97,2" => "107.8 Antenne AC", + "97,2" => "Radio MK", + "97,3" => "Radio Siegen", + "97,3" => "WDR 3", + "97,3" => "WDR 3", + "97,4" => "Antenne Unna", + "97,5" => "WDR 3", + "97,5" => "Deutschlandradio Kultur", + "97,6" => "Radio WMW", + "97,6" => "WDR (Test)", + "97,6" => "Radio Bielefeld", + "97,6" => "Radio Neandertal", + "97,6" => "WDR 5", + "97,7" => "Deutschlandradio Kultur", + "97,8" => "Radio Bonn/Rhein-Sieg", + "97,8" => "WDR 3", + "98,0" => "Antenne Niederrhein", + "98,1" => "WDR 3", + "98,2" => "WDR 3", + "98,2" => "WDR Eins Live", + "98,3" => "Radio Bielefeld", + "98,4" => "WDR 3", + "98,5" => "Radio Bochum", + "98,6" => "WDR 2 + Messeradio Köln", + "98,6" => "WDR 5", + "98,7" => "Radio Emscher Lippe", + "98,9" => "Deutschlandradio Kultur", + "98,9" => "Lokalradio Olpe", + "98,9" => "Radio Siegen", + "99,1" => "Hochschulradio Aachen", + "99,1" => "WDR 2 Bielefeld", + "99,2" => "WDR 2 Rhein-Ruhr", + "99,4" => "WDR 2 Siegen", + "99,4" => "Triquency", + "99,5" => "WDR 4", + "99,5" => "Radio MK", + "99,6" => "WDR 4", + "99,7" => "Radio Euskirchen", + "99,7" => "WDR 5", + "99,7" => "Radio Berg", + "99,7" => "WDR Eins Live", + "99,8" => "WDR 2 Wuppertal", + "99,9" => "Radio Bonn/Rhein-Sieg", + "100,0" => "Kölncampus", + "100,0" => "WDR 4", + "100,1" => "107.8 Antenne AC", + "100,1" => "WDR Eins Live", + "100,2" => "Radio MK", + "100,2" => "Deutschlandradio Kultur", + "100,4" => "WDR 2 Köln", + "100,5" => "WDR 4", + "100,6" => "Welle Niederrhein", + "100,7" => "WDR 4", + "100,8" => "WDR 2 Aachen", + "100,9" => "Hellweg Radio", + "101,0" => "WDR 2 Aachen", + "101,0" => "Radio Lippe", + "101,1" => "WDR 4", + "101,1" => "Deutschlandradio Kultur", + "101,2" => "WDR 4", + "101,3" => "WDR 4", + "101,6" => "BFBS Radio 2", + "101,7" => "WDR 4", + "101,7" => "domradio", + "101,8" => "WDR 2 Siegen", + "101,9" => "WDR 5", + "101,9" => "BFBS Radio 1", + "102,1" => "NE-WS 89,4", + "102,1" => "WDR 2 Siegen", + "102,2" => "Radio Essen", + "102,2" => "BFBS Radio 2", + "102,3" => "Antenne Unna", + "102,4" => "WDR Eins Live", + "102,5" => "WDR Eins Live", + "102,7" => "Deutschlandfunk (DLF)", + "102,7" => "Deutschlandfunk (DLF)", + "102,8" => "Deutschlandfunk (DLF)", + "103,0" => "BFBS Radio 1", + "103,3" => "Funkhaus Europa", + "103,6" => "Radio WMW", + "103,6" => "Hellweg Radio", + "103,7" => "WDR Eins Live", + "103,8" => "WDR 4", + "103,9" => "Radio Q", + "104,0" => "BFBS Radio 1", + "104,0" => "Radio RST", + "104,1" => "WDR 4", + "104,2" => "Radio Bonn/Rhein-Sieg", + "104,2" => "Antenne Düsseldorf", + "104,2" => "Radio Ennepe Ruhr", + "104,3" => "BFBS Radio 2", + "104,4" => "WDR 4", + "104,4" => "Deutschlandfunk (DLF)", + "104,5" => "CampusFM", + "104,5" => "Deutschlandfunk (DLF)", + "104,5" => "WDR 4", + "104,7" => "WDR Eins Live", + "104,8" => "Radio Hochstift", + "104,8" => "Radio Hochstift", + "104,9" => "Radio Sauerland", + "105,0" => "Radio Essen", + "105,0" => "Radio Lippe Welle Hamm", + "105,0" => "107.8 Antenne AC", + "105,0" => "BFBS Radio 2", + "105,1" => "BFBS Radio 1", + "105,2" => "Radio Vest", + "105,2" => "Radio Berg", + "105,2" => "Radio RST", + "105,4" => "Radio Siegen", + "105,5" => "WDR Eins Live", + "105,5" => "WDR Eins Live", + "105,6" => "CampusFM", + "105,7" => "Antenne Niederrhein", + "105,7" => "Radio Ennepe Ruhr", + "105,7" => "WDR Eins Live", + "105,7" => "Radio Berg", + "105,8" => "Radio Erft", + "106,0" => "BFBS Radio 1", + "106,1" => "Deutschlandradio Kultur", + "106,1" => "Deutschlandradio Kultur", + "106,2" => "Deutschlandradio Kultur", + "106,2" => "106.2 Radio Oberhausen", + "106,3" => "Radio Kiepenkerl", + "106,4" => "WDR Eins Live", + "106,5" => "Radio Sauerland", + "106,5" => "Radio Sauerland", + "106,5" => "Radio St. Laurentius", + "106,6" => "Radio Lippe", + "106,6" => "Radio Westfalica", + "106,6" => "Deutschlandfunk (DLF)", + "106,7" => "WDR Eins Live", + "106,8" => "Radio Gütersloh", + "106,9" => "Radio Euskirchen", + "107,0" => "WDR Eins Live", + "107,1" => "Radio Köln", + "107,2" => "WDR Eins Live", + "107,2" => "Deutschlandfunk (DLF)", + "107,3" => "WDR Eins Live", + "107,3" => "Hellweg Radio", + "107,4" => "Radio Euskirchen", + "107,4" => "Radio Kiepenkerl", + "107,4" => "Radio Lippe", + "107,4" => "Radio Wuppertal", + "107,5" => "Radio Rur", + "107,5" => "Radio Gütersloh", + "107,5" => "WDR Eins Live", + "107,6" => "Radio Leverkusen", + "107,6" => "Radio Sauerland", + "107,6" => "Radio K.W.", + "107,7" => "WDR Eins Live", + "107,7" => "Hellweg Radio", + "107,7" => "107.7 Radio Hagen", + "107,8" => "107.8 Antenne AC", + "107,8" => "Lokalradio Olpe", + "107,9" => "Radio Bonn/Rhein-Sieg", + "107,9" => "WDR Eins Live", + "107,9" => "Radio RSG", + ); + + my @m = mode values %radio_ukw_nrw; + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([14, 'WDR 5', 'WDR Eins Live'], \@m, "multimodal result in list context"); + $m = mode values %radio_ukw_nrw; + is(14, $m, "multimodal result in scalar context"); +} + +leak_free_ok( + 'mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @m = mode @probes; + }, + 'scalar mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $m = mode @probes; + }, + 'mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my @m = mode @probes; + }, + 'scalar mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $m = mode @probes; + }, + 'mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my @m = mode @probes; + }, + 'scalar mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my $m = mode @probes; + }, +); + +leak_free_ok( + 'mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @m = mode @probes; + }; + }, + 'scalar mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $m = mode @probes; + }; + }, + 'mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my @m = mode @probes; + }; + }, + 'scalar mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my $m = mode @probes; + }; + }, + 'mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my @m = mode @probes; + }; + }, + 'scalar mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my $m = mode @probes; + }; + }, +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/natatime.pm liblist-moreutils-perl-0.430/t/inline/natatime.pm --- liblist-moreutils-perl-0.416/t/inline/natatime.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/natatime.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,35 @@ + +use Test::More; +use Test::LMU; + +my @x = ('a' .. 'g'); +my $it = natatime 3, @x; +my @r; +local $" = " "; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "natatime with 3 elements"); + +my @a = (1 .. 1000); +$it = natatime 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "natatime with 1 element"); + +leak_free_ok( + natatime => sub { + my @y = 1; + my $it = natatime 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/none.pm liblist-moreutils-perl-0.430/t/inline/none.pm --- liblist-moreutils-perl-0.416/t/inline/none.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/none.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none { not defined } @list); +is_true(none { $_ > 10000 } @list); +is_false(none { defined } @list); +is_true(none {}); + +leak_free_ok( + none => sub { + my $ok = none { $_ == 5000 } @list; + my $ok2 = none { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none without sub' => sub { &none(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/none_u.pm liblist-moreutils-perl-0.430/t/inline/none_u.pm --- liblist-moreutils-perl-0.416/t/inline/none_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/none_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none_u { not defined } @list); +is_true(none_u { $_ > 10000 } @list); +is_false(none_u { defined } @list); +is_undef(none_u {}); + +leak_free_ok( + none_u => sub { + my $ok = none_u { $_ == 5000 } @list; + my $ok2 = none_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none_u without sub' => sub { &none_u(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/notall.pm liblist-moreutils-perl-0.430/t/inline/notall.pm --- liblist-moreutils-perl-0.416/t/inline/notall.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/notall.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall { !defined } @list); +is_true(notall { $_ < 10000 } @list); +is_false(notall { $_ <= 10000 } @list); +is_false(notall {}); + +leak_free_ok( + notall => sub { + my $ok = notall { $_ == 5000 } @list; + my $ok2 = notall { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall without sub' => sub { ¬all(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/notall_u.pm liblist-moreutils-perl-0.430/t/inline/notall_u.pm --- liblist-moreutils-perl-0.416/t/inline/notall_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/notall_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,20 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall_u { !defined } @list); +is_true(notall_u { $_ < 10000 } @list); +is_false(notall_u { $_ <= 10000 } @list); +is_undef(notall_u {}); + +leak_free_ok( + notall_u => sub { + my $ok = notall_u { $_ == 5000 } @list; + my $ok2 = notall_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall_u without sub' => sub { ¬all_u(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/occurrences.pm liblist-moreutils-perl-0.430/t/inline/occurrences.pm --- liblist-moreutils-perl-0.416/t/inline/occurrences.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/occurrences.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,81 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + + my $n_comma = scalar(split /,/, $lorem) - 1; + my $n_dot = scalar(split /\./, $lorem); # there is one at end ... mind the gap + my $n_et = scalar(split /\bet\b/, $lorem) - 1; + + my @l = @lorem; + my @o = occurrences @l; + + is(undef, $o[0], "Each word is counted"); + is(undef, $o[1], "Text to long, each word is there at least twice"); + is_deeply([','], $o[$n_comma], "$n_comma comma"); + is_deeply(['.'], $o[$n_dot], "$n_dot dots"); + is_deeply(['et'], $o[$n_et], "$n_et words 'et'"); + + @o = occurrences grep { /\w+/ } @lorem; + my $wc = reduce_0 { defined $b ? $a + $_ * scalar @$b : $a } @o; + is($wc, 124, "Words are as many as requested at www.loremipsum.de"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { ref $_ ? [sort @$_] : $_ } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +SCOPE: +{ + my @probes = ((1) x 3, undef, (2) x 4, undef, (3) x 2, undef, (4) x 7, undef, (5) x 2, undef, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { + ref $_ + ? [sort { (defined $a <=> defined $b) or $a <=> $b } @$_] + : $_ + } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], [undef], undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +leak_free_ok( + occurrences => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @o = occurrences @probes; + }, + 'scalar occurrences' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $o = occurrences @probes; + } +); + +leak_free_ok( + 'occurrences with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @o = occurrences @probes; + }; + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $o = occurrences @probes; + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/one.pm liblist-moreutils-perl-0.430/t/inline/one.pm --- liblist-moreutils-perl-0.416/t/inline/one.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/one.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,23 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one { 1 == $_ } @list); +is_true(one { 150 == $_ } @list); +is_true(one { 300 == $_ } @list); +is_false(one { 0 == $_ } @list); +is_false(one { 1 <= $_ } @list); +is_false(one { !(127 & $_) } @list); +is_false(one { 0 } ()); + +leak_free_ok( + one => sub { + my $ok = one { 150 <= $_ } @list; + my $ok2 = one { 150 <= $_ } 1 .. 300; + } +); +is_dying('one without sub' => sub { &one(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/one_u.pm liblist-moreutils-perl-0.430/t/inline/one_u.pm --- liblist-moreutils-perl-0.416/t/inline/one_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/one_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,23 @@ + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one_u { 1 == $_ } @list); +is_true(one_u { 150 == $_ } @list); +is_true(one_u { 300 == $_ } @list); +is_false(one_u { 0 == $_ } @list); +is_false(one_u { 1 <= $_ } @list); +is_false(one_u { !(127 & $_) } @list); +is_undef(one_u {}); + +leak_free_ok( + one_u => sub { + my $ok = one_u { 150 <= $_ } @list; + my $ok2 = one_u { 150 <= $_ } 1 .. 300; + } +); +is_dying('one_u without sub' => sub { &one_u(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/onlyidx.pm liblist-moreutils-perl-0.430/t/inline/onlyidx.pm --- liblist-moreutils-perl-0.416/t/inline/onlyidx.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/onlyidx.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,33 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_index = __PACKAGE__->can("onlyidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(0, onlyidx { 1 == $_ } @list); +is(149, onlyidx { 150 == $_ } @list); +is(299, onlyidx { 300 == $_ } @list); +is(-1, onlyidx { 0 == $_ } @list); +is(-1, onlyidx { 1 <= $_ } @list); +is(-1, onlyidx { !(127 & $_) } @list); + +# Test aliases +is(0, only_index { 1 == $_ } @list); +is(149, only_index { 150 == $_ } @list); +is(299, only_index { 300 == $_ } @list); +is(-1, only_index { 0 == $_ } @list); +is(-1, only_index { 1 <= $_ } @list); +is(-1, only_index { !(127 & $_) } @list); + +leak_free_ok( + onlyidx => sub { + my $ok = onlyidx { 150 <= $_ } @list; + my $ok2 = onlyidx { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyidx without sub' => sub { &onlyidx(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/onlyres.pm liblist-moreutils-perl-0.430/t/inline/onlyres.pm --- liblist-moreutils-perl-0.416/t/inline/onlyres.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/onlyres.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,31 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_result = __PACKAGE__->can("onlyres"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is("Hallelujah", onlyres { 150 == $_ and "Hallelujah" } @list); +is(1, onlyres { 300 == $_ } @list); +is(undef, onlyres { 0 == $_ } @list); +is(undef, onlyres { 1 <= $_ } @list); +is(undef, onlyres { !(127 & $_) } @list); + +# Test aliases +is(1, only_result { 150 == $_ } @list); +is("Hallelujah", only_result { 300 == $_ and "Hallelujah" } @list); +is(undef, only_result { 0 == $_ } @list); +is(undef, only_result { 1 <= $_ } @list); +is(undef, only_result { !(127 & $_) } @list); + +leak_free_ok( + onlyres => sub { + my $ok = onlyres { 150 <= $_ } @list; + my $ok2 = onlyres { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyres without sub' => sub { &onlyres(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/onlyval.pm liblist-moreutils-perl-0.430/t/inline/onlyval.pm --- liblist-moreutils-perl-0.416/t/inline/onlyval.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/onlyval.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,33 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_value = __PACKAGE__->can("onlyval"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(1, onlyval { 1 == $_ } @list); +is(150, onlyval { 150 == $_ } @list); +is(300, onlyval { 300 == $_ } @list); +is(undef, onlyval { 0 == $_ } @list); +is(undef, onlyval { 1 <= $_ } @list); +is(undef, onlyval { !(127 & $_) } @list); + +# Test aliases +is(1, only_value { 1 == $_ } @list); +is(150, only_value { 150 == $_ } @list); +is(300, only_value { 300 == $_ } @list); +is(undef, only_value { 0 == $_ } @list); +is(undef, only_value { 1 <= $_ } @list); +is(undef, only_value { !(127 & $_) } @list); + +leak_free_ok( + onlyval => sub { + my $ok = onlyval { 150 <= $_ } @list; + my $ok2 = onlyval { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyval without sub' => sub { &onlyval(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/pairwise.pm liblist-moreutils-perl-0.430/t/inline/pairwise.pm --- liblist-moreutils-perl-0.416/t/inline/pairwise.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/pairwise.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,118 @@ + +use Test::More; +use Test::LMU; + +my @a = (1, 2, 3, 4, 5); +my @b = (2, 4, 6, 8, 10); +my @c = pairwise { $a + $b } @a, @b; +is_deeply(\@c, [3, 6, 9, 12, 15], "pw1"); + +@c = pairwise { $a * $b } @a, @b; # returns (2, 8, 18) +is_deeply(\@c, [2, 8, 18, 32, 50], "pw2"); + +# Did we modify the input arrays? +is_deeply(\@a, [1, 2, 3, 4, 5], "pw3"); +is_deeply(\@b, [2, 4, 6, 8, 10], "pw4"); + +# $a and $b should be aliases: test +@b = @a = (1, 2, 3); +@c = pairwise { $a++; $b *= 2 } @a, @b; +is_deeply(\@a, [2, 3, 4], "pw5"); +is_deeply(\@b, [2, 4, 6], "pw6"); +is_deeply(\@c, [2, 4, 6], "pw7"); + +# sub returns more than two items +@a = (1, 1, 2, 3, 5); +@b = (2, 3, 5, 7, 11, 13); +@c = pairwise { ($a) x $b } @a, @b; +is_deeply(\@c, [(1) x 2, (1) x 3, (2) x 5, (3) x 7, (5) x 11, (undef) x 13], "pw8"); +is_deeply(\@a, [1, 1, 2, 3, 5], "pw9"); +is_deeply(\@b, [2, 3, 5, 7, 11, 13], "pwX"); + +(@a, @b) = (); +push @a, int rand(1000) for 0 .. rand(1000); +push @b, int rand(1000) for 0 .. rand(1000); +SCOPE: +{ + local $SIG{__WARN__} = sub { }; # XXX + my @res1 = pairwise { $a + $b } @a, @b; + # Test this one more thoroughly: the XS code looks flakey + # correctness of pairwise_perl proved by human auditing. :-) + my $limit = $#a > $#b ? $#a : $#b; + my @res2 = map { $a[$_] + $b[$_] } 0 .. $limit; + is_deeply(\@res1, \@res2); +} + +@a = qw/a b c/; +@b = qw/1 2 3/; +@c = pairwise { ($a, $b) } @a, @b; +is_deeply(\@c, [qw/a 1 b 2 c 3/], "pw map"); + +SKIP: +{ + $ENV{PERL5OPT} and skip 'A defined PERL5OPT may inject extra deps crashing this test', 1; + # Test that a die inside the code-reference will not be trapped + eval { + pairwise { die "I died\n" } @a, @b; + }; + is($@, "I died\n"); +} + +leak_free_ok( + pairwise => sub { + @a = (1); + @b = (2); + @c = pairwise { $a + $b } @a, @b; + } +); + +leak_free_ok( + 'exceptional block' => sub { + @a = qw/a b c/; + @b = qw/1 2 3/; + eval { + @c = pairwise { $b == 3 and die "Primes suck!"; "$a:$b" } @a, @b; + }; + } +); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will warn here ...", 1; + my ($a, $b, @t); + eval { + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + }; + my $err = $@; + like($err, qr/Can't use lexical \$a or \$b in pairwise code block/, "pairwise die's on broken caller"); +} + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "XS will die on purpose here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, @_ }; + my ($a, $b, @t); + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + like(join("", @warns[0, 1]), qr/Use of uninitialized value.*? in addition/, "warning on broken caller"); +} + +is_dying('pairwise without sub' => sub { &pairwise(42, \@a, \@b); }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not core here ...", 2; + is_dying( + 'pairwise without first ARRAY' => sub { + @c = &pairwise(sub { }, 1, \@b); + } + ); + is_dying( + 'pairwise without second ARRAY' => sub { + @c = &pairwise(sub { }, \@a, 2); + } + ); +} + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/part.pm liblist-moreutils-perl-0.430/t/inline/part.pm --- liblist-moreutils-perl-0.416/t/inline/part.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/part.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,79 @@ + +use Test::More; +use Test::LMU; + +my @list = 1 .. 12; +my $i = 0; +my @part = part { $i++ % 3 } @list; +is_deeply($part[0], [1, 4, 7, 10], " i: part % 3"); +is_deeply($part[1], [2, 5, 8, 11], " ii: part % 3"); +is_deeply($part[2], [3, 6, 9, 12], "iii: part % 3"); + +$list[2] = 0; +is($part[2][0], 3, 'Values are not aliases'); + +@list = 1 .. 12; +@part = part { 3 } @list; +is($part[0], undef, " i: part 3"); +is($part[1], undef, " ii: part 3"); +is($part[2], undef, "iii: part 3"); +is_deeply($part[3], [1 .. 12], " iv: part 3"); + +eval { + @part = part { -1 } @list; +}; +like($@, qr/^Modification of non-creatable array value attempted, subscript -1/); + +$i = 0; +@part = part { $i++ == 0 ? 0 : -1 } @list; +is_deeply($part[0], [1 .. 12], "part with negative indices"); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "Only PurePerl will warn here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, [@_] }; + @part = part { undef } @list; + is_deeply($part[0], [1 .. 12], "part with undef"); + like(join("\n", @{$warns[0]}), qr/Use of uninitialized value in array element.*line\s+\d+\.$/, "warning of undef"); + is_deeply(\@warns, [($warns[0]) x 12], "amount of similar undef warnings"); +} + +@part = part { 10000 } @list; +is_deeply($part[10000], [@list], " i: part 10_000"); +is($part[0], undef, " ii: part 10_000"); +is($part[@part / 2], undef, "iii: part 10_000"); +is($part[9999], undef, " iv: part 10_000"); + +# Changing the list in place used to destroy +# its elements due to a wrong refcnt +@list = 1 .. 10; +@list = part { $_ } @list; +foreach (1 .. 10) +{ + is_deeply($list[$_], [$_], "part \$_: $_"); +} + +leak_free_ok( + part => sub { + my @list = 1 .. 12; + my $i = 0; + my @part = part { $i++ % 3 } @list; + } +); + +leak_free_ok( + 'part with stack-growing' => sub { + # This test is from Kevin Ryde; see RT#38699 + my @part = part { grow_stack(); 1024 } 'one', 'two'; + } +); + +leak_free_ok( + 'part with exception' => sub { + my @long_list = int rand(1000) for 0 .. 1E7; + my @part = part { $_ == 1E7 and die "Too much!"; ($_ % 10) * 2 } @long_list; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/qsort.pm liblist-moreutils-perl-0.430/t/inline/qsort.pm --- liblist-moreutils-perl-0.416/t/inline/qsort.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/qsort.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,19 @@ + +use Test::More; +use Test::LMU; + +plan skip_all => "It's insane to use a pure-perl qsort" unless $INC{'List/MoreUtils/XS.pm'}; + +my @ltn_asc = qw(2 3 5 7 11 13 17 19 23 29 31 37); +my @ltn_des = reverse @ltn_asc; +my @l; + +@l = @ltn_des; +qsort sub { $a <=> $b }, @l; +is_deeply(\@l, \@ltn_asc, "sorted ascending"); + +@l = @ltn_asc; +qsort sub { $b <=> $a }, @l; +is_deeply(\@l, \@ltn_des, "sorted descending"); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/reduce_0.pm liblist-moreutils-perl-0.430/t/inline/reduce_0.pm --- liblist-moreutils-perl-0.416/t/inline/reduce_0.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/reduce_0.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,38 @@ + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_0' => sub { + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + }, + 'reduce_0 X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_0 { $a + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_0 with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_0 { die } 1; + }; + } +); +is_dying('reduce_0 without sub' => sub { &reduce_0(42, 4711); }); + +done_testing + diff -Nru liblist-moreutils-perl-0.416/t/inline/reduce_1.pm liblist-moreutils-perl-0.430/t/inline/reduce_1.pm --- liblist-moreutils-perl-0.416/t/inline/reduce_1.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/reduce_1.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,31 @@ + +use Test::More; +use Test::LMU; + +use Scalar::Util qw(looks_like_number); + +# (this code shamelessly stolen from Math::Complex's t/Trig.t, with some mods to near) from BBYRD in RT#72638 and taken from SQL-Statement now +use Math::Trig; +my $eps = 1e-11; + +if ($^O eq 'unicos') +{ # See lib/Math/Complex.pm and t/lib/complex.t. + $eps = 1e-10; +} + +sub near ($$$;$) +{ + my $d = $_[1] ? abs($_[0] / $_[1] - 1) : abs($_[0]); + local $Test::Builder::Level = $Test::Builder::Level + 1; + looks_like_number($_[0]) or return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/nan/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/inf/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + my $e = defined $_[3] ? $_[3] : $eps; + cmp_ok($d, '<', $e, "$_[2] => near? $_[0] ~= $_[1]") or diag("near? $_[0] ~= $_[1]"); +} + +my $half_pi = reduce_1 { $a * ((4 * $b * $b) / ((2 * $b - 1) * (2 * $b + 1))) } 1 .. 750; + +near($half_pi, pi / 2, "Wallis product", 1e-2); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/reduce_u.pm liblist-moreutils-perl-0.430/t/inline/reduce_u.pm --- liblist-moreutils-perl-0.416/t/inline/reduce_u.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/reduce_u.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,37 @@ + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (0, 2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_u' => sub { + my @exam_results = (undef, 2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + }, + 'reduce_u X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_u { ($a || 0) + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_u { die } 1; + }; + } +); +is_dying('reduce_u without sub' => sub { &reduce_u(42, 4711); }); + +done_testing diff -Nru liblist-moreutils-perl-0.416/t/inline/samples.pm liblist-moreutils-perl-0.430/t/inline/samples.pm --- liblist-moreutils-perl-0.416/t/inline/samples.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/samples.pm 2020-10-02 06:23:17.000000000 +0000 @@ -0,0 +1,39 @@ + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @l = (1 .. 100); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 integer probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = (1 .. 10); + my @s = samples 10, @l; + is(scalar @s, 10, "samples delivers 10 out of 10 when used as shuffle"); + my @u = uniq grep { defined $_ } @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = ('AA' .. 'ZZ'); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 strings probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any string twice"); +} + +is_dying('to much samples' => sub { my @l = (1 .. 3); samples 5, @l }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + is_dying('samples without list' => sub { samples 5 }); +} + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/singleton.pm liblist-moreutils-perl-0.430/t/inline/singleton.pm --- liblist-moreutils-perl-0.416/t/inline/singleton.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/singleton.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,97 @@ + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = map { (1 .. 1000) } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(200, $u); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = map { ("aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(scalar @s, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my $fs = freeze(\@s); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $fa = freeze(\@a); + my @u = singleton map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@s]); + is($fs, freeze(\@s)); + is($fa, freeze(\@a)); + is($fu, $fs); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + @a = (@d, @s); + my @u = singleton map { $_ } @a; + is_deeply(\@u, [@s]); + @a = (@d, @s); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @sfoo = ('a', undef, 'c'); + is_deeply([singleton @foo], \@sfoo, 'one undef is supported correctly by singleton'); + @foo = ('a', 'b', '', undef, 'b', 'c', undef); + @sfoo = ('a', '', 'c'); + is_deeply([singleton @foo], \@sfoo, 'twice undef is supported correctly by singleton'); + is((scalar singleton @foo), scalar @sfoo, 'scalar twice undef is supported correctly by singleton'); +} + +leak_free_ok( + singleton => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + scalar singleton @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'singleton with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = singleton $obj, $obj; + }; + eval { + my $obj = DieOnStringify->new; + my $u = singleton $obj, $obj; + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/slideatatime.pm liblist-moreutils-perl-0.430/t/inline/slideatatime.pm --- liblist-moreutils-perl-0.416/t/inline/slideatatime.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/slideatatime.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,64 @@ + +use Test::More; +use Test::LMU; + +local $" = " "; +my $it; +my @r; + +my @x = ('a' .. 'g'); +$it = slideatatime 3, 3, @x; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "slideatatime as natatime with 3 elements"); + +$it = slideatatime 2, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'c d e', 'e f g', 'g']), 1, "slideatatime moving 3 elements by 2 items"); + +$it = slideatatime 1, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'b c d', 'c d e', 'd e f', 'e f g', 'f g', 'g']), 1, "slideatatime moving 3 elements by 1 item"); + +my @a = (1 .. 1000); +$it = slideatatime 1, 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "slideatatime as natatime with 1 element"); + +leak_free_ok( + slideatatime => sub { + my @y = 1; + my $it = slideatatime 2, 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + }, + 'slideatatime with exception' => sub { + my @r; + eval { + my $it = slideatatime 1, 3, @x; + while (my @vals = $it->()) + { + scalar @vals == 3 or die; + push @r, "@vals"; + } + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/slide.pm liblist-moreutils-perl-0.430/t/inline/slide.pm --- liblist-moreutils-perl-0.416/t/inline/slide.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/slide.pm 2020-10-02 06:23:17.000000000 +0000 @@ -0,0 +1,11 @@ + +use Test::More; +use Test::LMU; + +# use case provided my Michael Schwern +my @ol = (0 .. 3); +is(join(", ", slide { "$a and $b" } @ol), "0 and 1, 1 and 2, 2 and 3", "M. Schwern requested example"); + +is_dying('slide without sub' => sub { &slide(0 .. 3); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/true.pm liblist-moreutils-perl-0.430/t/inline/true.pm --- liblist-moreutils-perl-0.416/t/inline/true.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/true.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,25 @@ + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = true {}; +my @null_list = true {}; +is($null_scalar, 0, 'true(null) returns undef'); +is_deeply(\@null_list, [0], 'true(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, true { defined } @list); +is(0, true { not defined } @list); +is(1, true { $_ == 5000 } @list); + +leak_free_ok( + true => sub { + my $n = true { $_ == 5000 } @list; + my $n2 = true { $_ == 5000 } 1 .. 10000; + } +); +is_dying('true without sub' => sub { &true(42, 4711); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/uniq.pm liblist-moreutils-perl-0.430/t/inline/uniq.pm --- liblist-moreutils-perl-0.416/t/inline/uniq.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/uniq.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,91 @@ +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *distinct = __PACKAGE__->can("uniq"); +} + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, [1 .. 10]); + my $u = uniq @a; + is(10, $u); +} + +# Test aliases +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = distinct @a; + is_deeply(\@u, [1 .. 10]); + my $u = distinct @a; + is(10, $u); +} + +# Test strings +SCOPE: +{ + my @a = map { ("a" .. "z") } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, ["a" .. "z"]); + my $u = uniq @a; + is(26, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $fa = freeze(\@a); + my @u = uniq map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + is($fa, freeze(\@a)); + is($fu, freeze([1 .. 10, "a" .. "z"])); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my @u = uniq @a; + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @ufoo = ('a', 'b', '', undef, 'c'); + is_deeply([uniq @foo], \@ufoo, 'undef is supported correctly'); +} + +leak_free_ok( + uniq => sub { + my @a = map { (1 .. 1000) } 0 .. 1; + my @u = uniq @a; + uniq @a[1 .. 100]; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'uniq with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = uniq "foo", $obj, "bar", $obj; + }; + } +); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/upper_bound.pm liblist-moreutils-perl-0.430/t/inline/upper_bound.pm --- liblist-moreutils-perl-0.416/t/inline/upper_bound.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/upper_bound.pm 2020-10-05 09:09:30.000000000 +0000 @@ -0,0 +1,54 @@ + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (upper_bound { $_ <=> 0 } @list), "upper bound 0"); +is(2, (upper_bound { $_ <=> 1 } @list), "upper bound 1"); +is(4, (upper_bound { $_ <=> 2 } @list), "upper bound 2"); +is(14, (upper_bound { $_ <=> 4 } @list), "upper bound 4"); +is(scalar @list, (upper_bound { $_ <=> 19 } @list), "upper bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i, (upper_bound { $_ - $j } @list), "placed $j"); + is($i + 1, (upper_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (upper_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (upper_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + upper_bound => sub { + my $elem = int(rand(1000)) + 1; + upper_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + upper_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + upper_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('upper_bound without sub' => sub { &upper_bound(42, (1 .. 100)); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/inline/XS.pm liblist-moreutils-perl-0.430/t/inline/XS.pm --- liblist-moreutils-perl-0.416/t/inline/XS.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/XS.pm 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,37 @@ + +use Test::More; +$INC{'List/MoreUtils.pm'} or plan skip_all => "Unreasonable unless loaded via List::MoreUtils"; + +is(List::MoreUtils::_XScompiled(), 0 + defined($INC{'List/MoreUtils/XS.pm'}), "_XScompiled"); + +done_testing(); + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. + +=cut diff -Nru liblist-moreutils-perl-0.416/t/inline/zip6.pm liblist-moreutils-perl-0.430/t/inline/zip6.pm --- liblist-moreutils-perl-0.416/t/inline/zip6.pm 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/inline/zip6.pm 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,49 @@ + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + is_deeply(\@z, [['a', 1], ['b', 2], ['c', 3], ['d', 4]], "zip6 two lists with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip6 @a, @b, @c; + is_deeply( + \@z, + [['x', 1, 'zip'], [undef, 2, 'zap'], [undef, undef, 'zot']], + "zip6 three list with increasing count of elements" + ); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = zip6 @a, @d; + is_deeply( + \@z, + [[1, undef], [2, undef], [3, undef], [4, undef], [5, undef], [6, undef], [7, undef], [8, undef], [9, undef], [10, undef]], + "zip6 one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + zip6 => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + } +); +is_dying('zip6 with a list, not at least two arrays' => sub { &zip6(1, 2); }); + +done_testing; diff -Nru liblist-moreutils-perl-0.416/t/lib/LMU/Test/ab.pm liblist-moreutils-perl-0.430/t/lib/LMU/Test/ab.pm --- liblist-moreutils-perl-0.416/t/lib/LMU/Test/ab.pm 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/lib/LMU/Test/ab.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ -package LMU::Test::ab; - -use strict; - -BEGIN -{ - $| = 1; -} - -use Test::More; -use List::MoreUtils 'pairwise'; - -sub run_tests -{ - test_ab(); - done_testing(); -} - -sub test_ab -{ - my @A = ( 1, 2, 3, 4, 5 ); - my @B = ( 2, 4, 6, 8, 10 ); - my @C = pairwise { $a + $b } @A, @B; - is_deeply( \@C, [ 3, 6, 9, 12, 15 ], "pw1" ); -} - -1; diff -Nru liblist-moreutils-perl-0.416/t/lib/LMU/Test/Functions.pm liblist-moreutils-perl-0.430/t/lib/LMU/Test/Functions.pm --- liblist-moreutils-perl-0.416/t/lib/LMU/Test/Functions.pm 2016-04-13 09:12:29.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/lib/LMU/Test/Functions.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,1540 +0,0 @@ -package LMU::Test::Functions; - -use strict; -use warnings; - -use Test::More; -use Test::LMU; -use Tie::Array (); -use List::MoreUtils ':all'; - -use Config; - -my $have_scalar_util; -eval "use Scalar::Util qw(); \$have_scalar_util = 1;"; - -eval "use Storable qw();"; -$@ or Storable->import(qw(freeze)); -__PACKAGE__->can("freeze") or eval <<'EOFR'; -use inc::latest 'JSON::PP'; -use JSON::PP qw(); -sub freeze { - my $json = JSON::PP->new(); - $json->encode($_[0]); -} -EOFR - -# Run all tests -sub run_tests -{ - test_any(); - test_all(); - test_none(); - test_notall(); - test_one(); - test_any_u(); - test_all_u(); - test_none_u(); - test_notall_u(); - test_one_u(); - test_true(); - test_false(); - test_firstidx(); - test_lastidx(); - test_onlyidx(); - test_insert_after(); - test_insert_after_string(); - test_apply(); - test_indexes(); - test_before(); - test_before_incl(); - test_after(); - test_after_incl(); - test_firstval(); - test_lastval(); - test_onlyval(); - test_firstres(); - test_lastres(); - test_onlyres(); - test_each_array(); - test_pairwise(); - test_natatime(); - test_zip(); - test_mesh(); - test_uniq(); - test_singleton(); - test_part(); - test_minmax(); - test_bsearch(); - test_bsearchidx(); - - done_testing(); -} - -###################################################################### -# Test code intentionally ignorant of implementation (Pure Perl or XS) - -# The any function should behave identically to -# !! grep CODE LIST -sub test_any_u -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( any_u { $_ == 5000 } @list ); - is_true( any_u { $_ == 5000 } 1 .. 10000 ); - is_true( any_u { defined } @list ); - is_false( any_u { not defined } @list ); - is_true( any_u { not defined } undef ); - is_undef( any_u {} ); - - leak_free_ok( - any_u => sub { - my $ok = any_u { $_ == 5000 } @list; - my $ok2 = any_u { $_ == 5000 } 1 .. 10000; - } - ); - leak_free_ok( - 'any_u with a coderef that dies' => sub { - # This test is from Kevin Ryde; see RT#48669 - eval { - my $ok = any_u { die } 1; - }; - } - ); - is_dying( sub { &any_u( 42, 4711 ); } ); -} - -sub test_all_u -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( all_u { defined } @list ); - is_true( all_u { $_ > 0 } @list ); - is_false( all_u { $_ < 5000 } @list ); - is_undef( all_u {} ); - - leak_free_ok( - all_u => sub { - my $ok = all_u { $_ == 5000 } @list; - my $ok2 = all_u { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &all_u( 42, 4711 ); } ); -} - -sub test_none_u -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( none_u { not defined } @list ); - is_true( none_u { $_ > 10000 } @list ); - is_false( none_u { defined } @list ); - is_undef( none_u {} ); - - leak_free_ok( - none_u => sub { - my $ok = none_u { $_ == 5000 } @list; - my $ok2 = none_u { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &none_u( 42, 4711 ); } ); -} - -sub test_notall_u -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( notall_u { !defined } @list ); - is_true( notall_u { $_ < 10000 } @list ); - is_false( notall_u { $_ <= 10000 } @list ); - is_undef( notall_u {} ); - - leak_free_ok( - notall_u => sub { - my $ok = notall_u { $_ == 5000 } @list; - my $ok2 = notall_u { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { ¬all_u( 42, 4711 ); } ); -} - -sub test_one_u -{ - # Normal cases - my @list = ( 1 .. 300 ); - is_true( one_u { 1 == $_ } @list ); - is_true( one_u { 150 == $_ } @list ); - is_true( one_u { 300 == $_ } @list ); - is_false( one_u { 0 == $_ } @list ); - is_false( one_u { 1 <= $_ } @list ); - is_false( one_u { !( 127 & $_ ) } @list ); - is_undef( one_u {} ); - - leak_free_ok( - one => sub { - my $ok = one_u { 150 <= $_ } @list; - my $ok2 = one_u { 150 <= $_ } 1 .. 300; - } - ); - is_dying( sub { &one_u( 42, 4711 ); } ); -} - -sub test_true -{ - # The null set should return zero - my $null_scalar = true {}; - my @null_list = true {}; - is( $null_scalar, 0, 'true(null) returns undef' ); - is_deeply( \@null_list, [0], 'true(null) returns undef' ); - - # Normal cases - my @list = ( 1 .. 10000 ); - is( 10000, true { defined } @list ); - is( 0, true { not defined } @list ); - is( 1, true { $_ == 5000 } @list ); - - leak_free_ok( - true => sub { - my $n = true { $_ == 5000 } @list; - my $n2 = true { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &true( 42, 4711 ); } ); -} - -sub test_false -{ - # The null set should return zero - my $null_scalar = false {}; - my @null_list = false {}; - is( $null_scalar, 0, 'false(null) returns undef' ); - is_deeply( \@null_list, [0], 'false(null) returns undef' ); - - # Normal cases - my @list = ( 1 .. 10000 ); - is( 10000, false { not defined } @list ); - is( 0, false { defined } @list ); - is( 1, false { $_ > 1 } @list ); - - leak_free_ok( - false => sub { - my $n = false { $_ == 5000 } @list; - my $n2 = false { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &false( 42, 4711 ); } ); -} - -sub test_firstidx -{ - my @list = ( 1 .. 10000 ); - is( 4999, ( firstidx { $_ >= 5000 } @list ), "firstidx" ); - is( -1, ( firstidx { not defined } @list ), "invalid firstidx" ); - is( 0, ( firstidx { defined } @list ), "real firstidx" ); - is( -1, ( firstidx {} ), "empty firstidx" ); - - # Test the alias - is( 4999, first_index { $_ >= 5000 } @list ); - is( -1, first_index { not defined } @list ); - is( 0, first_index { defined } @list ); - is( -1, first_index {} ); - - leak_free_ok( - firstidx => sub { - my $i = firstidx { $_ >= 5000 } @list; - my $i2 = firstidx { $_ >= 5000 } 1 .. 10000; - } - ); - is_dying( sub { &firstidx( 42, 4711 ); } ); -} - -sub test_lastidx -{ - my @list = ( 1 .. 10000 ); - is( 9999, lastidx { $_ >= 5000 } @list ); - is( -1, lastidx { not defined } @list ); - is( 9999, lastidx { defined } @list ); - is( -1, lastidx {} ); - - # Test aliases - is( 9999, last_index { $_ >= 5000 } @list ); - is( -1, last_index { not defined } @list ); - is( 9999, last_index { defined } @list ); - is( -1, last_index {} ); - - leak_free_ok( - lastidx => sub { - my $i = lastidx { $_ >= 5000 } @list; - my $i2 = lastidx { $_ >= 5000 } 1 .. 10000; - } - ); - is_dying( sub { &lastidx( 42, 4711 ); } ); -} - -sub test_onlyidx -{ - my @list = ( 1 .. 300 ); - is( 0, onlyidx { 1 == $_ } @list ); - is( 149, onlyidx { 150 == $_ } @list ); - is( 299, onlyidx { 300 == $_ } @list ); - is( -1, onlyidx { 0 == $_ } @list ); - is( -1, onlyidx { 1 <= $_ } @list ); - is( -1, onlyidx { !( 127 & $_ ) } @list ); - - # Test aliases - is( 0, only_index { 1 == $_ } @list ); - is( 149, only_index { 150 == $_ } @list ); - is( 299, only_index { 300 == $_ } @list ); - is( -1, only_index { 0 == $_ } @list ); - is( -1, only_index { 1 <= $_ } @list ); - is( -1, only_index { !( 127 & $_ ) } @list ); - - leak_free_ok( - onlyidx => sub { - my $ok = onlyidx { 150 <= $_ } @list; - my $ok2 = onlyidx { 150 <= $_ } 1 .. 300; - } - ); - is_dying( sub { &onlyidx( 42, 4711 ); } ); -} - -sub test_insert_after -{ - my @list = qw{This is a list}; - insert_after { $_ eq "a" } "longer" => @list; - is( join( ' ', @list ), "This is a longer list" ); - insert_after { 0 } "bla" => @list; - is( join( ' ', @list ), "This is a longer list" ); - insert_after { $_ eq "list" } "!" => @list; - is( join( ' ', @list ), "This is a longer list !" ); - @list = ( qw{This is}, undef, qw{list} ); - insert_after { not defined($_) } "longer" => @list; - $list[2] = "a"; - is( join( ' ', @list ), "This is a longer list" ); - - leak_free_ok( - insert_after => sub { - @list = qw{This is a list}; - insert_after { $_ eq 'a' } "longer" => @list; - } - ); - is_dying( sub { &insert_after( 42, 4711, [qw(die bart die)] ); } ); - is_dying( sub { &insert_after( 42, 4711, "13" ); } ); - is_dying( - sub { - &insert_after( sub { }, 4711, "13" ); - } - ); -} - -sub test_insert_after_string -{ - my @list = qw{This is a list}; - insert_after_string "a", "longer" => @list; - is( join( ' ', @list ), "This is a longer list" ); - @list = ( undef, qw{This is a list} ); - insert_after_string "a", "longer", @list; - shift @list; - is( join( ' ', @list ), "This is a longer list" ); - @list = ( "This\0", "is\0", "a\0", "list\0" ); - insert_after_string "a\0", "longer\0", @list; - is( join( ' ', @list ), "This\0 is\0 a\0 longer\0 list\0" ); - - leak_free_ok( - insert_after_string => sub { - @list = qw{This is a list}; - insert_after_string "a", "longer", @list; - } - ); - is_dying( sub { &insert_after_string( 42, 4711, "13" ); } ); -} - -sub test_apply -{ - # Test the null case - my $null_scalar = apply {}; - is( $null_scalar, undef, 'apply(null) returns undef' ); - - my @null_list = apply {}; - is_deeply( \@null_list, [], 'apply(null) returns null list' ); - - # Normal cases - my @list = ( 0 .. 9 ); - my @list1 = apply { $_++ } @list; - ok( is_deeply( \@list, [ 0 .. 9 ] ) ); - ok( is_deeply( \@list1, [ 1 .. 10 ] ) ); - @list = ( " foo ", " bar ", " ", "foobar" ); - @list1 = apply { s/^\s+|\s+$//g } @list; - ok( is_deeply( \@list, [ " foo ", " bar ", " ", "foobar" ] ) ); - ok( is_deeply( \@list1, [ "foo", "bar", "", "foobar" ] ) ); - my $item = apply { s/^\s+|\s+$//g } @list; - is( $item, "foobar" ); - - # RT 38630 - SCOPE: - { - # wrong results from apply() [XS] - @list = ( 1 .. 4 ); - @list1 = apply - { - grow_stack(); - $_ = 5; - } - @list; - ok( is_deeply( \@list, [ 1 .. 4 ] ) ); - ok( is_deeply( \@list1, [ (5) x 4 ] ) ); - } - - leak_free_ok( - apply => sub { - @list = ( 1 .. 4 ); - @list1 = apply - { - grow_stack(); - $_ = 5; - } - @list; - } - ); - is_dying( sub { &apply( 42, 4711 ); } ); -} - -sub test_indexes -{ - my @x = indexes { $_ > 5 } ( 4 .. 9 ); - ok( is_deeply( \@x, [ 2 .. 5 ] ) ); - @x = indexes { $_ > 5 } ( 1 .. 4 ); - is_deeply( \@x, [], 'Got the null list' ); - - my ( $lr, @s, @n, @o, @e ); - leak_free_ok( - indexes => sub { - $lr = 1; - @s = indexes { $_ > 5 } ( 4 .. 9 ); - @n = indexes { $_ > 5 } ( 1 .. 5 ); - @o = indexes { $_ & 1 } ( 10 .. 15 ); - @e = indexes { !( $_ & 1 ) } ( 10 .. 15 ); - } - ); - $lr and is_deeply( \@s, [ 2 .. 5 ], "indexes/leak: some" ); - $lr and is_deeply( \@n, [], "indexes/leak: none" ); - $lr and is_deeply( \@o, [ 1, 3, 5 ], "indexes/leak: odd" ); - $lr and is_deeply( \@e, [ 0, 2, 4 ], "indexes/leak: even" ); - - leak_free_ok( - indexes => sub { - @s = indexes { grow_stack; $_ > 5 } ( 4 .. 9 ); - @n = indexes { grow_stack; $_ > 5 } ( 1 .. 4 ); - @o = indexes { grow_stack; $_ & 1 } ( 10 .. 15 ); - @e = indexes { grow_stack; !( $_ & 1 ) } ( 10 .. 15 ); - } - ); - - $lr and is_deeply( \@s, [ 2 .. 5 ], "indexes/leak: some" ); - $lr and is_deeply( \@n, [], "indexes/leak: none" ); - $lr and is_deeply( \@o, [ 1, 3, 5 ], "indexes/leak: odd" ); - $lr and is_deeply( \@e, [ 0, 2, 4 ], "indexes/leak: even" ); - - if ($have_scalar_util) - { - my $ref = \( indexes( sub { 1 }, 123 ) ); - Scalar::Util::weaken($ref); - is( $ref, undef, "weakened away" ); - } - is_dying( sub { &indexes( 42, 4711 ); } ); -} - -# In the following, the @dummy variable is needed to circumvent -# a parser glitch in the 5.6.x series. -sub test_before -{ - my @x = before { $_ % 5 == 0 } 1 .. 9; - ok( is_deeply( \@x, [ 1, 2, 3, 4 ] ) ); - @x = before { /b/ } my @dummy = qw{ bar baz }; - is_deeply( \@x, [], 'Got the null list' ); - @x = before { /f/ } @dummy = qw{ bar baz foo }; - ok( is_deeply( \@x, [qw{ bar baz }] ) ); - - leak_free_ok( - before => sub { - @x = before { /f/ } @dummy = qw{ bar baz foo }; - } - ); - is_dying( sub { &before( 42, 4711 ); } ); -} - -# In the following, the @dummy variable is needed to circumvent -# a parser glitch in the 5.6.x series. -sub test_before_incl -{ - my @x = before_incl { $_ % 5 == 0 } 1 .. 9; - ok( is_deeply( \@x, [ 1, 2, 3, 4, 5 ] ) ); - @x = before_incl { /foo/ } my @dummy = qw{ bar baz }; - ok( is_deeply( \@x, [qw{ bar baz }] ) ); - @x = before_incl { /f/ } @dummy = qw{ bar baz foo }; - ok( is_deeply( \@x, [qw{ bar baz foo }] ) ); - - leak_free_ok( - before_incl => sub { - @x = before_incl { /z/ } @dummy = qw{ bar baz foo }; - } - ); - is_dying( sub { &before_incl( 42, 4711 ); } ); -} - -# In the following, the @dummy variable is needed to circumvent -# a parser glitch in the 5.6.x series. -sub test_after -{ - my @x = after { $_ % 5 == 0 } 1 .. 9; - ok( is_deeply( \@x, [ 6, 7, 8, 9 ] ) ); - @x = after { /foo/ } my @dummy = qw{ bar baz }; - is_deeply( \@x, [], 'Got the null list' ); - @x = after { /b/ } @dummy = qw{ bar baz foo }; - ok( is_deeply( \@x, [qw{ baz foo }] ) ); - - leak_free_ok( - after => sub { - @x = after { /z/ } @dummy = qw{ bar baz foo }; - } - ); - is_dying( sub { &after( 42, 4711 ); } ); - - @x = ( 1, after { /foo/ } qw(abc def) ); - is_deeply(\@x, [ 1 ], "check XS implementation doesn't mess up stack"); -} - -# In the following, the @dummy variable is needed to circumvent -# a parser glitch in the 5.6.x series. -sub test_after_incl -{ - my @x = after_incl { $_ % 5 == 0 } 1 .. 9; - ok( is_deeply( \@x, [ 5, 6, 7, 8, 9 ] ) ); - @x = after_incl { /foo/ } my @dummy = qw{ bar baz }; - is_deeply( \@x, [], 'Got the null list' ); - @x = after_incl { /b/ } @dummy = qw{ bar baz foo }; - ok( is_deeply( \@x, [qw{ bar baz foo }] ) ); - - leak_free_ok( - after_incl => sub { - @x = after_incl { /z/ } @dummy = qw{ bar baz foo }; - } - ); - is_dying( sub { &after_incl( 42, 4711 ); } ); -} - -sub test_firstval -{ - my $x = firstval { $_ > 5 } 4 .. 9; - is( $x, 6 ); - $x = firstval { $_ > 5 } 1 .. 4; - is( $x, undef ); - is_undef( firstval { $_ > 5 } ); - - # Test aliases - $x = first_value { $_ > 5 } 4 .. 9; - is( $x, 6 ); - $x = first_value { $_ > 5 } 1 .. 4; - is( $x, undef ); - - leak_free_ok( - firstval => sub { - $x = firstval { $_ > 5 } 4 .. 9; - } - ); - is_dying( sub { &firstval( 42, 4711 ); } ); -} - -sub test_onlyval -{ - my @list = ( 1 .. 300 ); - is( 1, onlyval { 1 == $_ } @list ); - is( 150, onlyval { 150 == $_ } @list ); - is( 300, onlyval { 300 == $_ } @list ); - is( undef, onlyval { 0 == $_ } @list ); - is( undef, onlyval { 1 <= $_ } @list ); - is( undef, onlyval { !( 127 & $_ ) } @list ); - - # Test aliases - is( 1, only_value { 1 == $_ } @list ); - is( 150, only_value { 150 == $_ } @list ); - is( 300, only_value { 300 == $_ } @list ); - is( undef, only_value { 0 == $_ } @list ); - is( undef, only_value { 1 <= $_ } @list ); - is( undef, only_value { !( 127 & $_ ) } @list ); - - leak_free_ok( - onlyval => sub { - my $ok = onlyval { 150 <= $_ } @list; - my $ok2 = onlyval { 150 <= $_ } 1 .. 300; - } - ); - is_dying( sub { &onlyval( 42, 4711 ); } ); -} - -sub test_lastval -{ - my $x = lastval { $_ > 5 } 4 .. 9; - is( $x, 9 ); - $x = lastval { $_ > 5 } 1 .. 4; - is( $x, undef ); - is_undef( lastval { $_ > 5 } ); - - # Test aliases - $x = last_value { $_ > 5 } 4 .. 9; - is( $x, 9 ); - $x = last_value { $_ > 5 } 1 .. 4; - is( $x, undef ); - - leak_free_ok( - lastval => sub { - $x = lastval { $_ > 5 } 4 .. 9; - } - ); - is_dying( sub { &lastval( 42, 4711 ); } ); -} - -sub test_firstres -{ - my $x = firstres { 2 * ( $_ > 5 ) } 4 .. 9; - is( $x, 2 ); - $x = firstres { $_ > 5 } 1 .. 4; - is( $x, undef ); - - # Test aliases - $x = first_result { $_ > 5 } 4 .. 9; - is( $x, 1 ); - $x = first_result { $_ > 5 } 1 .. 4; - is( $x, undef ); - - leak_free_ok( - firstres => sub { - $x = firstres { $_ > 5 } 4 .. 9; - } - ); - is_dying( sub { &firstres( 42, 4711 ); } ); -} - -sub test_lastres -{ - my $x = lastres { 2 * ( $_ > 5 ) } 4 .. 9; - is( $x, 2 ); - $x = lastres { $_ > 5 } 1 .. 4; - is( $x, undef ); - - # Test aliases - $x = last_result { $_ > 5 } 4 .. 9; - is( $x, 1 ); - $x = last_result { $_ > 5 } 1 .. 4; - is( $x, undef ); - - leak_free_ok( - lastres => sub { - $x = lastres { $_ > 5 } 4 .. 9; - } - ); - is_dying( sub { &lastres( 42, 4711 ); } ); -} - -sub test_onlyres -{ - my @list = ( 1 .. 300 ); - is( "Hallelujah", onlyres { 150 == $_ and "Hallelujah" } @list ); - is( 1, onlyres { 300 == $_ } @list ); - is( undef, onlyres { 0 == $_ } @list ); - is( undef, onlyres { 1 <= $_ } @list ); - is( undef, onlyres { !( 127 & $_ ) } @list ); - - # Test aliases - is( 1, only_result { 150 == $_ } @list ); - is( "Hallelujah", only_result { 300 == $_ and "Hallelujah" } @list ); - is( undef, only_result { 0 == $_ } @list ); - is( undef, only_result { 1 <= $_ } @list ); - is( undef, only_result { !( 127 & $_ ) } @list ); - - leak_free_ok( - onlyres => sub { - my $ok = onlyres { 150 <= $_ } @list; - my $ok2 = onlyres { 150 <= $_ } 1 .. 300; - } - ); - is_dying( sub { &onlyres( 42, 4711 ); } ); -} - -sub test_each_array -{ - SCOPE: - { - my @a = ( 7, 3, 'a', undef, 'r' ); - my @b = qw{ a 2 -1 x }; - my $it = each_array @a, @b; - my ( @r, @idx ); - while ( my ( $a, $b ) = $it->() ) - { - push @r, $a, $b; - push @idx, $it->('index'); - } - - # Do I segfault? I shouldn't. - $it->(); - - ok( is_deeply( \@r, [ 7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef ] ) ); - ok( is_deeply( \@idx, [ 0 .. 4 ] ) ); - - # Testing two iterators on the same arrays in parallel - @a = ( 1, 3, 5 ); - @b = ( 2, 4, 6 ); - my $i1 = each_array @a, @b; - my $i2 = each_array @a, @b; - @r = (); - while ( my ( $a, $b ) = $i1->() and my ( $c, $d ) = $i2->() ) - { - push @r, $a, $b, $c, $d; - } - ok( is_deeply( \@r, [ 1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6 ] ) ); - - # Input arrays must not be modified - ok( is_deeply( \@a, [ 1, 3, 5 ] ) ); - ok( is_deeply( \@b, [ 2, 4, 6 ] ) ); - - # This used to give "semi-panic: attempt to dup freed string" - # See: - my $ea = each_arrayref( [ 1 .. 26 ], [ 'A' .. 'Z' ] ); - ( @a, @b ) = (); - while ( my ( $a, $b ) = $ea->() ) - { - push @a, $a; - push @b, $b; - } - ok( is_deeply( \@a, [ 1 .. 26 ] ) ); - ok( is_deeply( \@b, [ 'A' .. 'Z' ] ) ); - - # And this even used to dump core - my @nums = 1 .. 26; - $ea = each_arrayref( \@nums, [ 'A' .. 'Z' ] ); - ( @a, @b ) = (); - while ( my ( $a, $b ) = $ea->() ) - { - push @a, $a; - push @b, $b; - } - ok( is_deeply( \@a, [ 1 .. 26 ] ) ); - ok( is_deeply( \@a, \@nums ) ); - ok( is_deeply( \@b, [ 'A' .. 'Z' ] ) ); - } - - SCOPE: - { - my @a = ( 7, 3, 'a', undef, 'r' ); - my @b = qw/a 2 -1 x/; - - my $it = each_arrayref \@a, \@b; - my ( @r, @idx ); - while ( my ( $a, $b ) = $it->() ) - { - push @r, $a, $b; - push @idx, $it->('index'); - } - - # Do I segfault? I shouldn't. - $it->(); - - ok( is_deeply( \@r, [ 7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef ] ) ); - ok( is_deeply( \@idx, [ 0 .. 4 ] ) ); - - # Testing two iterators on the same arrays in parallel - @a = ( 1, 3, 5 ); - @b = ( 2, 4, 6 ); - my $i1 = each_array @a, @b; - my $i2 = each_array @a, @b; - @r = (); - while ( my ( $a, $b ) = $i1->() and my ( $c, $d ) = $i2->() ) - { - push @r, $a, $b, $c, $d; - } - ok( is_deeply( \@r, [ 1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6 ] ) ); - - # Input arrays must not be modified - ok( is_deeply( \@a, [ 1, 3, 5 ] ) ); - ok( is_deeply( \@b, [ 2, 4, 6 ] ) ); - } - - # Note that the leak_free_ok tests for each_array and each_arrayref - # should not be run until either of them has been called at least once - # in the current perl. That's because calling them the first time - # causes the runtime to allocate some memory used for the OO structures - # that their implementation uses internally. - leak_free_ok( - each_array => sub { - my @a = (1); - my $it = each_array @a; - while ( my ($a) = $it->() ) - { - } - } - ); - leak_free_ok( - each_arrayref => sub { - my @a = (1); - my $it = each_arrayref \@a; - while ( my ($a) = $it->() ) - { - } - } - ); - is_dying( sub { &each_array( 42, 4711 ); } ); - is_dying( sub { &each_arrayref( 42, 4711 ); } ); -} - -sub test_pairwise -{ - my @a = ( 1, 2, 3, 4, 5 ); - my @b = ( 2, 4, 6, 8, 10 ); - my @c = pairwise { $a + $b } @a, @b; - is_deeply( \@c, [ 3, 6, 9, 12, 15 ], "pw1" ); - - @c = pairwise { $a * $b } @a, @b; # returns (2, 8, 18) - is_deeply( \@c, [ 2, 8, 18, 32, 50 ], "pw2" ); - - # Did we modify the input arrays? - is_deeply( \@a, [ 1, 2, 3, 4, 5 ], "pw3" ); - is_deeply( \@b, [ 2, 4, 6, 8, 10 ], "pw4" ); - - # $a and $b should be aliases: test - @b = @a = ( 1, 2, 3 ); - @c = pairwise { $a++; $b *= 2 } @a, @b; - is_deeply( \@a, [ 2, 3, 4 ], "pw5" ); - is_deeply( \@b, [ 2, 4, 6 ], "pw6" ); - is_deeply( \@c, [ 2, 4, 6 ], "pw7" ); - - # sub returns more than two items - @a = ( 1, 1, 2, 3, 5 ); - @b = ( 2, 3, 5, 7, 11 ); - @c = pairwise { ($a) x $b } @a, @b; - is_deeply( \@c, [ (1) x 2, (1) x 3, (2) x 5, (3) x 7, (5) x 11 ], "pw8" ); - - - ( @a, @b ) = (); - push @a, int rand(1000) for 0 .. rand(1000); - push @b, int rand(1000) for 0 .. rand(1000); - SCOPE: - { - local $SIG{__WARN__} = sub { }; # XXX - my @res1 = pairwise { $a + $b } @a, @b; - # Test this one more thoroughly: the XS code looks flakey - # correctness of pairwise_perl proved by human auditing. :-) - my $limit = $#a > $#b ? $#a : $#b; - my @res2 = map { $a[$_] + $b[$_] } 0 .. $limit; - is_deeply( \@res1, \@res2 ); - } - - @a = qw/a b c/; - @b = qw/1 2 3/; - @c = pairwise { ( $a, $b ) } @a, @b; - is_deeply( \@c, [qw/a 1 b 2 c 3/], "pw map" ); - - SKIP: - { - $ENV{PERL5OPT} and skip 'A defined PERL5OPT may inject extra deps crashing this test', 1; - # Test that a die inside the code-reference will not be trapped - eval { - pairwise { die "I died\n" } @a, @b; - }; - is( $@, "I died\n" ); - } - - leak_free_ok( - pairwise => sub { - @a = (1); - @b = (2); - @c = pairwise { $a + $b } @a, @b; - } - ); - @a = qw/a b c/; - @b = qw/1 2 3/; - - SKIP: - { - List::MoreUtils::_XScompiled or skip "PurePerl will warn here ...", 1; - my ( $a, $b, @t ); - eval { - my @l1 = ( 1 .. 10 ); - @t = pairwise { $a + $b } @l1, @l1; - }; - my $err = $@; - like( $err, qr/Can't use lexical \$a or \$b in pairwise code block/, "pairwise die's on broken caller" ); - } - - SKIP: - { - List::MoreUtils::_XScompiled and skip "XS will die on purpose here ...", 1; - my @warns = (); - local $SIG{__WARN__} = sub { push @warns, @_ }; - my ( $a, $b, @t ); - my @l1 = ( 1 .. 10 ); - @t = pairwise { $a + $b } @l1, @l1; - like( join( "", @warns[ 0, 1 ] ), qr/Use of uninitialized value.*? in addition/, "warning on broken caller" ); - } - - is_dying( sub { &pairwise( 42, \@a, \@b ); } ); - SKIP: - { - List::MoreUtils::_XScompiled or skip "PurePerl will not core here ...", 2; - is_dying( - sub { - @c = &pairwise( sub { }, 1, \@b ); - } - ); - is_dying( - sub { - @c = &pairwise( sub { }, \@a, 2 ); - } - ); - } -} - -sub test_natatime -{ - my @x = ( 'a' .. 'g' ); - my $it = natatime 3, @x; - my @r; - local $" = " "; - while ( my @vals = $it->() ) - { - push @r, "@vals"; - } - is( is_deeply( \@r, [ 'a b c', 'd e f', 'g' ] ), 1, "natatime1" ); - - my @a = ( 1 .. 1000 ); - $it = natatime 1, @a; - @r = (); - while ( my @vals = &$it ) - { - push @r, @vals; - } - is( is_deeply( \@r, \@a ), 1, "natatime2" ); - - leak_free_ok( - natatime => sub { - my @y = 1; - my $it = natatime 2, @y; - while ( my @vals = $it->() ) - { - # do nothing - } - } - ); -} - -sub test_zip -{ - SCOPE: - { - my @x = qw/a b c d/; - my @y = qw/1 2 3 4/; - my @z = zip @x, @y; - ok( is_deeply( \@z, [ 'a', 1, 'b', 2, 'c', 3, 'd', 4 ] ) ); - } - - SCOPE: - { - my @a = ('x'); - my @b = ( '1', '2' ); - my @c = qw/zip zap zot/; - my @z = zip @a, @b, @c; - ok( is_deeply( \@z, [ 'x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot' ] ) ); - } - - SCOPE: - { - # Make array with holes - my @a = ( 1 .. 10 ); - my @d; - $#d = 9; - my @z = zip @a, @d; - ok( - is_deeply( - \@z, [ 1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef, ] - ) - ); - } - - leak_free_ok( - zip => sub { - my @x = qw/a b c d/; - my @y = qw/1 2 3 4/; - my @z = zip @x, @y; - } - ); - is_dying( sub { &zip( 1, 2 ); } ); -} - -sub test_mesh -{ - SCOPE: - { - my @x = qw/a b c d/; - my @y = qw/1 2 3 4/; - my @z = mesh @x, @y; - ok( is_deeply( \@z, [ 'a', 1, 'b', 2, 'c', 3, 'd', 4 ] ) ); - } - - SCOPE: - { - my @a = ('x'); - my @b = ( '1', '2' ); - my @c = qw/zip zap zot/; - my @z = mesh @a, @b, @c; - ok( is_deeply( \@z, [ 'x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot' ] ) ); - } - - # Make array with holes - SCOPE: - { - my @a = ( 1 .. 10 ); - my @d; - $#d = 9; - my @z = mesh @a, @d; - ok( - is_deeply( - \@z, [ 1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef, ] - ) - ); - } - - leak_free_ok( - mesh => sub { - my @x = qw/a b c d/; - my @y = qw/1 2 3 4/; - my @z = mesh @x, @y; - } - ); - is_dying( sub { &mesh( 1, 2 ); } ); -} - -sub test_uniq -{ - SCOPE: - { - my @a = map { ( 1 .. 10 ) } 0 .. 1; - my @u = uniq @a; - is_deeply( \@u, [ 1 .. 10 ] ); - my $u = uniq @a; - is( 10, $u ); - } - - # Test aliases - SCOPE: - { - my @a = map { ( 1 .. 10 ) } 0 .. 1; - my @u = distinct @a; - is_deeply( \@u, [ 1 .. 10 ] ); - my $u = distinct @a; - is( 10, $u ); - } - - # Test strings - SCOPE: - { - my @a = map { ( "a" .. "z" ) } 0 .. 1; - my @u = uniq @a; - is_deeply( \@u, [ "a" .. "z" ] ); - my $u = uniq @a; - is( 26, $u ); - } - - # Test mixing strings and numbers - SCOPE: - { - my @a = ( ( map { ( 1 .. 10 ) } 0 .. 1 ), ( map { ( "a" .. "z" ) } 0 .. 1 ) ); - my $fa = freeze( \@a ); - my @u = uniq map { $_ } @a; - my $fu = freeze( \@u ); - is_deeply( \@u, [ 1 .. 10, "a" .. "z" ] ); - is( $fa, freeze( \@a ) ); - is( $fu, freeze( [ 1 .. 10, "a" .. "z" ] ) ); - my $u = uniq @a; - is( 10 + 26, $u ); - } - - SCOPE: - { - my @a; - tie @a, "Tie::StdArray"; - @a = ( ( map { ( 1 .. 10 ) } 0 .. 1 ), ( map { ( "a" .. "z" ) } 0 .. 1 ) ); - my @u = uniq @a; - is_deeply( \@u, [ 1 .. 10, "a" .. "z" ] ); - @a = ( ( map { ( 1 .. 10 ) } 0 .. 1 ), ( map { ( "a" .. "z" ) } 0 .. 1 ) ); - my $u = uniq @a; - is( 10 + 26, $u ); - } - - SCOPE: - { - my @foo = ( 'a', 'b', '', undef, 'b', 'c', '' ); - my @ufoo = ( 'a', 'b', '', undef, 'c' ); - is_deeply( [ uniq @foo ], \@ufoo, 'undef is supported correctly' ); - } - - leak_free_ok( - uniq => sub { - my @a = map { ( 1 .. 1000 ) } 0 .. 1; - my @u = uniq @a; - uniq @a[ 1 .. 100 ]; - } - ); - - # This test (and the associated fix) are from Kevin Ryde; see RT#49796 - leak_free_ok( - 'uniq with exception in overloading stringify', - sub { - eval { - my $obj = DieOnStringify->new; - my @u = uniq $obj, $obj; - }; - eval { - my $obj = DieOnStringify->new; - my $u = uniq $obj, $obj; - }; - } - ); -} - -sub test_singleton -{ - SCOPE: - { - my @s = ( 1001 .. 1200 ); - my @d = map { ( 1 .. 1000 ) } 0 .. 1; - my @a = ( @d, @s ); - my @u = singleton @a; - is_deeply( \@u, [@s] ); - my $u = singleton @a; - is( 200, $u ); - } - - # Test strings - SCOPE: - { - my @s = ( "AA" .. "ZZ" ); - my @d = map { ( "aa" .. "zz" ) } 0 .. 1; - my @a = ( @d, @s ); - my @u = singleton @a; - is_deeply( \@u, [@s] ); - my $u = singleton @a; - is( scalar @s, $u ); - } - - # Test mixing strings and numbers - SCOPE: - { - my @s = ( 1001 .. 1200, "AA" .. "ZZ" ); - my $fs = freeze( \@s ); - my @d = map { ( 1 .. 1000, "aa" .. "zz" ) } 0 .. 1; - my @a = ( @d, @s ); - my $fa = freeze( \@a ); - my @u = singleton map { $_ } @a; - my $fu = freeze( \@u ); - is_deeply( \@u, [@s] ); - is( $fs, freeze( \@s ) ); - is( $fa, freeze( \@a ) ); - is( $fu, $fs ); - my $u = singleton @a; - is( scalar @s, $u ); - } - - SCOPE: - { - my @a; - tie @a, "Tie::StdArray"; - my @s = ( 1001 .. 1200, "AA" .. "ZZ" ); - my @d = map { ( 1 .. 1000, "aa" .. "zz" ) } 0 .. 1; - @a = ( @d, @s ); - my @u = singleton map { $_ } @a; - is_deeply( \@u, [@s] ); - @a = ( @d, @s ); - my $u = singleton @a; - is( scalar @s, $u ); - } - - SCOPE: - { - my @foo = ( 'a', 'b', '', undef, 'b', 'c', '' ); - my @sfoo = ( 'a', undef, 'c' ); - is_deeply( [ singleton @foo ], \@sfoo, 'one undef is supported correctly by singleton' ); - @foo = ( 'a', 'b', '', undef, 'b', 'c', undef ); - @sfoo = ( 'a', '', 'c' ); - is_deeply( [ singleton @foo ], \@sfoo, 'twice undef is supported correctly by singleton' ); - is( ( scalar singleton @foo ), scalar @sfoo, 'scalar twice undef is supported correctly by singleton' ); - } - - leak_free_ok( - uniq => sub { - my @s = ( 1001 .. 1200, "AA" .. "ZZ" ); - my @d = map { ( 1 .. 1000, "aa" .. "zz" ) } 0 .. 1; - my @a = ( @d, @s ); - my @u = singleton @a; - scalar singleton @a; - } - ); - - # This test (and the associated fix) are from Kevin Ryde; see RT#49796 - leak_free_ok( - 'singleton with exception in overloading stringify', - sub { - eval { - my $obj = DieOnStringify->new; - my @u = singleton $obj, $obj; - }; - eval { - my $obj = DieOnStringify->new; - my $u = singleton $obj, $obj; - }; - } - ); -} - -sub test_part -{ - my @list = 1 .. 12; - my $i = 0; - my @part = part { $i++ % 3 } @list; - ok( is_deeply( $part[0], [ 1, 4, 7, 10 ] ) ); - ok( is_deeply( $part[1], [ 2, 5, 8, 11 ] ) ); - ok( is_deeply( $part[2], [ 3, 6, 9, 12 ] ) ); - - $list[2] = 0; - is( $part[2][0], 3, 'Values are not aliases' ); - - @list = 1 .. 12; - @part = part { 3 } @list; - is( $part[0], undef ); - is( $part[1], undef ); - is( $part[2], undef ); - ok( is_deeply( $part[3], [ 1 .. 12 ] ) ); - - eval { - @part = part { -1 } @list; - }; - like( $@, qr/^Modification of non-creatable array value attempted, subscript -1/ ); - - $i = 0; - @part = part { $i++ == 0 ? 0 : -1 } @list; - is_deeply( $part[0], [ 1 .. 12 ], "part with negative indices" ); - - SKIP: - { - List::MoreUtils::_XScompiled and skip "Only PurePerl will warn here ...", 1; - my @warns = (); - local $SIG{__WARN__} = sub { push @warns, [@_] }; - @part = part { undef } @list; - is_deeply( $part[0], [ 1 .. 12 ], "part with undef" ); - like( join( "\n", @{ $warns[0] } ), qr/Use of uninitialized value in array element.*line\s+\d+\.$/, "warning of undef" ); - is_deeply( \@warns, [ ( $warns[0] ) x 12 ], "amount of similar undef warnings" ); - } - - @part = part { 10000 } @list; - ok( is_deeply( $part[10000], [@list] ) ); - is( $part[0], undef ); - is( $part[ @part / 2 ], undef ); - is( $part[9999], undef ); - - # Changing the list in place used to destroy - # its elements due to a wrong refcnt - @list = 1 .. 10; - @list = part { $_ } @list; - foreach ( 1 .. 10 ) - { - ok( is_deeply( $list[$_], [$_] ) ); - } - - leak_free_ok( - part => sub { - my @list = 1 .. 12; - my $i = 0; - my @part = part { $i++ % 3 } @list; - } - ); - - leak_free_ok( - 'part with stack-growing' => sub { - # This test is from Kevin Ryde; see RT#38699 - my @part = part { grow_stack(); 1024 } 'one', 'two'; - } - ); -} - -sub test_minmax -{ - my @list = reverse 0 .. 10000; - my ( $min, $max ) = minmax @list; - is( $min, 0 ); - is( $max, 10000 ); - - # Even number of elements - push @list, 10001; - ( $min, $max ) = minmax @list; - is( $min, 0 ); - is( $max, 10001 ); - $list[0] = 17; - - # Some floats - @list = ( 0, -1.1, 3.14, 1 / 7, 10000, -10 / 3 ); - ( $min, $max ) = minmax @list; - - # Floating-point comparison cunningly avoided - is( sprintf( "%.2f", $min ), "-3.33" ); - is( $max, 10000 ); - - # Test with a single negative list value - my $input = -1; - ( $min, $max ) = minmax $input; - is( $min, -1 ); - is( $max, -1 ); - - # COW causes missing max when optimization for 1 argument is applied - @list = grep {defined $_ } map { my ($min, $max) = minmax(sprintf("%.3g", rand)); ($min, $max) } (0..19); - is( scalar @list, 40, "minmax swallows max on COW" ); - - # Confirm output are independant copies of input - $input = 1; - is( $min, -1 ); - is( $max, -1 ); - $min = 2; - is( $max, -1 ); - - # prove overrun - my $uvmax = ~0; - my $ivmax = $uvmax >> 1; - my $ivmin = ( 0 - $ivmax ) - 1; - my @low_ints = map { $ivmin + $_ } ( 0 .. 10 ); - ( $min, $max ) = minmax @low_ints; - is( $min, $ivmin, "minmax finds ivmin" ); - is( $max, $ivmin + 10, "minmax finds ivmin + 10" ); - - my @high_ints = map { $ivmax - $_ } ( 0 .. 10 ); - ( $min, $max ) = minmax @high_ints; - is( $min, $ivmax - 10, "minmax finds ivmax-10" ); - is( $max, $ivmax, "minmax finds ivmax" ); - - my @mixed_ints = map { ( $ivmin + $_, $ivmax - $_ ) } ( 0 .. 10 ); - ( $min, $max ) = minmax @mixed_ints; - is( $min, $ivmin, "minmax finds ivmin" ); - is( $max, $ivmax, "minmax finds ivmax" ); - - my @high_uints = map { $uvmax - $_ } ( 0 .. 10 ); - ( $min, $max ) = minmax @high_uints; - is( $min, $uvmax - 10, "minmax finds uvmax-10" ); - is( $max, $uvmax, "minmax finds uvmax" ); - - my @mixed_nums = map { ( $ivmin + $_, $uvmax - $_ ) } ( 0 .. 10 ); - ( $min, $max ) = minmax @mixed_nums; - is( $min, $ivmin, "minmax finds ivmin" ); - is( $max, $uvmax, "minmax finds uvmax" ); - - leak_free_ok( - minmax => sub { - @list = ( 0, -1.1, 3.14, 1 / 7, 10000, -10 / 3 ); - ( $min, $max ) = minmax @list; - } - ); -} - -sub test_bsearch -{ - my @list = my @in = 1 .. 1000; - for my $elem (@in) - { - ok( scalar bsearch { $_ - $elem } @list ); - } - for my $elem (@in) - { - my ($e) = bsearch { $_ - $elem } @list; - ok( $e == $elem ); - } - my @out = ( -10 .. 0, 1001 .. 1011 ); - for my $elem (@out) - { - my $r = bsearch { $_ - $elem } @list; - ok( !defined $r ); - } - - leak_free_ok( - bsearch => sub { - my $elem = int( rand(1000) ) + 1; - scalar bsearch { $_ - $elem } @list; - } - ); - - leak_free_ok( - 'bsearch with stack-growing' => sub { - my $elem = int( rand(1000) ); - scalar bsearch { grow_stack(); $_ - $elem } @list; - } - ); - - leak_free_ok( - 'bsearch with stack-growing and exception' => sub { - my $elem = int( rand(1000) ); - eval { - scalar bsearch { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; - }; - } - ); - is_dying( sub { &bsearch( 42, ( 1 .. 100 ) ); } ); -} - -sub test_bsearchidx -{ - my @list = my @in = 1 .. 1000; - for my $i ( 0 .. $#in ) - { - is( $i, bsearchidx { $_ - $in[$i] } @list ); - } - my @out = ( -10 .. 0, 1001 .. 1011 ); - for my $elem (@out) - { - my $r = bsearchidx { $_ - $elem } @list; - is( -1, $r ); - } - - leak_free_ok( - bsearch => sub { - my $elem = int( rand(1000) ) + 1; - bsearchidx { $_ - $elem } @list; - } - ); - - leak_free_ok( - 'bsearch with stack-growing' => sub { - my $elem = int( rand(1000) ); - bsearchidx { grow_stack(); $_ - $elem } @list; - } - ); - - leak_free_ok( - 'bsearch with stack-growing and exception' => sub { - my $elem = int( rand(1000) ); - eval { - bsearchidx { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; - }; - } - ); - is_dying( sub { &bsearchidx( 42, ( 1 .. 100 ) ); } ); -} - -sub test_any -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( any { $_ == 5000 } @list ); - is_true( any { $_ == 5000 } 1 .. 10000 ); - is_true( any { defined } @list ); - is_false( any { not defined } @list ); - is_true( any { not defined } undef ); - is_false( any {} ); - - leak_free_ok( - any => sub { - my $ok = any { $_ == 5000 } @list; - my $ok2 = any { $_ == 5000 } 1 .. 10000; - } - ); - leak_free_ok( - 'any with a coderef that dies' => sub { - # This test is from Kevin Ryde; see RT#48669 - eval { - my $ok = any { die } 1; - }; - } - ); - is_dying( sub { &any( 42, 4711 ); } ); -} - -sub test_all -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( all { defined } @list ); - is_true( all { $_ > 0 } @list ); - is_false( all { $_ < 5000 } @list ); - is_true( all {} ); - - leak_free_ok( - all => sub { - my $ok = all { $_ == 5000 } @list; - my $ok2 = all { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &all( 42, 4711 ); } ); -} - -sub test_none -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( none { not defined } @list ); - is_true( none { $_ > 10000 } @list ); - is_false( none { defined } @list ); - is_true( none {} ); - - leak_free_ok( - none => sub { - my $ok = none { $_ == 5000 } @list; - my $ok2 = none { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { &none( 42, 4711 ); } ); -} - -sub test_notall -{ - # Normal cases - my @list = ( 1 .. 10000 ); - is_true( notall { !defined } @list ); - is_true( notall { $_ < 10000 } @list ); - is_false( notall { $_ <= 10000 } @list ); - is_false( notall {} ); - - leak_free_ok( - notall => sub { - my $ok = notall { $_ == 5000 } @list; - my $ok2 = notall { $_ == 5000 } 1 .. 10000; - } - ); - is_dying( sub { ¬all( 42, 4711 ); } ); -} - -sub test_one -{ - # Normal cases - my @list = ( 1 .. 300 ); - is_true( one { 1 == $_ } @list ); - is_true( one { 150 == $_ } @list ); - is_true( one { 300 == $_ } @list ); - is_false( one { 0 == $_ } @list ); - is_false( one { 1 <= $_ } @list ); - is_false( one { !( 127 & $_ ) } @list ); - - leak_free_ok( - one => sub { - my $ok = one { 150 <= $_ } @list; - my $ok2 = one { 150 <= $_ } 1 .. 300; - } - ); - is_dying( sub { &one( 42, 4711 ); } ); -} - -sub test_sort_by -{ - my @list = map { [$_] } 1 .. 100; - is_deeply( [ sort_by { $_->[0] } @list ], [ map { [$_] } sort { $a cmp $b } 1 .. 100 ] ); -} - -sub test_nsort_by -{ - my @list = map { [$_] } 1 .. 100; - is_deeply( [ nsort_by { $_->[0] } @list ], [ map { [$_] } sort { $a <=> $b } 1 .. 100 ] ); -} - -1; diff -Nru liblist-moreutils-perl-0.416/t/lib/LMU/Test/Import.pm liblist-moreutils-perl-0.430/t/lib/LMU/Test/Import.pm --- liblist-moreutils-perl-0.416/t/lib/LMU/Test/Import.pm 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/lib/LMU/Test/Import.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -package LMU::Test::Import; - -use strict; - -BEGIN -{ - $| = 1; -} - -use Test::More; - -sub run_tests -{ - use_ok( - "List::MoreUtils", qw(any all none notall - any_u all_u none_u notall_u - true false firstidx lastidx - insert_after insert_after_string - apply indexes - after after_incl before before_incl - firstval lastval - each_array each_arrayref - pairwise natatime - mesh uniq - minmax part - bsearch - sort_by nsort_by - first_index last_index first_value last_value zip distinct) - ); - done_testing(); -} - -1; - diff -Nru liblist-moreutils-perl-0.416/t/lib/LMU/Test/XS.pm liblist-moreutils-perl-0.430/t/lib/LMU/Test/XS.pm --- liblist-moreutils-perl-0.416/t/lib/LMU/Test/XS.pm 2015-03-18 11:07:51.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/lib/LMU/Test/XS.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -package LMU::Test::XS; - -use strict; - -BEGIN -{ - $| = 1; -} - -use Test::More; -use List::MoreUtils; - -sub run_tests -{ - test_xs(); - done_testing(); -} - -sub test_xs -{ - defined $ENV{LIST_MOREUTILS_PP} - or plan skip_all => "No dedicated test for XS/PP - but can't detect configure time settings at tets runtime"; - is( List::MoreUtils::_XScompiled, 0 + !$ENV{LIST_MOREUTILS_PP}, "_XScompiled" ); -} - -1; diff -Nru liblist-moreutils-perl-0.416/t/lib/Test/LMU.pm liblist-moreutils-perl-0.430/t/lib/Test/LMU.pm --- liblist-moreutils-perl-0.416/t/lib/Test/LMU.pm 2015-03-22 08:33:08.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/lib/Test/LMU.pm 2020-10-05 09:09:30.000000000 +0000 @@ -8,11 +8,22 @@ use base qw(Test::Builder::Module Exporter); -our @EXPORT = qw(is_true is_false is_defined is_undef is_dying grow_stack leak_free_ok); -our @EXPORT_OK = qw(is_true is_false is_defined is_undef is_dying grow_stack leak_free_ok); +our @EXPORT = qw(freeze is_true is_false is_defined is_undef is_dying not_dying grow_stack leak_free_ok); +our @EXPORT_OK = qw(freeze is_true is_false is_defined is_undef is_dying not_dying grow_stack leak_free_ok); my $CLASS = __PACKAGE__; +eval "use Storable qw();"; +$@ or Storable->import(qw(freeze)); +__PACKAGE__->can("freeze") or eval <<'EOFR'; +use inc::latest 'JSON::PP'; +use JSON::PP qw(); +sub freeze { + my $json = JSON::PP->new(); + $json->encode($_[0]); +} +EOFR + ###################################################################### # Support Functions @@ -20,36 +31,56 @@ { @_ == 1 or croak "Expected 1 param"; my $tb = $CLASS->builder(); - $tb->ok( $_[0], "is_true ()" ); + $tb->ok($_[0], "is_true ()"); } sub is_false { @_ == 1 or croak "Expected 1 param"; my $tb = $CLASS->builder(); - $tb->ok( !$_[0], "is_false()" ); + $tb->ok(!$_[0], "is_false()"); } sub is_defined { @_ < 1 or croak "Expected 0..1 param"; my $tb = $CLASS->builder(); - $tb->ok( defined( $_[0] ), "is_defined ()" ); + $tb->ok(defined($_[0]), "is_defined ()"); } sub is_undef { @_ <= 1 or croak "Expected 0..1 param"; my $tb = $CLASS->builder(); - $tb->ok( !defined( $_[0] ), "is_undef()" ); + $tb->ok(!defined($_[0]), "is_undef()"); } sub is_dying { - @_ == 1 or croak "Expected 1 param"; + @_ == 1 or @_ == 2 or croak "is_dying(name => code)"; + my ($name, $code); + $name = shift if @_ == 2; + $code = shift; + ref $code eq "CODE" or croak "is_dying(name => code)"; + my $tb = $CLASS->builder(); + eval { $code->(); }; + my $except = $@; + chomp $except; + $tb->ok($except, "$name is_dying()") and note($except); +} + +sub not_dying +{ + @_ == 1 or @_ == 2 or croak "not_dying(name => code)"; + my ($name, $code); + $name = shift if @_ == 2; + $code = shift; + ref $code eq "CODE" or croak "not_dying(name => code)"; my $tb = $CLASS->builder(); - eval { $_[0]->(); }; - $tb->ok( $@, "is_dying()" ); + eval { $code->(); }; + my $except = $@; + chomp $except; + $tb->ok(!$except, "$name not_dying()") or diag($except); } my @bigary = (1) x 500; @@ -65,13 +96,16 @@ sub leak_free_ok { - my $name = shift; - my $code = shift; - SKIP: + while (@_) { - skip 'Test::LeakTrace not installed', 1 unless $have_test_leak_trace; - local $Test::Builder::Level = $Test::Builder::Level + 1; - &Test::LeakTrace::no_leaks_ok( $code, "No memory leaks in $name" ); + my $name = shift; + my $code = shift; + SKIP: + { + skip 'Test::LeakTrace not installed', 1 unless $have_test_leak_trace; + local $Test::Builder::Level = $Test::Builder::Level + 1; + &Test::LeakTrace::no_leaks_ok($code, "No memory leaks in $name"); + } } } @@ -79,8 +113,36 @@ package DieOnStringify; use overload '""' => \&stringify; - sub new { bless {}, shift } + sub new { bless {}, shift } sub stringify { die 'DieOnStringify exception' } } 1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. + +=cut diff -Nru liblist-moreutils-perl-0.416/t/LICENSE liblist-moreutils-perl-0.430/t/LICENSE --- liblist-moreutils-perl-0.416/t/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/LICENSE 2020-10-02 06:22:45.000000000 +0000 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff -Nru liblist-moreutils-perl-0.416/t/.perltidyrc liblist-moreutils-perl-0.430/t/.perltidyrc --- liblist-moreutils-perl-0.416/t/.perltidyrc 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/.perltidyrc 2020-10-02 06:23:17.000000000 +0000 @@ -0,0 +1,17 @@ +-b +-bl +-noll +-pt=2 +-bt=2 +-sbt=2 +-vt=0 +-vtc=0 +-dws +-aws +-nsfs +-asc +-bbt=0 +-cab=0 +-l=130 +-ole=unix +--noblanks-before-comments diff -Nru liblist-moreutils-perl-0.416/t/pureperl/ab.t liblist-moreutils-perl-0.430/t/pureperl/ab.t --- liblist-moreutils-perl-0.416/t/pureperl/ab.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/ab.t 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -#!perl - -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 1; -END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS - -require LMU::Test::ab; - -LMU::Test::ab->run_tests; - diff -Nru liblist-moreutils-perl-0.416/t/pureperl/after_incl.t liblist-moreutils-perl-0.430/t/pureperl/after_incl.t --- liblist-moreutils-perl-0.416/t/pureperl/after_incl.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/after_incl.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = after_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [5, 6, 7, 8, 9], "after 5, included"); + +@x = after_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after_incl { /b/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "after /b/, included"); + +leak_free_ok( + after_incl => sub { + @x = after_incl { /z/ } qw{bar baz foo}; + } +); +is_dying('after_incl without sub' => sub { &after_incl(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/after.t liblist-moreutils-perl-0.430/t/pureperl/after.t --- liblist-moreutils-perl-0.416/t/pureperl/after.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/after.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,35 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = after { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [6, 7, 8, 9], "after 5"); + +@x = after { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after { /b/ } qw{bar baz foo }; +is_deeply(\@x, [qw{baz foo }], "after /b/"); + +leak_free_ok( + after => sub { + @x = after { /z/ } qw{bar baz foo}; + } +); +is_dying('after without sub' => sub { &after(42, 4711); }); + +@x = (1, after { /foo/ } qw(abc def)); +is_deeply(\@x, [1], "check XS implementation doesn't mess up stack"); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/all.t liblist-moreutils-perl-0.430/t/pureperl/all.t --- liblist-moreutils-perl-0.416/t/pureperl/all.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/all.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all { defined } @list); +is_true(all { $_ > 0 } @list); +is_false(all { $_ < 5000 } @list); +is_true(all {}); + +leak_free_ok( + all => sub { + my $ok = all { $_ == 5000 } @list; + my $ok2 = all { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all without sub' => sub { &all(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/all_u.t liblist-moreutils-perl-0.430/t/pureperl/all_u.t --- liblist-moreutils-perl-0.416/t/pureperl/all_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/all_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all_u { defined } @list); +is_true(all_u { $_ > 0 } @list); +is_false(all_u { $_ < 5000 } @list); +is_undef(all_u {}); + +leak_free_ok( + all_u => sub { + my $ok = all_u { $_ == 5000 } @list; + my $ok2 = all_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all_u without sub' => sub { &all_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/any.t liblist-moreutils-perl-0.430/t/pureperl/any.t --- liblist-moreutils-perl-0.416/t/pureperl/any.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/any.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,41 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any { $_ == 5000 } @list); +is_true(any { $_ == 5000 } 1 .. 10000); +is_true(any { defined } @list); +is_false(any { not defined } @list); +is_true(any { not defined } undef); +is_false(any {}); + +leak_free_ok( + any => sub { + my $ok = any { $_ == 5000 } @list; + my $ok2 = any { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any { die } 1; + }; + } +); +is_dying('any without sub' => sub { &any(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/any_u.t liblist-moreutils-perl-0.430/t/pureperl/any_u.t --- liblist-moreutils-perl-0.416/t/pureperl/any_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/any_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,41 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any_u { $_ == 5000 } @list); +is_true(any_u { $_ == 5000 } 1 .. 10000); +is_true(any_u { defined } @list); +is_false(any_u { not defined } @list); +is_true(any_u { not defined } undef); +is_undef(any_u {}); + +leak_free_ok( + any_u => sub { + my $ok = any_u { $_ == 5000 } @list; + my $ok2 = any_u { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any_u { die } 1; + }; + } +); +is_dying('any_u without sub' => sub { &any_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/apply.t liblist-moreutils-perl-0.430/t/pureperl/apply.t --- liblist-moreutils-perl-0.416/t/pureperl/apply.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/apply.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,80 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Test the null case +my $null_scalar = apply {}; +is($null_scalar, undef, 'apply(null) returns undef'); + +my @null_list = apply {}; +is_deeply(\@null_list, [], 'apply(null) returns null list'); + +# Normal cases +my @list = (0 .. 9); +my @list1 = apply { $_++ } @list; +is_deeply(\@list, [0 .. 9], "original numbers untouched"); +is_deeply(\@list1, [1 .. 10], "returned numbers increased"); +@list = (" foo ", " bar ", " ", "foobar"); +@list1 = apply { s/^\s+|\s+$//g } @list; +is_deeply(\@list, [" foo ", " bar ", " ", "foobar"], "original strings untouched"); +is_deeply(\@list1, ["foo", "bar", "", "foobar"], "returned strings stripped"); +my $item = apply { s/^\s+|\s+$//g } @list; +is($item, "foobar"); + +# RT 96596 +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + eval { my @a = \&apply(1, 2); }; + my $err = $@; + like($err, qr/\QList::MoreUtils::XS::apply(code, ...)\E/, "apply must be reasonable invoked"); +} + +# RT 38630 +SCOPE: +{ + # wrong results from apply() [XS] + @list = (1 .. 4); + @list1 = apply { grow_stack(); $_ = 5; } @list; + is_deeply(\@list, [1 .. 4]); + is_deeply(\@list1, [(5) x 4]); +} + +leak_free_ok( + apply => sub { + @list = (1 .. 4); + @list1 = apply + { + grow_stack(); + $_ = 5; + } + @list; + } +); + +SCOPE: +{ + leak_free_ok( + 'dying callback during apply' => sub { + my @l = (1 .. 4); + eval { + my @l1 = apply { $_ % 2 or die "Even!"; $_ %= 2; } @l; + }; + } + ); +} + +is_dying('apply without sub' => sub { &apply(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/arrayify.t liblist-moreutils-perl-0.430/t/pureperl/arrayify.t --- liblist-moreutils-perl-0.416/t/pureperl/arrayify.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/arrayify.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,125 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]], 18); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 18], "linear flattened int mix i"); +} + +SCOPE: +{ + my @in = (1 .. 4, [[5 .. 11]], 12, [[13 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened int mix ii"); +} + +SCOPE: +{ + # typical structure when parsing XML using XML::Hash::XS + my %src = ( + root => { + foo_list => {foo_elem => {attr => 42}}, + bar_list => {bar_elem => [{hummel => 2}, {hummel => 3}, {hummel => 5}]} + } + ); + my @foo_elems = arrayify $src{root}->{foo_list}->{foo_elem}; + is_deeply(\@foo_elems, [{attr => 42}], "arrayified struct with one element"); + my @bar_elems = arrayify $src{root}->{bar_list}->{bar_elem}; + is_deeply(\@bar_elems, [{hummel => 2}, {hummel => 3}, {hummel => 5}], "arrayified struct with three elements"); +} + +SCOPE: +{ + my @in; + tie @in, "Tie::StdArray"; + @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mix"); +} + +SCOPE: +{ + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mixture"); +} + +SCOPE: +{ + my @in = (qw(av_make av_undef av_clear), [qw(av_push av_pop)], qw(av_fetch av_store), [['av_shift'], ['av_unshift']]); + my @out = arrayify @in; + is_deeply( + \@out, + [qw(av_make av_undef av_clear av_push av_pop av_fetch av_store av_shift av_unshift)], + "linear flattened string mix i" + ); +} + +leak_free_ok( + arrayify => sub { + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + }, + 'arrayify magic' => sub { + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + } +); + +SKIP: +{ + leak_free_ok( + 'arrayify with exception in overloading stringify at begin' => sub { + my @in = ( + DieOnStringify->new, qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']] + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + }, + ); + leak_free_ok( + 'arrayify with exception in overloading stringify at end' => sub { + my @in = ( + qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']], + DieOnStringify->new + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + } + ); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/before_incl.t liblist-moreutils-perl-0.430/t/pureperl/before_incl.t --- liblist-moreutils-perl-0.416/t/pureperl/before_incl.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/before_incl.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = before_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4, 5], "before 5, included"); + +@x = before_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [qw{bar baz}]); + +@x = before_incl { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "before /f/, included"); + +leak_free_ok( + before_incl => sub { + @x = before_incl { /z/ } qw{ bar baz foo }; + } +); +is_dying('before_incl without sub' => sub { &before_incl(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/before.t liblist-moreutils-perl-0.430/t/pureperl/before.t --- liblist-moreutils-perl-0.416/t/pureperl/before.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/before.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = before { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4], "before 5"); + +@x = before { /b/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = before { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz}], "before /f/"); + +leak_free_ok( + before => sub { + @x = before { /f/ } qw{ bar baz foo }; + } +); +is_dying('before without sub' => sub { &before(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/binsert.t liblist-moreutils-perl-0.430/t/pureperl/binsert.t --- liblist-moreutils-perl-0.416/t/pureperl/binsert.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/binsert.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,148 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @list = (); + is(0, (binsert { $_ cmp "Hello" } "Hello", @list), "Inserting into empty list"); + is(1, (binsert { $_ cmp "world" } "world", @list), "Inserting into one-item list"); +} + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (@odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements into even list succeeded"); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements reversely into even list succeeded"); + +@in = @odd; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements into odd list succeeded"); + +@in = @odd; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements reversely into odd list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements into even list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements reversely into even list succeeded"); + +leak_free_ok( + 'binsert random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert existing random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = 2 * (int(rand(100)) + 1); + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert odd into even' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into odd' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert odd into odd' => sub { + my @list = @odd; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into even' => sub { + my @list = @even; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert random with stack-growing' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + }, + 'binsert odd with stack-growing' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, + 'binsert even with stack-growing' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert with stack-growing and exception' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + eval { + binsert { grow_stack(); $_ <=> $elem or die "Goal!"; $_ <=> $elem } $elem, @list; + }; + } +); + +is_dying('binsert without sub' => sub { &binsert(42, @even); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/bremove.t liblist-moreutils-perl-0.430/t/pureperl/bremove.t --- liblist-moreutils-perl-0.416/t/pureperl/bremove.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/bremove.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,119 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@expected = @even; +@in = mesh @odd, @even; +foreach my $v (@odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements reversely succeeded"); + +@expected = @odd; +@in = mesh @odd, @even; +foreach my $v (@even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements reversely succeeded"); + +# test from shawnlaffan from GH issue #2 of List-MoreUtils-XS +SCOPE: +{ + my @list = ('somestring'); + my $target = $list[0]; + is($target, (bremove { $_ cmp $target } @list), 'removed from single item list'); +} + +leak_free_ok( + 'bremove first' => sub { + my @list = (1 .. 100); + my $v = $list[0]; + bremove { $_ <=> $v } @list; + }, + 'bremove last' => sub { + my @list = (1 .. 100); + my $v = $list[-1]; + bremove { $_ <=> $v } @list; + }, + 'bremove middle' => sub { + my @list = (1 .. 100); + my $v = $list[int($#list / 2)]; + bremove { $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove last with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove middle with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + bremove { grow_stack(); $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove last with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove middle with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, +); +is_dying('bremove without sub' => sub { &bremove(42, @even); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/bsearchidx.t liblist-moreutils-perl-0.430/t/pureperl/bsearchidx.t --- liblist-moreutils-perl-0.416/t/pureperl/bsearchidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/bsearchidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,52 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $i (0 .. $#in) +{ + is($i, bsearchidx { $_ - $in[$i] } @list); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearchidx { $_ - $elem } @list; + is(-1, $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + bsearchidx { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + bsearchidx { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + bsearchidx { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearchidx without sub' => sub { &bsearchidx(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/bsearch.t liblist-moreutils-perl-0.430/t/pureperl/bsearch.t --- liblist-moreutils-perl-0.416/t/pureperl/bsearch.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/bsearch.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,57 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $elem (@in) +{ + ok(scalar bsearch { $_ - $elem } @list); +} +for my $elem (@in) +{ + my ($e) = bsearch { $_ - $elem } @list; + ok($e == $elem); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearch { $_ - $elem } @list; + ok(!defined $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + scalar bsearch { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + scalar bsearch { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + scalar bsearch { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearch without sub' => sub { &bsearch(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/duplicates.t liblist-moreutils-perl-0.430/t/pureperl/duplicates.t --- liblist-moreutils-perl-0.416/t/pureperl/duplicates.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/duplicates.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,121 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my $fd = freeze(\@d); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@d], "duplicates of numbers/strings mixture"); + is($fd, freeze(\@d), "frozen duplicates of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + is($fu, $fd); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is_deeply(\@u, [@d], "duplicates of tied array of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + @a = (@u, @d); + $fa = freeze(\@a); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of tied array of numbers/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my @dfoo = ('b', '', undef); + is_deeply([duplicates @foo], \@dfoo, "two undef's are supported correctly by duplicates"); + @foo = ('a', undef, 'b', '', 'b', 'c', ''); + @dfoo = ('b', ''); + is_deeply([duplicates @foo], \@dfoo, 'one undef is ignored correctly by duplicates'); + is((scalar duplicates @foo), scalar @dfoo, 'scalar one undef is ignored correctly by duplicates'); +} + +leak_free_ok( + duplicates => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = duplicates @a; + scalar duplicates @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'duplicates with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my @u = duplicates @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $u = duplicates 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; + + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/each_array.t liblist-moreutils-perl-0.430/t/pureperl/each_array.t --- liblist-moreutils-perl-0.416/t/pureperl/each_array.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/each_array.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,138 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw{ a 2 -1 x }; + my $it = each_array @a, @b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); + + # This used to give "semi-panic: attempt to dup freed string" + # See: + my $ea = each_arrayref([1 .. 26], ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@b, ['A' .. 'Z']); + + # And this even used to dump core + my @nums = 1 .. 26; + $ea = each_arrayref(\@nums, ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@a, \@nums); + is_deeply(\@b, ['A' .. 'Z']); +} + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw/a 2 -1 x/; + + my $it = each_arrayref \@a, \@b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); +} + +# Note that the leak_free_ok tests for each_array and each_arrayref +# should not be run until either of them has been called at least once +# in the current perl. That's because calling them the first time +# causes the runtime to allocate some memory used for the OO structures +# that their implementation uses internally. +leak_free_ok( + each_array => sub { + my @a = (1); + my $it = each_array @a; + while (my ($a) = $it->()) + { + } + } +); +leak_free_ok( + each_arrayref => sub { + my @a = (1); + my $it = each_arrayref \@a; + while (my ($a) = $it->()) + { + } + } +); +is_dying('each_array without sub' => sub { &each_array(42, 4711); }); +is_dying('each_arrayref without sub' => sub { &each_arrayref(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/equal_range.t liblist-moreutils-perl-0.430/t/pureperl/equal_range.t --- liblist-moreutils-perl-0.416/t/pureperl/equal_range.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/equal_range.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,48 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is_deeply([0, 0], [equal_range { $_ <=> 0 } @list], "equal range 0"); +is_deeply([0, 2], [equal_range { $_ <=> 1 } @list], "equal range 1"); +is_deeply([2, 4], [equal_range { $_ <=> 2 } @list], "equal range 2"); +is_deeply([10, 14], [equal_range { $_ <=> 4 } @list], "equal range 4"); +is_deeply([(scalar @list) x 2], [equal_range { $_ <=> 19 } @list], "equal range 19"); + +my @in = @list = 1 .. 100; +leak_free_ok( + equal_range => sub { + my $elem = int(rand(101)) + 1; + equal_range { $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing' => sub { + my $elem = int(rand(101)); + equal_range { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing and exception' => sub { + my $elem = int(rand(101)); + eval { + equal_range { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('equal_range without sub' => sub { &equal_range(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/false.t liblist-moreutils-perl-0.430/t/pureperl/false.t --- liblist-moreutils-perl-0.416/t/pureperl/false.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/false.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,36 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = false {}; +my @null_list = false {}; +is($null_scalar, 0, 'false(null) returns undef'); +is_deeply(\@null_list, [0], 'false(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, false { not defined } @list); +is(0, false { defined } @list); +is(1, false { $_ > 1 } @list); + +leak_free_ok( + false => sub { + my $n = false { $_ == 5000 } @list; + my $n2 = false { $_ == 5000 } 1 .. 10000; + } +); +is_dying('false without sub' => sub { &false(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/firstidx.t liblist-moreutils-perl-0.430/t/pureperl/firstidx.t --- liblist-moreutils-perl-0.416/t/pureperl/firstidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/firstidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,43 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_index = __PACKAGE__->can("firstidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(4999, (firstidx { $_ >= 5000 } @list), "firstidx"); +is(-1, (firstidx { not defined } @list), "invalid firstidx"); +is(0, (firstidx { defined } @list), "real firstidx"); +is(-1, (firstidx {}), "empty firstidx"); + +SKIP: +{ + # Test the alias + is(4999, first_index { $_ >= 5000 } @list); + is(-1, first_index { not defined } @list); + is(0, first_index { defined } @list); + is(-1, first_index {}); +} + +leak_free_ok( + firstidx => sub { + my $i = firstidx { $_ >= 5000 } @list; + my $i2 = firstidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('firstidx without sub' => sub { &firstidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/firstres.t liblist-moreutils-perl-0.430/t/pureperl/firstres.t --- liblist-moreutils-perl-0.416/t/pureperl/firstres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/firstres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,38 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_result = __PACKAGE__->can("firstres"); +} + +use Test::More; +use Test::LMU; + +my $x = firstres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = firstres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = first_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = first_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstres => sub { + $x = firstres { $_ > 5 } 4 .. 9; + } +); +is_dying('firstres without sub' => sub { &firstres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/firstval.t liblist-moreutils-perl-0.430/t/pureperl/firstval.t --- liblist-moreutils-perl-0.416/t/pureperl/firstval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/firstval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,39 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_value = __PACKAGE__->can("firstval"); +} + +use Test::More; +use Test::LMU; + +my $x = firstval { $_ > 5 } 4 .. 9; +is($x, 6); +$x = firstval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(firstval { $_ > 5 }); + +# Test aliases +$x = first_value { $_ > 5 } 4 .. 9; +is($x, 6); +$x = first_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstval => sub { + $x = firstval { $_ > 5 } 4 .. 9; + } +); +is_dying('firstval without sub' => sub { &firstval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/frequency.t liblist-moreutils-perl-0.430/t/pureperl/frequency.t --- liblist-moreutils-perl-0.416/t/pureperl/frequency.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/frequency.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,128 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves numbers untouched"); + is_deeply(\%f, {%e}, "frequency of numbers"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G:SCALAR leaves numbers untouched"); + is(scalar keys %e, $f, "scalar result of frequency of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves strings untouched"); + is_deeply(\%f, {%e}, "frequency of strings"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves strings untouched"); + is(scalar keys %e, $f, "scalar result of frequency of strings"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of number/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves tied array of number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of tied array of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves tied array of number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of tied array of number/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my %e = ( + a => 1, + b => 2, + '' => 2, + c => 1 + ); + my @f = frequency @foo; + my $seen_undef; + ref $f[-2] and ref $f[-2] eq "SCALAR" and not defined ${$f[-2]} and (undef, $seen_undef) = splice @f, -2, 2, (); + my %f = @f; + is_deeply(\%f, \%e, "stuff around undef's is supported correctly by frequency"); + is($seen_undef, 2, "two undef's are supported correctly by frequency"); +} + +leak_free_ok( + frequency => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my %f = frequency @a; + }, + 'scalar frequency' => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $f = frequency @a; + } +); + +leak_free_ok( + 'frequency with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my %f = frequency @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $f = frequency 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/Functions.t liblist-moreutils-perl-0.430/t/pureperl/Functions.t --- liblist-moreutils-perl-0.416/t/pureperl/Functions.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/Functions.t 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -#!perl - -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 1; -END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS - -require LMU::Test::Functions; - -LMU::Test::Functions->run_tests; - diff -Nru liblist-moreutils-perl-0.416/t/pureperl/Import.t liblist-moreutils-perl-0.430/t/pureperl/Import.t --- liblist-moreutils-perl-0.416/t/pureperl/Import.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/Import.t 2020-10-21 14:47:09.000000000 +0000 @@ -1,10 +1,92 @@ #!perl -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 1; +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @pure_funcs = qw(any all none notall one + any_u all_u none_u notall_u one_u + true false + insert_after insert_after_string + apply indexes + after after_incl before before_incl + firstidx lastidx onlyidx + firstval lastval onlyval + firstres lastres onlyres + singleton + each_array each_arrayref + pairwise natatime + mesh uniq + minmax part + bsearch bsearchidx); +my @v0_33 = qw(sort_by nsort_by); +my %alias_list = ( + v0_22 => { + first_index => "firstidx", + last_index => "lastidx", + first_value => "firstval", + last_value => "lastval", + zip => "mesh", + }, + v0_33 => { + distinct => "uniq", + }, + v0_400 => { + first_result => "firstres", + only_index => "onlyidx", + only_value => "onlyval", + only_result => "onlyres", + last_result => "lastres", + bsearch_index => "bsearchidx", + }, +); + +can_ok(__PACKAGE__, $_) for @pure_funcs; + +SKIP: +{ + $INC{'List/MoreUtils.pm'} or skip "List::MoreUtils::XS doesn't alias", 1; + can_ok(__PACKAGE__, $_) for @v0_33; + can_ok(__PACKAGE__, $_) for map { keys %$_ } values %alias_list; +} + +done_testing; + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. -require LMU::Test::Import; +=cut -LMU::Test::Import->run_tests; diff -Nru liblist-moreutils-perl-0.416/t/pureperl/indexes.t liblist-moreutils-perl-0.430/t/pureperl/indexes.t --- liblist-moreutils-perl-0.416/t/pureperl/indexes.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/indexes.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,77 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = indexes { $_ > 5 } (4 .. 9); +is_deeply(\@x, [2 .. 5], "indexes > 5 ..."); +@x = indexes { $_ > 5 } (1 .. 4); +is_deeply(\@x, [], 'Got the null list'); + +my ($lr, @s, @n, @o, @e); +leak_free_ok( + indexes => sub { + $lr = 1; + @s = indexes { $_ > 5 } (4 .. 9); + @n = indexes { $_ > 5 } (1 .. 5); + @o = indexes { $_ & 1 } (10 .. 15); + @e = indexes { !($_ & 1) } (10 .. 15); + } +); +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +@n = map { $_ + 1 } @o = (0 .. 9); +@x = indexes { ++$_ > 7 } @o; +is_deeply(\@o, \@n, "indexes behaves like grep on modified \$_"); +is_deeply(\@x, [7 .. 9], "indexes/modify"); + +not_dying( + 'indexes_on_set' => sub { + @x = indexes { ++$_ > 7 } (0 .. 9); + } +); +is_deeply(\@x, [7 .. 9], "indexes/modify set"); + +leak_free_ok( + indexes => sub { + @s = indexes { grow_stack; $_ > 5 } (4 .. 9); + @n = indexes { grow_stack; $_ > 5 } (1 .. 4); + @o = indexes { grow_stack; $_ & 1 } (10 .. 15); + @e = indexes { grow_stack; !($_ & 1) } (10 .. 15); + }, + 'indexes interrupted by exception' => sub { + eval { + @s = indexes { $_ > 10 and die "range exceeded"; $_ > 5 } (1 .. 15); + }; + }, +); + +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +my $have_scalar_util = eval { require Scalar::Util; 1 }; + +if ($have_scalar_util) +{ + my $ref = \(indexes(sub { 1 }, 123)); + Scalar::Util::weaken($ref); + is($ref, undef, "weakened away"); +} +is_dying('indexes without sub' => sub { &indexes(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/insert_after_string.t liblist-moreutils-perl-0.430/t/pureperl/insert_after_string.t --- liblist-moreutils-perl-0.416/t/pureperl/insert_after_string.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/insert_after_string.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,43 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after_string "a", "longer" => @list; +is(join(' ', @list), "This is a longer list"); +@list = (undef, qw{This is a list}); +insert_after_string "a", "longer", @list; +shift @list; +is(join(' ', @list), "This is a longer list"); +@list = ("This\0", "is\0", "a\0", "list\0"); +insert_after_string "a\0", "longer\0", @list; +is(join(' ', @list), "This\0 is\0 a\0 longer\0 list\0"); + +leak_free_ok( + insert_after_string => sub { + @list = qw{This is a list}; + insert_after_string "a", "longer", @list; + } +); +leak_free_ok( + 'insert_after_string with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after_string "a", "longer", @list; + }; + } +); +is_dying('insert_after_string without array' => sub { &insert_after_string(42, 4711, "13"); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/insert_after.t liblist-moreutils-perl-0.430/t/pureperl/insert_after.t --- liblist-moreutils-perl-0.416/t/pureperl/insert_after.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/insert_after.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,50 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after { $_ eq "a" } "longer" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { 0 } "bla" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { $_ eq "list" } "!" => @list; +is(join(' ', @list), "This is a longer list !"); +@list = (qw{This is}, undef, qw{list}); +insert_after { not defined($_) } "longer" => @list; +$list[2] = "a"; +is(join(' ', @list), "This is a longer list"); + +leak_free_ok( + insert_after => sub { + @list = qw{This is a list}; + insert_after { $_ eq 'a' } "longer" => @list; + } +); +leak_free_ok( + 'insert_after with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after { $_ eq 'a' } "longer" => @list; + }; + } +); +is_dying('insert_after without sub' => sub { &insert_after(42, 4711, [qw(die bart die)]); }); +is_dying('insert_after without sub and array' => sub { &insert_after(42, 4711, "13"); }); +is_dying( + 'insert_after without array' => sub { + &insert_after(sub { }, 4711, "13"); + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/lastidx.t liblist-moreutils-perl-0.430/t/pureperl/lastidx.t --- liblist-moreutils-perl-0.416/t/pureperl/lastidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/lastidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,40 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_index = __PACKAGE__->can("lastidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(9999, lastidx { $_ >= 5000 } @list); +is(-1, lastidx { not defined } @list); +is(9999, lastidx { defined } @list); +is(-1, lastidx {}); + +# Test aliases +is(9999, last_index { $_ >= 5000 } @list); +is(-1, last_index { not defined } @list); +is(9999, last_index { defined } @list); +is(-1, last_index {}); + +leak_free_ok( + lastidx => sub { + my $i = lastidx { $_ >= 5000 } @list; + my $i2 = lastidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('lastidx without sub' => sub { &lastidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/lastres.t liblist-moreutils-perl-0.430/t/pureperl/lastres.t --- liblist-moreutils-perl-0.416/t/pureperl/lastres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/lastres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,38 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_result = __PACKAGE__->can("lastres"); +} + +use Test::More; +use Test::LMU; + +my $x = lastres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = lastres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = last_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = last_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastres => sub { + $x = lastres { $_ > 5 } 4 .. 9; + } +); +is_dying('lastres without sub' => sub { &lastres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/lastval.t liblist-moreutils-perl-0.430/t/pureperl/lastval.t --- liblist-moreutils-perl-0.416/t/pureperl/lastval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/lastval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,39 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_value = __PACKAGE__->can("lastval"); +} + +use Test::More; +use Test::LMU; + +my $x = lastval { $_ > 5 } 4 .. 9; +is($x, 9); +$x = lastval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(lastval { $_ > 5 }); + +# Test aliases +$x = last_value { $_ > 5 } 4 .. 9; +is($x, 9); +$x = last_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastval => sub { + $x = lastval { $_ > 5 } 4 .. 9; + } +); +is_dying('lastval without sub' => sub { &lastval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/listcmp.t liblist-moreutils-perl-0.430/t/pureperl/listcmp.t --- liblist-moreutils-perl-0.416/t/pureperl/listcmp.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/listcmp.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,127 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen); + my @b = qw(two three five seven eleven thirteen seventeen); + my @c = qw(one one two three five eight thirteen twentyone); + + my %expected = ( + one => [0, 2], + two => [0, 1, 2], + three => [0, 1, 2], + four => [0], + five => [0, 1, 2], + six => [0], + seven => [0, 1], + eight => [0, 2], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1, 2], + seventeen => [1], + twentyone => [2], + ); + + my %cmped = listcmp @a, @b, @c; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime vs. Fibonacci sorted out correctly"); +} + +SCOPE: +{ + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime filled with undef sorted out correctly"); +} + +leak_free_ok( + listcmp => sub { + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'listcmp with exception in overloading stringify at begin' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = (DieOnStringify->new, "two", "three"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + }, + 'listcmp with exception in overloading stringify at end' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = ("two", "three", DieOnStringify->new); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/lower_bound.t liblist-moreutils-perl-0.430/t/pureperl/lower_bound.t --- liblist-moreutils-perl-0.416/t/pureperl/lower_bound.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/lower_bound.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,65 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (lower_bound { $_ <=> 0 } @list), "lower bound 0"); +is(0, (lower_bound { $_ <=> 1 } @list), "lower bound 1"); +is(2, (lower_bound { $_ <=> 2 } @list), "lower bound 2"); +is(10, (lower_bound { $_ <=> 4 } @list), "lower bound 4"); +is(scalar @list, (lower_bound { $_ <=> 19 } @list), "lower bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i ? $i - 1 : 0, (lower_bound { $_ - $j } @list), "placed $j"); + is($i, (lower_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (lower_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (lower_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + lower_bound => sub { + my $elem = int(rand(1000)) + 1; + lower_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + lower_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + lower_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('lower_bound without sub' => sub { &lower_bound(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/mesh.t liblist-moreutils-perl-0.430/t/pureperl/mesh.t --- liblist-moreutils-perl-0.416/t/pureperl/mesh.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/mesh.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,79 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *zip = __PACKAGE__->can("mesh"); +} + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "mesh two list with same count of elements"); +} + +SCOPE: +{ + # alias check + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "zip two list with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = mesh @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "mesh three list with increasing count of elements"); +} + +SCOPE: +{ + # alias check + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "zip three list with increasing count of elements"); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = mesh @a, @d; + is_deeply( + \@z, + [1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef,], + "mesh one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + mesh => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + } +); +is_dying('mesh with a list, not at least two arrays' => sub { &mesh(1, 2); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/minmaxstr.t liblist-moreutils-perl-0.430/t/pureperl/minmaxstr.t --- liblist-moreutils-perl-0.416/t/pureperl/minmaxstr.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/minmaxstr.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,53 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +use Test::More; +use Test::LMU; + +use POSIX qw(setlocale LC_COLLATE); +setlocale(LC_COLLATE, "C"); + +my @list = reverse 'AA' .. 'ZZ'; +my ($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ'); + +# Odd number of elements +push @list, 'ZZ Top'; +($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ Top'); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmaxstr(sprintf("%s", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmaxstr swallows max on COW"); + +# Test with a single list value +my $input = 'foo'; +($min, $max) = minmaxstr $input; +is($min, 'foo'); +is($max, 'foo'); + +# Confirm output are independant copies of input +$input = 'bar'; +is($min, 'foo'); +is($max, 'foo'); +$min = 'bar'; +is($max, 'foo'); + +leak_free_ok( + minmaxstr => sub { + @list = reverse 'AA' .. 'ZZ', 'ZZ Top'; + ($min, $max) = minmaxstr @list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/minmax.t liblist-moreutils-perl-0.430/t/pureperl/minmax.t --- liblist-moreutils-perl-0.416/t/pureperl/minmax.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/minmax.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,89 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = reverse 0 .. 10000; +my ($min, $max) = minmax @list; +is($min, 0); +is($max, 10000); + +# Even number of elements +push @list, 10001; +($min, $max) = minmax @list; +is($min, 0); +is($max, 10001); +$list[0] = 17; + +# Some floats +@list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); +($min, $max) = minmax @list; + +# Floating-point comparison cunningly avoided +is(sprintf("%.2f", $min), "-3.33"); +is($max, 10000); + +# Test with a single negative list value +my $input = -1; +($min, $max) = minmax $input; +is($min, -1); +is($max, -1); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmax(sprintf("%.3g", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmax swallows max on COW"); + +# Confirm output are independant copies of input +$input = 1; +is($min, -1); +is($max, -1); +$min = 2; +is($max, -1); + +# prove overrun +my $uvmax = ~0; +my $ivmax = $uvmax >> 1; +my $ivmin = (0 - $ivmax) - 1; +my @low_ints = map { $ivmin + $_ } (0 .. 10); +($min, $max) = minmax @low_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmin + 10, "minmax finds ivmin + 10"); + +my @high_ints = map { $ivmax - $_ } (0 .. 10); +($min, $max) = minmax @high_ints; +is($min, $ivmax - 10, "minmax finds ivmax-10"); +is($max, $ivmax, "minmax finds ivmax"); + +my @mixed_ints = map { ($ivmin + $_, $ivmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmax, "minmax finds ivmax"); + +my @high_uints = map { $uvmax - $_ } (0 .. 10); +($min, $max) = minmax @high_uints; +is($min, $uvmax - 10, "minmax finds uvmax-10"); +is($max, $uvmax, "minmax finds uvmax"); + +my @mixed_nums = map { ($ivmin + $_, $uvmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_nums; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $uvmax, "minmax finds uvmax"); + +leak_free_ok( + minmax => sub { + @list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); + ($min, $max) = minmax @list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/mode.t liblist-moreutils-perl-0.430/t/pureperl/mode.t --- liblist-moreutils-perl-0.416/t/pureperl/mode.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/mode.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,452 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + my $fl = freeze(\@lorem); + + my $n_comma = scalar(split /,/, $lorem) - 1; + + my @m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_ARRAY lorem untouched"); + is_deeply([$n_comma, ','], \@m, "lorem mode as list"); + my $m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_SCALAR lorem untouched"); + is($n_comma, $m, "lorem mode as scalar"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "mode:G_ARRAY probes untouched"); + is_deeply([7, 4], \@m, "unimodal result in list context"); + my $m = mode @probes; + is($fp, freeze(\@probes), "mode:G_SCALAR probes untouched"); + is(7, $m, "unimodal result in scalar context"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_ARRAY probes untouched"); + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([7, 4, 8], \@m, "bimodal result in list context"); + $m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_SCALAR probes untouched"); + is(7, $m, "bimodal result in scalar context"); +} + +SCOPE: +{ + my %radio_ukw_nrw = ( + "87,6" => "WDR Eins Live", + "87,7" => "WDR 5", + "87,7" => "Welle Niederrhein", + "87,7" => "WDR 5", + "87,8" => "Welle West", + "87,8" => "WDR 4", + "87,8" => "WDR 2 Dortmund", + "87,9" => "Radio HERTZ", + "88,0" => "WDR 5", + "88,1" => "Radio Hochstift", + "88,2" => "Radio Kiepenkerl", + "88,2" => "Radio Siegen", + "88,3" => "WDR 5", + "88,3" => "Radio MK", + "88,4" => "WDR 2 Köln", + "88,4" => "Radio WMW", + "88,4" => "WDR 5", + "88,5" => "WDR 5", + "88,5" => "Werrepark Radio", + "88,5" => "WDR 5", + "88,6" => "WDR 5", + "88,7" => "WDR 3", + "88,8" => "WDR 5", + "88,9" => "Deutschlandradio Kultur", + "89,0" => "Lokalradio Olpe", + "89,1" => "Deutschlandfunk (DLF)", + "89,1" => "Radio Sauerland", + "89,2" => "WDR (Test)", + "89,3" => "Antenne Unna", + "89,4" => "NE-WS 89,4", + "89,4" => "L`UniCo FM", + "89,6" => "WDR 5", + "89,7" => "WDR 3", + "90,0" => "CT das radio", + "90,0" => "WDR 5", + "90,1" => "WDR 4", + "90,1" => "Deutschlandradio Kultur", + "90,1" => "Radio 90,1", + "90,3" => "WDR 5", + "90,6" => "WDR 5", + "90,7" => "WDR 4", + "90,8" => "Radio Herne", + "90,8" => "Radio MK", + "90,9" => "Radio Q", + "91,0" => "Deutschlandradio Kultur", + "91,0" => "Deutschlandfunk (DLF)", + "91,2" => "WDR (Test)", + "91,2" => "Radio 91,2", + "91,2" => "Radio Bonn/Rhein-Sieg", + "91,3" => "Radio Lippe (geplant)", + "91,3" => "Deutschlandfunk (DLF)", + "91,3" => "BFBS Radio 1", + "91,4" => "Radio Erft", + "91,5" => "Radio MK", + "91,5" => "Deutschlandfunk (DLF)", + "91,5" => "Radio Ennepe Ruhr", + "91,7" => "WDR 4", + "91,7" => "BFBS Radio 2", + "91,7" => "WDR 3", + "91,7" => "Radio K.W.", + "91,7" => "Radio Herford", + "91,8" => "WDR 2 Wuppertal", + "91,8" => "WDR 2 Bielefeld", + "91,9" => "WDR 4", + "92,0" => "WDR 5", + "92,0" => "domradio", + "92,1" => "Radius 92,1", + "92,2" => "Radio Duisburg", + "92,2" => "Deutschlandfunk (DLF)", + "92,2" => "Radio RSG", + "92,3" => "WDR 2 Siegen", + "92,5" => "BFBS Radio 1", + "92,5" => "Radio MK", + "92,6" => "Radio WAF", + "92,7" => "WDR 3", + "92,7" => "Radio Rur", + "92,7" => "Radio Ennepe Ruhr", + "92,9" => "Radio Mülheim", + "93,0" => "Radio WMW", + "93,0" => "elDOradio", + "93,1" => "WDR 3", + "93,2" => "WDR 2 Bielefeld", + "93,3" => "WDR 2 Rhein-Ruhr", + "93,5" => "WDR 2 Siegen", + "93,6" => "WDR Eins Live", + "93,7" => "Radio Hochstift", + "93,8" => "WDR 2 Siegen", + "93,9" => "WDR 4", + "93,9" => "Deutschlandfunk (DLF)", + "93,9" => "WDR 5", + "94,1" => "WDR 2 Münster", + "94,2" => "Radio Bonn/Rhein-Sieg", + "94,2" => "WDR 2 Aachen", + "94,2" => "Deutschlandfunk (DLF)", + "94,3" => "Antenne Bethel", + "94,3" => "Radio RSG", + "94,3" => "WDR 3", + "94,5" => "Deutschlandfunk (DLF)", + "94,6" => "Radio MK", + "94,6" => "Test FM", + "94,6" => "Deutschlandradio Kultur", + "94,6" => "Radio Vest", + "94,7" => "Radio FH", + "94,7" => "Radio WAF", + "94,8" => "WDR (Test)", + "94,8" => "Radio Sauerland", + "94,9" => "Radio Herford", + "95,1" => "WDR 3", + "95,1" => "Radio Westfalica", + "95,2" => "WDR 3", + "95,4" => "Antenne Münster", + "95,5" => "Deutschlandfunk (DLF)", + "95,6" => "Radio Vest", + "95,7" => "Radio WAF", + "95,7" => "Radio Westfalica", + "95,7" => "WDR 2 Wuppertal", + "95,8" => "WDR 5", + "95,9" => "WDR 3", + "95,9" => "Triquency", + "95,9" => "Radio Gütersloh", + "96,0" => "WDR Eins Live", + "96,0" => "WDR 2 Münster", + "96,0" => "WDR 2 Bielefeld", + "96,1" => "Radio Emscher Lippe", + "96,1" => "WDR 4", + "96,1" => "Triquency", + "96,2" => "Radio Sauerland", + "96,3" => "WDR 3", + "96,3" => "Radio WAF", + "96,3" => "Deutschlandradio Kultur", + "96,4" => "Radio Siegen (geplant)", + "96,4" => "WDR 2 Bielefeld", + "96,5" => "Deutschlandradio Kultur", + "96,8" => "bonn FM", + "96,9" => "Deutschlandradio Kultur", + "96,9" => "Radio Berg", + "97,0" => "WDR 3", + "97,1" => "Antenne GL", + "97,1" => "Hochschulradio Düsseldorf", + "97,1" => "WDR 2 Siegen", + "97,2" => "107.8 Antenne AC", + "97,2" => "Radio MK", + "97,3" => "Radio Siegen", + "97,3" => "WDR 3", + "97,3" => "WDR 3", + "97,4" => "Antenne Unna", + "97,5" => "WDR 3", + "97,5" => "Deutschlandradio Kultur", + "97,6" => "Radio WMW", + "97,6" => "WDR (Test)", + "97,6" => "Radio Bielefeld", + "97,6" => "Radio Neandertal", + "97,6" => "WDR 5", + "97,7" => "Deutschlandradio Kultur", + "97,8" => "Radio Bonn/Rhein-Sieg", + "97,8" => "WDR 3", + "98,0" => "Antenne Niederrhein", + "98,1" => "WDR 3", + "98,2" => "WDR 3", + "98,2" => "WDR Eins Live", + "98,3" => "Radio Bielefeld", + "98,4" => "WDR 3", + "98,5" => "Radio Bochum", + "98,6" => "WDR 2 + Messeradio Köln", + "98,6" => "WDR 5", + "98,7" => "Radio Emscher Lippe", + "98,9" => "Deutschlandradio Kultur", + "98,9" => "Lokalradio Olpe", + "98,9" => "Radio Siegen", + "99,1" => "Hochschulradio Aachen", + "99,1" => "WDR 2 Bielefeld", + "99,2" => "WDR 2 Rhein-Ruhr", + "99,4" => "WDR 2 Siegen", + "99,4" => "Triquency", + "99,5" => "WDR 4", + "99,5" => "Radio MK", + "99,6" => "WDR 4", + "99,7" => "Radio Euskirchen", + "99,7" => "WDR 5", + "99,7" => "Radio Berg", + "99,7" => "WDR Eins Live", + "99,8" => "WDR 2 Wuppertal", + "99,9" => "Radio Bonn/Rhein-Sieg", + "100,0" => "Kölncampus", + "100,0" => "WDR 4", + "100,1" => "107.8 Antenne AC", + "100,1" => "WDR Eins Live", + "100,2" => "Radio MK", + "100,2" => "Deutschlandradio Kultur", + "100,4" => "WDR 2 Köln", + "100,5" => "WDR 4", + "100,6" => "Welle Niederrhein", + "100,7" => "WDR 4", + "100,8" => "WDR 2 Aachen", + "100,9" => "Hellweg Radio", + "101,0" => "WDR 2 Aachen", + "101,0" => "Radio Lippe", + "101,1" => "WDR 4", + "101,1" => "Deutschlandradio Kultur", + "101,2" => "WDR 4", + "101,3" => "WDR 4", + "101,6" => "BFBS Radio 2", + "101,7" => "WDR 4", + "101,7" => "domradio", + "101,8" => "WDR 2 Siegen", + "101,9" => "WDR 5", + "101,9" => "BFBS Radio 1", + "102,1" => "NE-WS 89,4", + "102,1" => "WDR 2 Siegen", + "102,2" => "Radio Essen", + "102,2" => "BFBS Radio 2", + "102,3" => "Antenne Unna", + "102,4" => "WDR Eins Live", + "102,5" => "WDR Eins Live", + "102,7" => "Deutschlandfunk (DLF)", + "102,7" => "Deutschlandfunk (DLF)", + "102,8" => "Deutschlandfunk (DLF)", + "103,0" => "BFBS Radio 1", + "103,3" => "Funkhaus Europa", + "103,6" => "Radio WMW", + "103,6" => "Hellweg Radio", + "103,7" => "WDR Eins Live", + "103,8" => "WDR 4", + "103,9" => "Radio Q", + "104,0" => "BFBS Radio 1", + "104,0" => "Radio RST", + "104,1" => "WDR 4", + "104,2" => "Radio Bonn/Rhein-Sieg", + "104,2" => "Antenne Düsseldorf", + "104,2" => "Radio Ennepe Ruhr", + "104,3" => "BFBS Radio 2", + "104,4" => "WDR 4", + "104,4" => "Deutschlandfunk (DLF)", + "104,5" => "CampusFM", + "104,5" => "Deutschlandfunk (DLF)", + "104,5" => "WDR 4", + "104,7" => "WDR Eins Live", + "104,8" => "Radio Hochstift", + "104,8" => "Radio Hochstift", + "104,9" => "Radio Sauerland", + "105,0" => "Radio Essen", + "105,0" => "Radio Lippe Welle Hamm", + "105,0" => "107.8 Antenne AC", + "105,0" => "BFBS Radio 2", + "105,1" => "BFBS Radio 1", + "105,2" => "Radio Vest", + "105,2" => "Radio Berg", + "105,2" => "Radio RST", + "105,4" => "Radio Siegen", + "105,5" => "WDR Eins Live", + "105,5" => "WDR Eins Live", + "105,6" => "CampusFM", + "105,7" => "Antenne Niederrhein", + "105,7" => "Radio Ennepe Ruhr", + "105,7" => "WDR Eins Live", + "105,7" => "Radio Berg", + "105,8" => "Radio Erft", + "106,0" => "BFBS Radio 1", + "106,1" => "Deutschlandradio Kultur", + "106,1" => "Deutschlandradio Kultur", + "106,2" => "Deutschlandradio Kultur", + "106,2" => "106.2 Radio Oberhausen", + "106,3" => "Radio Kiepenkerl", + "106,4" => "WDR Eins Live", + "106,5" => "Radio Sauerland", + "106,5" => "Radio Sauerland", + "106,5" => "Radio St. Laurentius", + "106,6" => "Radio Lippe", + "106,6" => "Radio Westfalica", + "106,6" => "Deutschlandfunk (DLF)", + "106,7" => "WDR Eins Live", + "106,8" => "Radio Gütersloh", + "106,9" => "Radio Euskirchen", + "107,0" => "WDR Eins Live", + "107,1" => "Radio Köln", + "107,2" => "WDR Eins Live", + "107,2" => "Deutschlandfunk (DLF)", + "107,3" => "WDR Eins Live", + "107,3" => "Hellweg Radio", + "107,4" => "Radio Euskirchen", + "107,4" => "Radio Kiepenkerl", + "107,4" => "Radio Lippe", + "107,4" => "Radio Wuppertal", + "107,5" => "Radio Rur", + "107,5" => "Radio Gütersloh", + "107,5" => "WDR Eins Live", + "107,6" => "Radio Leverkusen", + "107,6" => "Radio Sauerland", + "107,6" => "Radio K.W.", + "107,7" => "WDR Eins Live", + "107,7" => "Hellweg Radio", + "107,7" => "107.7 Radio Hagen", + "107,8" => "107.8 Antenne AC", + "107,8" => "Lokalradio Olpe", + "107,9" => "Radio Bonn/Rhein-Sieg", + "107,9" => "WDR Eins Live", + "107,9" => "Radio RSG", + ); + + my @m = mode values %radio_ukw_nrw; + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([14, 'WDR 5', 'WDR Eins Live'], \@m, "multimodal result in list context"); + $m = mode values %radio_ukw_nrw; + is(14, $m, "multimodal result in scalar context"); +} + +leak_free_ok( + 'mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @m = mode @probes; + }, + 'scalar mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $m = mode @probes; + }, + 'mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my @m = mode @probes; + }, + 'scalar mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $m = mode @probes; + }, + 'mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my @m = mode @probes; + }, + 'scalar mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my $m = mode @probes; + }, +); + +leak_free_ok( + 'mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @m = mode @probes; + }; + }, + 'scalar mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $m = mode @probes; + }; + }, + 'mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my @m = mode @probes; + }; + }, + 'scalar mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my $m = mode @probes; + }; + }, + 'mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my @m = mode @probes; + }; + }, + 'scalar mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my $m = mode @probes; + }; + }, +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/natatime.t liblist-moreutils-perl-0.430/t/pureperl/natatime.t --- liblist-moreutils-perl-0.416/t/pureperl/natatime.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/natatime.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,46 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @x = ('a' .. 'g'); +my $it = natatime 3, @x; +my @r; +local $" = " "; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "natatime with 3 elements"); + +my @a = (1 .. 1000); +$it = natatime 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "natatime with 1 element"); + +leak_free_ok( + natatime => sub { + my @y = 1; + my $it = natatime 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/none.t liblist-moreutils-perl-0.430/t/pureperl/none.t --- liblist-moreutils-perl-0.416/t/pureperl/none.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/none.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none { not defined } @list); +is_true(none { $_ > 10000 } @list); +is_false(none { defined } @list); +is_true(none {}); + +leak_free_ok( + none => sub { + my $ok = none { $_ == 5000 } @list; + my $ok2 = none { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none without sub' => sub { &none(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/none_u.t liblist-moreutils-perl-0.430/t/pureperl/none_u.t --- liblist-moreutils-perl-0.416/t/pureperl/none_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/none_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none_u { not defined } @list); +is_true(none_u { $_ > 10000 } @list); +is_false(none_u { defined } @list); +is_undef(none_u {}); + +leak_free_ok( + none_u => sub { + my $ok = none_u { $_ == 5000 } @list; + my $ok2 = none_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none_u without sub' => sub { &none_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/notall.t liblist-moreutils-perl-0.430/t/pureperl/notall.t --- liblist-moreutils-perl-0.416/t/pureperl/notall.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/notall.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall { !defined } @list); +is_true(notall { $_ < 10000 } @list); +is_false(notall { $_ <= 10000 } @list); +is_false(notall {}); + +leak_free_ok( + notall => sub { + my $ok = notall { $_ == 5000 } @list; + my $ok2 = notall { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall without sub' => sub { ¬all(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/notall_u.t liblist-moreutils-perl-0.430/t/pureperl/notall_u.t --- liblist-moreutils-perl-0.416/t/pureperl/notall_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/notall_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall_u { !defined } @list); +is_true(notall_u { $_ < 10000 } @list); +is_false(notall_u { $_ <= 10000 } @list); +is_undef(notall_u {}); + +leak_free_ok( + notall_u => sub { + my $ok = notall_u { $_ == 5000 } @list; + my $ok2 = notall_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall_u without sub' => sub { ¬all_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/occurrences.t liblist-moreutils-perl-0.430/t/pureperl/occurrences.t --- liblist-moreutils-perl-0.416/t/pureperl/occurrences.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/occurrences.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,92 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + + my $n_comma = scalar(split /,/, $lorem) - 1; + my $n_dot = scalar(split /\./, $lorem); # there is one at end ... mind the gap + my $n_et = scalar(split /\bet\b/, $lorem) - 1; + + my @l = @lorem; + my @o = occurrences @l; + + is(undef, $o[0], "Each word is counted"); + is(undef, $o[1], "Text to long, each word is there at least twice"); + is_deeply([','], $o[$n_comma], "$n_comma comma"); + is_deeply(['.'], $o[$n_dot], "$n_dot dots"); + is_deeply(['et'], $o[$n_et], "$n_et words 'et'"); + + @o = occurrences grep { /\w+/ } @lorem; + my $wc = reduce_0 { defined $b ? $a + $_ * scalar @$b : $a } @o; + is($wc, 124, "Words are as many as requested at www.loremipsum.de"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { ref $_ ? [sort @$_] : $_ } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +SCOPE: +{ + my @probes = ((1) x 3, undef, (2) x 4, undef, (3) x 2, undef, (4) x 7, undef, (5) x 2, undef, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { + ref $_ + ? [sort { (defined $a <=> defined $b) or $a <=> $b } @$_] + : $_ + } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], [undef], undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +leak_free_ok( + occurrences => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @o = occurrences @probes; + }, + 'scalar occurrences' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $o = occurrences @probes; + } +); + +leak_free_ok( + 'occurrences with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @o = occurrences @probes; + }; + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $o = occurrences @probes; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/one.t liblist-moreutils-perl-0.430/t/pureperl/one.t --- liblist-moreutils-perl-0.416/t/pureperl/one.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/one.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,34 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one { 1 == $_ } @list); +is_true(one { 150 == $_ } @list); +is_true(one { 300 == $_ } @list); +is_false(one { 0 == $_ } @list); +is_false(one { 1 <= $_ } @list); +is_false(one { !(127 & $_) } @list); +is_false(one { 0 } ()); + +leak_free_ok( + one => sub { + my $ok = one { 150 <= $_ } @list; + my $ok2 = one { 150 <= $_ } 1 .. 300; + } +); +is_dying('one without sub' => sub { &one(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/one_u.t liblist-moreutils-perl-0.430/t/pureperl/one_u.t --- liblist-moreutils-perl-0.416/t/pureperl/one_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/one_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,34 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one_u { 1 == $_ } @list); +is_true(one_u { 150 == $_ } @list); +is_true(one_u { 300 == $_ } @list); +is_false(one_u { 0 == $_ } @list); +is_false(one_u { 1 <= $_ } @list); +is_false(one_u { !(127 & $_) } @list); +is_undef(one_u {}); + +leak_free_ok( + one_u => sub { + my $ok = one_u { 150 <= $_ } @list; + my $ok2 = one_u { 150 <= $_ } 1 .. 300; + } +); +is_dying('one_u without sub' => sub { &one_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/onlyidx.t liblist-moreutils-perl-0.430/t/pureperl/onlyidx.t --- liblist-moreutils-perl-0.416/t/pureperl/onlyidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/onlyidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,44 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_index = __PACKAGE__->can("onlyidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(0, onlyidx { 1 == $_ } @list); +is(149, onlyidx { 150 == $_ } @list); +is(299, onlyidx { 300 == $_ } @list); +is(-1, onlyidx { 0 == $_ } @list); +is(-1, onlyidx { 1 <= $_ } @list); +is(-1, onlyidx { !(127 & $_) } @list); + +# Test aliases +is(0, only_index { 1 == $_ } @list); +is(149, only_index { 150 == $_ } @list); +is(299, only_index { 300 == $_ } @list); +is(-1, only_index { 0 == $_ } @list); +is(-1, only_index { 1 <= $_ } @list); +is(-1, only_index { !(127 & $_) } @list); + +leak_free_ok( + onlyidx => sub { + my $ok = onlyidx { 150 <= $_ } @list; + my $ok2 = onlyidx { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyidx without sub' => sub { &onlyidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/onlyres.t liblist-moreutils-perl-0.430/t/pureperl/onlyres.t --- liblist-moreutils-perl-0.416/t/pureperl/onlyres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/onlyres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,42 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_result = __PACKAGE__->can("onlyres"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is("Hallelujah", onlyres { 150 == $_ and "Hallelujah" } @list); +is(1, onlyres { 300 == $_ } @list); +is(undef, onlyres { 0 == $_ } @list); +is(undef, onlyres { 1 <= $_ } @list); +is(undef, onlyres { !(127 & $_) } @list); + +# Test aliases +is(1, only_result { 150 == $_ } @list); +is("Hallelujah", only_result { 300 == $_ and "Hallelujah" } @list); +is(undef, only_result { 0 == $_ } @list); +is(undef, only_result { 1 <= $_ } @list); +is(undef, only_result { !(127 & $_) } @list); + +leak_free_ok( + onlyres => sub { + my $ok = onlyres { 150 <= $_ } @list; + my $ok2 = onlyres { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyres without sub' => sub { &onlyres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/onlyval.t liblist-moreutils-perl-0.430/t/pureperl/onlyval.t --- liblist-moreutils-perl-0.416/t/pureperl/onlyval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/onlyval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,44 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_value = __PACKAGE__->can("onlyval"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(1, onlyval { 1 == $_ } @list); +is(150, onlyval { 150 == $_ } @list); +is(300, onlyval { 300 == $_ } @list); +is(undef, onlyval { 0 == $_ } @list); +is(undef, onlyval { 1 <= $_ } @list); +is(undef, onlyval { !(127 & $_) } @list); + +# Test aliases +is(1, only_value { 1 == $_ } @list); +is(150, only_value { 150 == $_ } @list); +is(300, only_value { 300 == $_ } @list); +is(undef, only_value { 0 == $_ } @list); +is(undef, only_value { 1 <= $_ } @list); +is(undef, only_value { !(127 & $_) } @list); + +leak_free_ok( + onlyval => sub { + my $ok = onlyval { 150 <= $_ } @list; + my $ok2 = onlyval { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyval without sub' => sub { &onlyval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/pairwise.t liblist-moreutils-perl-0.430/t/pureperl/pairwise.t --- liblist-moreutils-perl-0.416/t/pureperl/pairwise.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/pairwise.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,129 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @a = (1, 2, 3, 4, 5); +my @b = (2, 4, 6, 8, 10); +my @c = pairwise { $a + $b } @a, @b; +is_deeply(\@c, [3, 6, 9, 12, 15], "pw1"); + +@c = pairwise { $a * $b } @a, @b; # returns (2, 8, 18) +is_deeply(\@c, [2, 8, 18, 32, 50], "pw2"); + +# Did we modify the input arrays? +is_deeply(\@a, [1, 2, 3, 4, 5], "pw3"); +is_deeply(\@b, [2, 4, 6, 8, 10], "pw4"); + +# $a and $b should be aliases: test +@b = @a = (1, 2, 3); +@c = pairwise { $a++; $b *= 2 } @a, @b; +is_deeply(\@a, [2, 3, 4], "pw5"); +is_deeply(\@b, [2, 4, 6], "pw6"); +is_deeply(\@c, [2, 4, 6], "pw7"); + +# sub returns more than two items +@a = (1, 1, 2, 3, 5); +@b = (2, 3, 5, 7, 11, 13); +@c = pairwise { ($a) x $b } @a, @b; +is_deeply(\@c, [(1) x 2, (1) x 3, (2) x 5, (3) x 7, (5) x 11, (undef) x 13], "pw8"); +is_deeply(\@a, [1, 1, 2, 3, 5], "pw9"); +is_deeply(\@b, [2, 3, 5, 7, 11, 13], "pwX"); + +(@a, @b) = (); +push @a, int rand(1000) for 0 .. rand(1000); +push @b, int rand(1000) for 0 .. rand(1000); +SCOPE: +{ + local $SIG{__WARN__} = sub { }; # XXX + my @res1 = pairwise { $a + $b } @a, @b; + # Test this one more thoroughly: the XS code looks flakey + # correctness of pairwise_perl proved by human auditing. :-) + my $limit = $#a > $#b ? $#a : $#b; + my @res2 = map { $a[$_] + $b[$_] } 0 .. $limit; + is_deeply(\@res1, \@res2); +} + +@a = qw/a b c/; +@b = qw/1 2 3/; +@c = pairwise { ($a, $b) } @a, @b; +is_deeply(\@c, [qw/a 1 b 2 c 3/], "pw map"); + +SKIP: +{ + $ENV{PERL5OPT} and skip 'A defined PERL5OPT may inject extra deps crashing this test', 1; + # Test that a die inside the code-reference will not be trapped + eval { + pairwise { die "I died\n" } @a, @b; + }; + is($@, "I died\n"); +} + +leak_free_ok( + pairwise => sub { + @a = (1); + @b = (2); + @c = pairwise { $a + $b } @a, @b; + } +); + +leak_free_ok( + 'exceptional block' => sub { + @a = qw/a b c/; + @b = qw/1 2 3/; + eval { + @c = pairwise { $b == 3 and die "Primes suck!"; "$a:$b" } @a, @b; + }; + } +); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will warn here ...", 1; + my ($a, $b, @t); + eval { + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + }; + my $err = $@; + like($err, qr/Can't use lexical \$a or \$b in pairwise code block/, "pairwise die's on broken caller"); +} + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "XS will die on purpose here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, @_ }; + my ($a, $b, @t); + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + like(join("", @warns[0, 1]), qr/Use of uninitialized value.*? in addition/, "warning on broken caller"); +} + +is_dying('pairwise without sub' => sub { &pairwise(42, \@a, \@b); }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not core here ...", 2; + is_dying( + 'pairwise without first ARRAY' => sub { + @c = &pairwise(sub { }, 1, \@b); + } + ); + is_dying( + 'pairwise without second ARRAY' => sub { + @c = &pairwise(sub { }, \@a, 2); + } + ); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/part.t liblist-moreutils-perl-0.430/t/pureperl/part.t --- liblist-moreutils-perl-0.416/t/pureperl/part.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/part.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,90 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = 1 .. 12; +my $i = 0; +my @part = part { $i++ % 3 } @list; +is_deeply($part[0], [1, 4, 7, 10], " i: part % 3"); +is_deeply($part[1], [2, 5, 8, 11], " ii: part % 3"); +is_deeply($part[2], [3, 6, 9, 12], "iii: part % 3"); + +$list[2] = 0; +is($part[2][0], 3, 'Values are not aliases'); + +@list = 1 .. 12; +@part = part { 3 } @list; +is($part[0], undef, " i: part 3"); +is($part[1], undef, " ii: part 3"); +is($part[2], undef, "iii: part 3"); +is_deeply($part[3], [1 .. 12], " iv: part 3"); + +eval { + @part = part { -1 } @list; +}; +like($@, qr/^Modification of non-creatable array value attempted, subscript -1/); + +$i = 0; +@part = part { $i++ == 0 ? 0 : -1 } @list; +is_deeply($part[0], [1 .. 12], "part with negative indices"); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "Only PurePerl will warn here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, [@_] }; + @part = part { undef } @list; + is_deeply($part[0], [1 .. 12], "part with undef"); + like(join("\n", @{$warns[0]}), qr/Use of uninitialized value in array element.*line\s+\d+\.$/, "warning of undef"); + is_deeply(\@warns, [($warns[0]) x 12], "amount of similar undef warnings"); +} + +@part = part { 10000 } @list; +is_deeply($part[10000], [@list], " i: part 10_000"); +is($part[0], undef, " ii: part 10_000"); +is($part[@part / 2], undef, "iii: part 10_000"); +is($part[9999], undef, " iv: part 10_000"); + +# Changing the list in place used to destroy +# its elements due to a wrong refcnt +@list = 1 .. 10; +@list = part { $_ } @list; +foreach (1 .. 10) +{ + is_deeply($list[$_], [$_], "part \$_: $_"); +} + +leak_free_ok( + part => sub { + my @list = 1 .. 12; + my $i = 0; + my @part = part { $i++ % 3 } @list; + } +); + +leak_free_ok( + 'part with stack-growing' => sub { + # This test is from Kevin Ryde; see RT#38699 + my @part = part { grow_stack(); 1024 } 'one', 'two'; + } +); + +leak_free_ok( + 'part with exception' => sub { + my @long_list = int rand(1000) for 0 .. 1E7; + my @part = part { $_ == 1E7 and die "Too much!"; ($_ % 10) * 2 } @long_list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/qsort.t liblist-moreutils-perl-0.430/t/pureperl/qsort.t --- liblist-moreutils-perl-0.416/t/pureperl/qsort.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/qsort.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,30 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +plan skip_all => "It's insane to use a pure-perl qsort" unless $INC{'List/MoreUtils/XS.pm'}; + +my @ltn_asc = qw(2 3 5 7 11 13 17 19 23 29 31 37); +my @ltn_des = reverse @ltn_asc; +my @l; + +@l = @ltn_des; +qsort sub { $a <=> $b }, @l; +is_deeply(\@l, \@ltn_asc, "sorted ascending"); + +@l = @ltn_asc; +qsort sub { $b <=> $a }, @l; +is_deeply(\@l, \@ltn_des, "sorted descending"); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/reduce_0.t liblist-moreutils-perl-0.430/t/pureperl/reduce_0.t --- liblist-moreutils-perl-0.416/t/pureperl/reduce_0.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/reduce_0.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,49 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_0' => sub { + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + }, + 'reduce_0 X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_0 { $a + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_0 with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_0 { die } 1; + }; + } +); +is_dying('reduce_0 without sub' => sub { &reduce_0(42, 4711); }); + +done_testing + + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/reduce_1.t liblist-moreutils-perl-0.430/t/pureperl/reduce_1.t --- liblist-moreutils-perl-0.416/t/pureperl/reduce_1.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/reduce_1.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,42 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +use Scalar::Util qw(looks_like_number); + +# (this code shamelessly stolen from Math::Complex's t/Trig.t, with some mods to near) from BBYRD in RT#72638 and taken from SQL-Statement now +use Math::Trig; +my $eps = 1e-11; + +if ($^O eq 'unicos') +{ # See lib/Math/Complex.pm and t/lib/complex.t. + $eps = 1e-10; +} + +sub near ($$$;$) +{ + my $d = $_[1] ? abs($_[0] / $_[1] - 1) : abs($_[0]); + local $Test::Builder::Level = $Test::Builder::Level + 1; + looks_like_number($_[0]) or return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/nan/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/inf/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + my $e = defined $_[3] ? $_[3] : $eps; + cmp_ok($d, '<', $e, "$_[2] => near? $_[0] ~= $_[1]") or diag("near? $_[0] ~= $_[1]"); +} + +my $half_pi = reduce_1 { $a * ((4 * $b * $b) / ((2 * $b - 1) * (2 * $b + 1))) } 1 .. 750; + +near($half_pi, pi / 2, "Wallis product", 1e-2); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/reduce_u.t liblist-moreutils-perl-0.430/t/pureperl/reduce_u.t --- liblist-moreutils-perl-0.416/t/pureperl/reduce_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/reduce_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,48 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (0, 2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_u' => sub { + my @exam_results = (undef, 2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + }, + 'reduce_u X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_u { ($a || 0) + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_u { die } 1; + }; + } +); +is_dying('reduce_u without sub' => sub { &reduce_u(42, 4711); }); + +done_testing + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/samples.t liblist-moreutils-perl-0.430/t/pureperl/samples.t --- liblist-moreutils-perl-0.416/t/pureperl/samples.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/samples.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,50 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @l = (1 .. 100); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 integer probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = (1 .. 10); + my @s = samples 10, @l; + is(scalar @s, 10, "samples delivers 10 out of 10 when used as shuffle"); + my @u = uniq grep { defined $_ } @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = ('AA' .. 'ZZ'); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 strings probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any string twice"); +} + +is_dying('to much samples' => sub { my @l = (1 .. 3); samples 5, @l }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + is_dying('samples without list' => sub { samples 5 }); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/singleton.t liblist-moreutils-perl-0.430/t/pureperl/singleton.t --- liblist-moreutils-perl-0.416/t/pureperl/singleton.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/singleton.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,108 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = map { (1 .. 1000) } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(200, $u); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = map { ("aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(scalar @s, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my $fs = freeze(\@s); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $fa = freeze(\@a); + my @u = singleton map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@s]); + is($fs, freeze(\@s)); + is($fa, freeze(\@a)); + is($fu, $fs); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + @a = (@d, @s); + my @u = singleton map { $_ } @a; + is_deeply(\@u, [@s]); + @a = (@d, @s); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @sfoo = ('a', undef, 'c'); + is_deeply([singleton @foo], \@sfoo, 'one undef is supported correctly by singleton'); + @foo = ('a', 'b', '', undef, 'b', 'c', undef); + @sfoo = ('a', '', 'c'); + is_deeply([singleton @foo], \@sfoo, 'twice undef is supported correctly by singleton'); + is((scalar singleton @foo), scalar @sfoo, 'scalar twice undef is supported correctly by singleton'); +} + +leak_free_ok( + singleton => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + scalar singleton @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'singleton with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = singleton $obj, $obj; + }; + eval { + my $obj = DieOnStringify->new; + my $u = singleton $obj, $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/slideatatime.t liblist-moreutils-perl-0.430/t/pureperl/slideatatime.t --- liblist-moreutils-perl-0.416/t/pureperl/slideatatime.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/slideatatime.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,75 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +local $" = " "; +my $it; +my @r; + +my @x = ('a' .. 'g'); +$it = slideatatime 3, 3, @x; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "slideatatime as natatime with 3 elements"); + +$it = slideatatime 2, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'c d e', 'e f g', 'g']), 1, "slideatatime moving 3 elements by 2 items"); + +$it = slideatatime 1, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'b c d', 'c d e', 'd e f', 'e f g', 'f g', 'g']), 1, "slideatatime moving 3 elements by 1 item"); + +my @a = (1 .. 1000); +$it = slideatatime 1, 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "slideatatime as natatime with 1 element"); + +leak_free_ok( + slideatatime => sub { + my @y = 1; + my $it = slideatatime 2, 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + }, + 'slideatatime with exception' => sub { + my @r; + eval { + my $it = slideatatime 1, 3, @x; + while (my @vals = $it->()) + { + scalar @vals == 3 or die; + push @r, "@vals"; + } + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/slide.t liblist-moreutils-perl-0.430/t/pureperl/slide.t --- liblist-moreutils-perl-0.416/t/pureperl/slide.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/slide.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,22 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# use case provided my Michael Schwern +my @ol = (0 .. 3); +is(join(", ", slide { "$a and $b" } @ol), "0 and 1, 1 and 2, 2 and 3", "M. Schwern requested example"); + +is_dying('slide without sub' => sub { &slide(0 .. 3); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/true.t liblist-moreutils-perl-0.430/t/pureperl/true.t --- liblist-moreutils-perl-0.416/t/pureperl/true.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/true.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,36 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = true {}; +my @null_list = true {}; +is($null_scalar, 0, 'true(null) returns undef'); +is_deeply(\@null_list, [0], 'true(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, true { defined } @list); +is(0, true { not defined } @list); +is(1, true { $_ == 5000 } @list); + +leak_free_ok( + true => sub { + my $n = true { $_ == 5000 } @list; + my $n2 = true { $_ == 5000 } 1 .. 10000; + } +); +is_dying('true without sub' => sub { &true(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/uniq.t liblist-moreutils-perl-0.430/t/pureperl/uniq.t --- liblist-moreutils-perl-0.416/t/pureperl/uniq.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/uniq.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,102 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *distinct = __PACKAGE__->can("uniq"); +} + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, [1 .. 10]); + my $u = uniq @a; + is(10, $u); +} + +# Test aliases +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = distinct @a; + is_deeply(\@u, [1 .. 10]); + my $u = distinct @a; + is(10, $u); +} + +# Test strings +SCOPE: +{ + my @a = map { ("a" .. "z") } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, ["a" .. "z"]); + my $u = uniq @a; + is(26, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $fa = freeze(\@a); + my @u = uniq map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + is($fa, freeze(\@a)); + is($fu, freeze([1 .. 10, "a" .. "z"])); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my @u = uniq @a; + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @ufoo = ('a', 'b', '', undef, 'c'); + is_deeply([uniq @foo], \@ufoo, 'undef is supported correctly'); +} + +leak_free_ok( + uniq => sub { + my @a = map { (1 .. 1000) } 0 .. 1; + my @u = uniq @a; + uniq @a[1 .. 100]; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'uniq with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = uniq "foo", $obj, "bar", $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/upper_bound.t liblist-moreutils-perl-0.430/t/pureperl/upper_bound.t --- liblist-moreutils-perl-0.416/t/pureperl/upper_bound.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/upper_bound.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,65 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (upper_bound { $_ <=> 0 } @list), "upper bound 0"); +is(2, (upper_bound { $_ <=> 1 } @list), "upper bound 1"); +is(4, (upper_bound { $_ <=> 2 } @list), "upper bound 2"); +is(14, (upper_bound { $_ <=> 4 } @list), "upper bound 4"); +is(scalar @list, (upper_bound { $_ <=> 19 } @list), "upper bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i, (upper_bound { $_ - $j } @list), "placed $j"); + is($i + 1, (upper_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (upper_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (upper_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + upper_bound => sub { + my $elem = int(rand(1000)) + 1; + upper_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + upper_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + upper_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('upper_bound without sub' => sub { &upper_bound(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/pureperl/XS.t liblist-moreutils-perl-0.430/t/pureperl/XS.t --- liblist-moreutils-perl-0.416/t/pureperl/XS.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/XS.t 2020-10-21 14:47:09.000000000 +0000 @@ -1,10 +1,48 @@ #!perl -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 1; +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +$INC{'List/MoreUtils.pm'} or plan skip_all => "Unreasonable unless loaded via List::MoreUtils"; + +is(List::MoreUtils::_XScompiled(), 0 + defined($INC{'List/MoreUtils/XS.pm'}), "_XScompiled"); + +done_testing(); + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. -require LMU::Test::XS; +=cut -LMU::Test::XS->run_tests; diff -Nru liblist-moreutils-perl-0.416/t/pureperl/zip6.t liblist-moreutils-perl-0.430/t/pureperl/zip6.t --- liblist-moreutils-perl-0.416/t/pureperl/zip6.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/pureperl/zip6.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,60 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use lib ("t/lib"); +use List::MoreUtils (":all"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + is_deeply(\@z, [['a', 1], ['b', 2], ['c', 3], ['d', 4]], "zip6 two lists with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip6 @a, @b, @c; + is_deeply( + \@z, + [['x', 1, 'zip'], [undef, 2, 'zap'], [undef, undef, 'zot']], + "zip6 three list with increasing count of elements" + ); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = zip6 @a, @d; + is_deeply( + \@z, + [[1, undef], [2, undef], [3, undef], [4, undef], [5, undef], [6, undef], [7, undef], [8, undef], [9, undef], [10, undef]], + "zip6 one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + zip6 => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + } +); +is_dying('zip6 with a list, not at least two arrays' => sub { &zip6(1, 2); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/ab.t liblist-moreutils-perl-0.430/t/xs/ab.t --- liblist-moreutils-perl-0.416/t/xs/ab.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/ab.t 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -#!perl - -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 0; -END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS - -require LMU::Test::ab; - -LMU::Test::ab->run_tests; - diff -Nru liblist-moreutils-perl-0.416/t/xs/after_incl.t liblist-moreutils-perl-0.430/t/xs/after_incl.t --- liblist-moreutils-perl-0.416/t/xs/after_incl.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/after_incl.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = after_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [5, 6, 7, 8, 9], "after 5, included"); + +@x = after_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after_incl { /b/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "after /b/, included"); + +leak_free_ok( + after_incl => sub { + @x = after_incl { /z/ } qw{bar baz foo}; + } +); +is_dying('after_incl without sub' => sub { &after_incl(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/after.t liblist-moreutils-perl-0.430/t/xs/after.t --- liblist-moreutils-perl-0.416/t/xs/after.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/after.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,35 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = after { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [6, 7, 8, 9], "after 5"); + +@x = after { /foo/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = after { /b/ } qw{bar baz foo }; +is_deeply(\@x, [qw{baz foo }], "after /b/"); + +leak_free_ok( + after => sub { + @x = after { /z/ } qw{bar baz foo}; + } +); +is_dying('after without sub' => sub { &after(42, 4711); }); + +@x = (1, after { /foo/ } qw(abc def)); +is_deeply(\@x, [1], "check XS implementation doesn't mess up stack"); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/all.t liblist-moreutils-perl-0.430/t/xs/all.t --- liblist-moreutils-perl-0.416/t/xs/all.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/all.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all { defined } @list); +is_true(all { $_ > 0 } @list); +is_false(all { $_ < 5000 } @list); +is_true(all {}); + +leak_free_ok( + all => sub { + my $ok = all { $_ == 5000 } @list; + my $ok2 = all { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all without sub' => sub { &all(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/all_u.t liblist-moreutils-perl-0.430/t/xs/all_u.t --- liblist-moreutils-perl-0.416/t/xs/all_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/all_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(all_u { defined } @list); +is_true(all_u { $_ > 0 } @list); +is_false(all_u { $_ < 5000 } @list); +is_undef(all_u {}); + +leak_free_ok( + all_u => sub { + my $ok = all_u { $_ == 5000 } @list; + my $ok2 = all_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('all_u without sub' => sub { &all_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/any.t liblist-moreutils-perl-0.430/t/xs/any.t --- liblist-moreutils-perl-0.416/t/xs/any.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/any.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,41 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any { $_ == 5000 } @list); +is_true(any { $_ == 5000 } 1 .. 10000); +is_true(any { defined } @list); +is_false(any { not defined } @list); +is_true(any { not defined } undef); +is_false(any {}); + +leak_free_ok( + any => sub { + my $ok = any { $_ == 5000 } @list; + my $ok2 = any { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any { die } 1; + }; + } +); +is_dying('any without sub' => sub { &any(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/any_u.t liblist-moreutils-perl-0.430/t/xs/any_u.t --- liblist-moreutils-perl-0.416/t/xs/any_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/any_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,41 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(any_u { $_ == 5000 } @list); +is_true(any_u { $_ == 5000 } 1 .. 10000); +is_true(any_u { defined } @list); +is_false(any_u { not defined } @list); +is_true(any_u { not defined } undef); +is_undef(any_u {}); + +leak_free_ok( + any_u => sub { + my $ok = any_u { $_ == 5000 } @list; + my $ok2 = any_u { $_ == 5000 } 1 .. 10000; + } +); +leak_free_ok( + 'any_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = any_u { die } 1; + }; + } +); +is_dying('any_u without sub' => sub { &any_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/apply.t liblist-moreutils-perl-0.430/t/xs/apply.t --- liblist-moreutils-perl-0.416/t/xs/apply.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/apply.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,80 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Test the null case +my $null_scalar = apply {}; +is($null_scalar, undef, 'apply(null) returns undef'); + +my @null_list = apply {}; +is_deeply(\@null_list, [], 'apply(null) returns null list'); + +# Normal cases +my @list = (0 .. 9); +my @list1 = apply { $_++ } @list; +is_deeply(\@list, [0 .. 9], "original numbers untouched"); +is_deeply(\@list1, [1 .. 10], "returned numbers increased"); +@list = (" foo ", " bar ", " ", "foobar"); +@list1 = apply { s/^\s+|\s+$//g } @list; +is_deeply(\@list, [" foo ", " bar ", " ", "foobar"], "original strings untouched"); +is_deeply(\@list1, ["foo", "bar", "", "foobar"], "returned strings stripped"); +my $item = apply { s/^\s+|\s+$//g } @list; +is($item, "foobar"); + +# RT 96596 +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + eval { my @a = \&apply(1, 2); }; + my $err = $@; + like($err, qr/\QList::MoreUtils::XS::apply(code, ...)\E/, "apply must be reasonable invoked"); +} + +# RT 38630 +SCOPE: +{ + # wrong results from apply() [XS] + @list = (1 .. 4); + @list1 = apply { grow_stack(); $_ = 5; } @list; + is_deeply(\@list, [1 .. 4]); + is_deeply(\@list1, [(5) x 4]); +} + +leak_free_ok( + apply => sub { + @list = (1 .. 4); + @list1 = apply + { + grow_stack(); + $_ = 5; + } + @list; + } +); + +SCOPE: +{ + leak_free_ok( + 'dying callback during apply' => sub { + my @l = (1 .. 4); + eval { + my @l1 = apply { $_ % 2 or die "Even!"; $_ %= 2; } @l; + }; + } + ); +} + +is_dying('apply without sub' => sub { &apply(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/arrayify.t liblist-moreutils-perl-0.430/t/xs/arrayify.t --- liblist-moreutils-perl-0.416/t/xs/arrayify.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/arrayify.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,125 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]], 18); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 18], "linear flattened int mix i"); +} + +SCOPE: +{ + my @in = (1 .. 4, [[5 .. 11]], 12, [[13 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened int mix ii"); +} + +SCOPE: +{ + # typical structure when parsing XML using XML::Hash::XS + my %src = ( + root => { + foo_list => {foo_elem => {attr => 42}}, + bar_list => {bar_elem => [{hummel => 2}, {hummel => 3}, {hummel => 5}]} + } + ); + my @foo_elems = arrayify $src{root}->{foo_list}->{foo_elem}; + is_deeply(\@foo_elems, [{attr => 42}], "arrayified struct with one element"); + my @bar_elems = arrayify $src{root}->{bar_list}->{bar_elem}; + is_deeply(\@bar_elems, [{hummel => 2}, {hummel => 3}, {hummel => 5}], "arrayified struct with three elements"); +} + +SCOPE: +{ + my @in; + tie @in, "Tie::StdArray"; + @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mix"); +} + +SCOPE: +{ + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + is_deeply(\@out, [1 .. 17], "linear flattened magic int mixture"); +} + +SCOPE: +{ + my @in = (qw(av_make av_undef av_clear), [qw(av_push av_pop)], qw(av_fetch av_store), [['av_shift'], ['av_unshift']]); + my @out = arrayify @in; + is_deeply( + \@out, + [qw(av_make av_undef av_clear av_push av_pop av_fetch av_store av_shift av_unshift)], + "linear flattened string mix i" + ); +} + +leak_free_ok( + arrayify => sub { + my @in = (1 .. 4, [5 .. 7], 8 .. 11, [[12 .. 17]]); + my @out = arrayify @in; + }, + 'arrayify magic' => sub { + my (@in, @inner, @innest); + tie @in, "Tie::StdArray"; + tie @inner, "Tie::StdArray"; + tie @innest, "Tie::StdArray"; + @inner = (5 .. 7); + @innest = ([12 .. 17]); + @in = (1 .. 4, \@inner, 8 .. 11, [@innest]); + my @out = arrayify @in; + } +); + +SKIP: +{ + leak_free_ok( + 'arrayify with exception in overloading stringify at begin' => sub { + my @in = ( + DieOnStringify->new, qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']] + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + }, + ); + leak_free_ok( + 'arrayify with exception in overloading stringify at end' => sub { + my @in = ( + qw(av_make av_undef av_clear), + [qw(av_push av_pop)], + qw(av_fetch av_store), + [['av_shift'], ['av_unshift']], + DieOnStringify->new + ); + eval { my @out = arrayify @in; }; + diag($@) if ($@); + } + ); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/before_incl.t liblist-moreutils-perl-0.430/t/xs/before_incl.t --- liblist-moreutils-perl-0.416/t/xs/before_incl.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/before_incl.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = before_incl { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4, 5], "before 5, included"); + +@x = before_incl { /foo/ } qw{bar baz}; +is_deeply(\@x, [qw{bar baz}]); + +@x = before_incl { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz foo}], "before /f/, included"); + +leak_free_ok( + before_incl => sub { + @x = before_incl { /z/ } qw{ bar baz foo }; + } +); +is_dying('before_incl without sub' => sub { &before_incl(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/before.t liblist-moreutils-perl-0.430/t/xs/before.t --- liblist-moreutils-perl-0.416/t/xs/before.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/before.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,32 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = before { $_ % 5 == 0 } 1 .. 9; +is_deeply(\@x, [1, 2, 3, 4], "before 5"); + +@x = before { /b/ } qw{bar baz}; +is_deeply(\@x, [], 'Got the null list'); + +@x = before { /f/ } qw{bar baz foo}; +is_deeply(\@x, [qw{bar baz}], "before /f/"); + +leak_free_ok( + before => sub { + @x = before { /f/ } qw{ bar baz foo }; + } +); +is_dying('before without sub' => sub { &before(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/binsert.t liblist-moreutils-perl-0.430/t/xs/binsert.t --- liblist-moreutils-perl-0.416/t/xs/binsert.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/binsert.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,148 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @list = (); + is(0, (binsert { $_ cmp "Hello" } "Hello", @list), "Inserting into empty list"); + is(1, (binsert { $_ cmp "world" } "world", @list), "Inserting into one-item list"); +} + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (@odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements into even list succeeded"); + +@in = @even; +@expected = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert odd elements reversely into even list succeeded"); + +@in = @odd; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements into odd list succeeded"); + +@in = @odd; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert even elements reversely into odd list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (@even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements into even list succeeded"); + +@in = @even; +@expected = map { $_, $_ } @in; +foreach my $v (reverse @even) +{ + binsert { $_ <=> $v } $v, @in; +} +is_deeply(\@in, \@expected, "binsert existing even elements reversely into even list succeeded"); + +leak_free_ok( + 'binsert random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert existing random' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = 2 * (int(rand(100)) + 1); + binsert { $_ <=> $elem } $elem, @list; + }, + 'binsert odd into even' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into odd' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert odd into odd' => sub { + my @list = @odd; + foreach my $elem (@odd) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, + 'binsert even into even' => sub { + my @list = @even; + foreach my $elem (@even) + { + binsert { $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert random with stack-growing' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + }, + 'binsert odd with stack-growing' => sub { + my @list = @even; + foreach my $elem (@odd) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, + 'binsert even with stack-growing' => sub { + my @list = @odd; + foreach my $elem (@even) + { + binsert { grow_stack(); $_ <=> $elem } $elem, @list; + } + }, +); + +leak_free_ok( + 'binsert with stack-growing and exception' => sub { + my @list = map { $_ * 2 } 1 .. 100; + my $elem = int(rand(100)) + 1; + eval { + binsert { grow_stack(); $_ <=> $elem or die "Goal!"; $_ <=> $elem } $elem, @list; + }; + } +); + +is_dying('binsert without sub' => sub { &binsert(42, @even); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/bremove.t liblist-moreutils-perl-0.430/t/xs/bremove.t --- liblist-moreutils-perl-0.416/t/xs/bremove.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/bremove.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,119 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @even = map { $_ * 2 } 1 .. 100; +my @odd = map { $_ * 2 - 1 } 1 .. 100; +my (@expected, @in); + +@expected = @even; +@in = mesh @odd, @even; +foreach my $v (@odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @odd) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all odd elements reversely succeeded"); + +@expected = @odd; +@in = mesh @odd, @even; +foreach my $v (@even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v in order removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements succeeded"); + +@in = mesh @odd, @even; +foreach my $v (reverse @even) +{ + is($v, (bremove { $_ <=> $v } @in), "$v reverse ordered removed"); +} +is_deeply(\@in, \@expected, "bremove all even elements reversely succeeded"); + +# test from shawnlaffan from GH issue #2 of List-MoreUtils-XS +SCOPE: +{ + my @list = ('somestring'); + my $target = $list[0]; + is($target, (bremove { $_ cmp $target } @list), 'removed from single item list'); +} + +leak_free_ok( + 'bremove first' => sub { + my @list = (1 .. 100); + my $v = $list[0]; + bremove { $_ <=> $v } @list; + }, + 'bremove last' => sub { + my @list = (1 .. 100); + my $v = $list[-1]; + bremove { $_ <=> $v } @list; + }, + 'bremove middle' => sub { + my @list = (1 .. 100); + my $v = $list[int($#list / 2)]; + bremove { $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove last with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + bremove { grow_stack(); $_ <=> $v } @list; + }, + 'bremove middle with stack-growing' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + bremove { grow_stack(); $_ <=> $v } @list; + }, +); + +leak_free_ok( + 'bremove first with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[0]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove last with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[-1]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, + 'bremove middle with stack-growing and exception' => sub { + my @list = mesh @odd, @even; + my $v = $list[int($#list / 2)]; + eval { + bremove { grow_stack(); $_ <=> $v or die "Goal!"; $_ <=> $v } @list; + }; + }, +); +is_dying('bremove without sub' => sub { &bremove(42, @even); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/bsearchidx.t liblist-moreutils-perl-0.430/t/xs/bsearchidx.t --- liblist-moreutils-perl-0.416/t/xs/bsearchidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/bsearchidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,52 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $i (0 .. $#in) +{ + is($i, bsearchidx { $_ - $in[$i] } @list); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearchidx { $_ - $elem } @list; + is(-1, $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + bsearchidx { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + bsearchidx { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + bsearchidx { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearchidx without sub' => sub { &bsearchidx(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/bsearch.t liblist-moreutils-perl-0.430/t/xs/bsearch.t --- liblist-moreutils-perl-0.416/t/xs/bsearch.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/bsearch.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,57 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = my @in = 1 .. 1000; +for my $elem (@in) +{ + ok(scalar bsearch { $_ - $elem } @list); +} +for my $elem (@in) +{ + my ($e) = bsearch { $_ - $elem } @list; + ok($e == $elem); +} +my @out = (-10 .. 0, 1001 .. 1011); +for my $elem (@out) +{ + my $r = bsearch { $_ - $elem } @list; + ok(!defined $r); +} + +leak_free_ok( + bsearch => sub { + my $elem = int(rand(1000)) + 1; + scalar bsearch { $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing' => sub { + my $elem = int(rand(1000)); + scalar bsearch { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'bsearch with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + scalar bsearch { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('bsearch without sub' => sub { &bsearch(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/duplicates.t liblist-moreutils-perl-0.430/t/xs/duplicates.t --- liblist-moreutils-perl-0.416/t/xs/duplicates.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/duplicates.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,121 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves numbers untouched"); + is_deeply(\@u, [@d], "duplicates of numbers"); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves numbers untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my $fd = freeze(\@d); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@d], "duplicates of numbers/strings mixture"); + is($fd, freeze(\@d), "frozen duplicates of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + is($fu, $fd); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of numbers/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my @u = duplicates @a; + is_deeply(\@u, [@d], "duplicates of tied array of numbers/strings mixture"); + is($fa, freeze(\@a), "duplicates:G_ARRAY leaves mixture untouched"); + @a = (@u, @d); + $fa = freeze(\@a); + my $u = duplicates @a; + is($fa, freeze(\@a), "duplicates:G_SCALAR leaves mixture untouched"); + is(scalar @d, $u, "scalar result of duplicates of tied array of numbers/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my @dfoo = ('b', '', undef); + is_deeply([duplicates @foo], \@dfoo, "two undef's are supported correctly by duplicates"); + @foo = ('a', undef, 'b', '', 'b', 'c', ''); + @dfoo = ('b', ''); + is_deeply([duplicates @foo], \@dfoo, 'one undef is ignored correctly by duplicates'); + is((scalar duplicates @foo), scalar @dfoo, 'scalar one undef is ignored correctly by duplicates'); +} + +leak_free_ok( + duplicates => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = duplicates @a; + scalar duplicates @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'duplicates with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my @u = duplicates @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $u = duplicates 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; + + + diff -Nru liblist-moreutils-perl-0.416/t/xs/each_array.t liblist-moreutils-perl-0.430/t/xs/each_array.t --- liblist-moreutils-perl-0.416/t/xs/each_array.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/each_array.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,138 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw{ a 2 -1 x }; + my $it = each_array @a, @b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); + + # This used to give "semi-panic: attempt to dup freed string" + # See: + my $ea = each_arrayref([1 .. 26], ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@b, ['A' .. 'Z']); + + # And this even used to dump core + my @nums = 1 .. 26; + $ea = each_arrayref(\@nums, ['A' .. 'Z']); + (@a, @b) = (); + while (my ($a, $b) = $ea->()) + { + push @a, $a; + push @b, $b; + } + is_deeply(\@a, [1 .. 26]); + is_deeply(\@a, \@nums); + is_deeply(\@b, ['A' .. 'Z']); +} + +SCOPE: +{ + my @a = (7, 3, 'a', undef, 'r'); + my @b = qw/a 2 -1 x/; + + my $it = each_arrayref \@a, \@b; + my (@r, @idx); + while (my ($a, $b) = $it->()) + { + push @r, $a, $b; + push @idx, $it->('index'); + } + + # Do I segfault? I shouldn't. + $it->(); + + is_deeply(\@r, [7, 'a', 3, 2, 'a', -1, undef, 'x', 'r', undef]); + is_deeply(\@idx, [0 .. 4]); + + # Testing two iterators on the same arrays in parallel + @a = (1, 3, 5); + @b = (2, 4, 6); + my $i1 = each_array @a, @b; + my $i2 = each_array @a, @b; + @r = (); + while (my ($a, $b) = $i1->() and my ($c, $d) = $i2->()) + { + push @r, $a, $b, $c, $d; + } + is_deeply(\@r, [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6]); + + # Input arrays must not be modified + is_deeply(\@a, [1, 3, 5]); + is_deeply(\@b, [2, 4, 6]); +} + +# Note that the leak_free_ok tests for each_array and each_arrayref +# should not be run until either of them has been called at least once +# in the current perl. That's because calling them the first time +# causes the runtime to allocate some memory used for the OO structures +# that their implementation uses internally. +leak_free_ok( + each_array => sub { + my @a = (1); + my $it = each_array @a; + while (my ($a) = $it->()) + { + } + } +); +leak_free_ok( + each_arrayref => sub { + my @a = (1); + my $it = each_arrayref \@a; + while (my ($a) = $it->()) + { + } + } +); +is_dying('each_array without sub' => sub { &each_array(42, 4711); }); +is_dying('each_arrayref without sub' => sub { &each_arrayref(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/equal_range.t liblist-moreutils-perl-0.430/t/xs/equal_range.t --- liblist-moreutils-perl-0.416/t/xs/equal_range.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/equal_range.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,48 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is_deeply([0, 0], [equal_range { $_ <=> 0 } @list], "equal range 0"); +is_deeply([0, 2], [equal_range { $_ <=> 1 } @list], "equal range 1"); +is_deeply([2, 4], [equal_range { $_ <=> 2 } @list], "equal range 2"); +is_deeply([10, 14], [equal_range { $_ <=> 4 } @list], "equal range 4"); +is_deeply([(scalar @list) x 2], [equal_range { $_ <=> 19 } @list], "equal range 19"); + +my @in = @list = 1 .. 100; +leak_free_ok( + equal_range => sub { + my $elem = int(rand(101)) + 1; + equal_range { $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing' => sub { + my $elem = int(rand(101)); + equal_range { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'equal_range with stack-growing and exception' => sub { + my $elem = int(rand(101)); + eval { + equal_range { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('equal_range without sub' => sub { &equal_range(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/false.t liblist-moreutils-perl-0.430/t/xs/false.t --- liblist-moreutils-perl-0.416/t/xs/false.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/false.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,36 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = false {}; +my @null_list = false {}; +is($null_scalar, 0, 'false(null) returns undef'); +is_deeply(\@null_list, [0], 'false(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, false { not defined } @list); +is(0, false { defined } @list); +is(1, false { $_ > 1 } @list); + +leak_free_ok( + false => sub { + my $n = false { $_ == 5000 } @list; + my $n2 = false { $_ == 5000 } 1 .. 10000; + } +); +is_dying('false without sub' => sub { &false(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/firstidx.t liblist-moreutils-perl-0.430/t/xs/firstidx.t --- liblist-moreutils-perl-0.416/t/xs/firstidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/firstidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,43 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_index = __PACKAGE__->can("firstidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(4999, (firstidx { $_ >= 5000 } @list), "firstidx"); +is(-1, (firstidx { not defined } @list), "invalid firstidx"); +is(0, (firstidx { defined } @list), "real firstidx"); +is(-1, (firstidx {}), "empty firstidx"); + +SKIP: +{ + # Test the alias + is(4999, first_index { $_ >= 5000 } @list); + is(-1, first_index { not defined } @list); + is(0, first_index { defined } @list); + is(-1, first_index {}); +} + +leak_free_ok( + firstidx => sub { + my $i = firstidx { $_ >= 5000 } @list; + my $i2 = firstidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('firstidx without sub' => sub { &firstidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/firstres.t liblist-moreutils-perl-0.430/t/xs/firstres.t --- liblist-moreutils-perl-0.416/t/xs/firstres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/firstres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,38 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_result = __PACKAGE__->can("firstres"); +} + +use Test::More; +use Test::LMU; + +my $x = firstres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = firstres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = first_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = first_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstres => sub { + $x = firstres { $_ > 5 } 4 .. 9; + } +); +is_dying('firstres without sub' => sub { &firstres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/firstval.t liblist-moreutils-perl-0.430/t/xs/firstval.t --- liblist-moreutils-perl-0.416/t/xs/firstval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/firstval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,39 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *first_value = __PACKAGE__->can("firstval"); +} + +use Test::More; +use Test::LMU; + +my $x = firstval { $_ > 5 } 4 .. 9; +is($x, 6); +$x = firstval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(firstval { $_ > 5 }); + +# Test aliases +$x = first_value { $_ > 5 } 4 .. 9; +is($x, 6); +$x = first_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + firstval => sub { + $x = firstval { $_ > 5 } 4 .. 9; + } +); +is_dying('firstval without sub' => sub { &firstval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/frequency.t liblist-moreutils-perl-0.430/t/xs/frequency.t --- liblist-moreutils-perl-0.416/t/xs/frequency.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/frequency.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,128 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = (1 .. 1000); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves numbers untouched"); + is_deeply(\%f, {%e}, "frequency of numbers"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G:SCALAR leaves numbers untouched"); + is(scalar keys %e, $f, "scalar result of frequency of numbers"); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = ("aa" .. "zz"); + my @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves strings untouched"); + is_deeply(\%f, {%e}, "frequency of strings"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves strings untouched"); + is(scalar keys %e, $f, "scalar result of frequency of strings"); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + my @a = (@d, @s, @d); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my $fa = freeze(\@a); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of number/strings mixture"); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = (1 .. 1000, "aa" .. "zz"); + @a = (@d, @s, @d); + my $fa = freeze(\@a); + my %e = ((map { $_ => 2 } @d), map { $_ => 1 } @s); + my %f = frequency @a; + is($fa, freeze(\@a), "frequency:G_ARRAY leaves tied array of number/strings mixture untouched"); + is_deeply(\%f, {%e}, "frequency of tied array of number/strings mixture"); + my $f = frequency @a; + is($fa, freeze(\@a), "frequency:G_SCALAR leaves tied array of number/strings mixture untouched"); + is(scalar keys %e, $f, "scalar result of frequency of tied array of number/strings mixture"); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', '', undef); + my %e = ( + a => 1, + b => 2, + '' => 2, + c => 1 + ); + my @f = frequency @foo; + my $seen_undef; + ref $f[-2] and ref $f[-2] eq "SCALAR" and not defined ${$f[-2]} and (undef, $seen_undef) = splice @f, -2, 2, (); + my %f = @f; + is_deeply(\%f, \%e, "stuff around undef's is supported correctly by frequency"); + is($seen_undef, 2, "two undef's are supported correctly by frequency"); +} + +leak_free_ok( + frequency => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my %f = frequency @a; + }, + 'scalar frequency' => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $f = frequency @a; + } +); + +leak_free_ok( + 'frequency with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @foo = ('a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj); + my %f = frequency @foo; + }; + eval { + my $obj = DieOnStringify->new; + my $f = frequency 'a', 'b', '', undef, $obj, 'b', 'c', '', undef, $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/Functions.t liblist-moreutils-perl-0.430/t/xs/Functions.t --- liblist-moreutils-perl-0.416/t/xs/Functions.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/Functions.t 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -#!perl - -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 0; -END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS - -require LMU::Test::Functions; - -LMU::Test::Functions->run_tests; - diff -Nru liblist-moreutils-perl-0.416/t/xs/Import.t liblist-moreutils-perl-0.430/t/xs/Import.t --- liblist-moreutils-perl-0.416/t/xs/Import.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/Import.t 2020-10-21 14:47:09.000000000 +0000 @@ -1,10 +1,92 @@ #!perl -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 0; +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @pure_funcs = qw(any all none notall one + any_u all_u none_u notall_u one_u + true false + insert_after insert_after_string + apply indexes + after after_incl before before_incl + firstidx lastidx onlyidx + firstval lastval onlyval + firstres lastres onlyres + singleton + each_array each_arrayref + pairwise natatime + mesh uniq + minmax part + bsearch bsearchidx); +my @v0_33 = qw(sort_by nsort_by); +my %alias_list = ( + v0_22 => { + first_index => "firstidx", + last_index => "lastidx", + first_value => "firstval", + last_value => "lastval", + zip => "mesh", + }, + v0_33 => { + distinct => "uniq", + }, + v0_400 => { + first_result => "firstres", + only_index => "onlyidx", + only_value => "onlyval", + only_result => "onlyres", + last_result => "lastres", + bsearch_index => "bsearchidx", + }, +); + +can_ok(__PACKAGE__, $_) for @pure_funcs; + +SKIP: +{ + $INC{'List/MoreUtils.pm'} or skip "List::MoreUtils::XS doesn't alias", 1; + can_ok(__PACKAGE__, $_) for @v0_33; + can_ok(__PACKAGE__, $_) for map { keys %$_ } values %alias_list; +} + +done_testing; + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. -require LMU::Test::Import; +=cut -LMU::Test::Import->run_tests; diff -Nru liblist-moreutils-perl-0.416/t/xs/indexes.t liblist-moreutils-perl-0.430/t/xs/indexes.t --- liblist-moreutils-perl-0.416/t/xs/indexes.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/indexes.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,77 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = indexes { $_ > 5 } (4 .. 9); +is_deeply(\@x, [2 .. 5], "indexes > 5 ..."); +@x = indexes { $_ > 5 } (1 .. 4); +is_deeply(\@x, [], 'Got the null list'); + +my ($lr, @s, @n, @o, @e); +leak_free_ok( + indexes => sub { + $lr = 1; + @s = indexes { $_ > 5 } (4 .. 9); + @n = indexes { $_ > 5 } (1 .. 5); + @o = indexes { $_ & 1 } (10 .. 15); + @e = indexes { !($_ & 1) } (10 .. 15); + } +); +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +@n = map { $_ + 1 } @o = (0 .. 9); +@x = indexes { ++$_ > 7 } @o; +is_deeply(\@o, \@n, "indexes behaves like grep on modified \$_"); +is_deeply(\@x, [7 .. 9], "indexes/modify"); + +not_dying( + 'indexes_on_set' => sub { + @x = indexes { ++$_ > 7 } (0 .. 9); + } +); +is_deeply(\@x, [7 .. 9], "indexes/modify set"); + +leak_free_ok( + indexes => sub { + @s = indexes { grow_stack; $_ > 5 } (4 .. 9); + @n = indexes { grow_stack; $_ > 5 } (1 .. 4); + @o = indexes { grow_stack; $_ & 1 } (10 .. 15); + @e = indexes { grow_stack; !($_ & 1) } (10 .. 15); + }, + 'indexes interrupted by exception' => sub { + eval { + @s = indexes { $_ > 10 and die "range exceeded"; $_ > 5 } (1 .. 15); + }; + }, +); + +$lr and is_deeply(\@s, [2 .. 5], "indexes/leak: some"); +$lr and is_deeply(\@n, [], "indexes/leak: none"); +$lr and is_deeply(\@o, [1, 3, 5], "indexes/leak: odd"); +$lr and is_deeply(\@e, [0, 2, 4], "indexes/leak: even"); + +my $have_scalar_util = eval { require Scalar::Util; 1 }; + +if ($have_scalar_util) +{ + my $ref = \(indexes(sub { 1 }, 123)); + Scalar::Util::weaken($ref); + is($ref, undef, "weakened away"); +} +is_dying('indexes without sub' => sub { &indexes(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/insert_after_string.t liblist-moreutils-perl-0.430/t/xs/insert_after_string.t --- liblist-moreutils-perl-0.416/t/xs/insert_after_string.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/insert_after_string.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,43 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after_string "a", "longer" => @list; +is(join(' ', @list), "This is a longer list"); +@list = (undef, qw{This is a list}); +insert_after_string "a", "longer", @list; +shift @list; +is(join(' ', @list), "This is a longer list"); +@list = ("This\0", "is\0", "a\0", "list\0"); +insert_after_string "a\0", "longer\0", @list; +is(join(' ', @list), "This\0 is\0 a\0 longer\0 list\0"); + +leak_free_ok( + insert_after_string => sub { + @list = qw{This is a list}; + insert_after_string "a", "longer", @list; + } +); +leak_free_ok( + 'insert_after_string with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after_string "a", "longer", @list; + }; + } +); +is_dying('insert_after_string without array' => sub { &insert_after_string(42, 4711, "13"); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/insert_after.t liblist-moreutils-perl-0.430/t/xs/insert_after.t --- liblist-moreutils-perl-0.416/t/xs/insert_after.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/insert_after.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,50 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = qw{This is a list}; +insert_after { $_ eq "a" } "longer" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { 0 } "bla" => @list; +is(join(' ', @list), "This is a longer list"); +insert_after { $_ eq "list" } "!" => @list; +is(join(' ', @list), "This is a longer list !"); +@list = (qw{This is}, undef, qw{list}); +insert_after { not defined($_) } "longer" => @list; +$list[2] = "a"; +is(join(' ', @list), "This is a longer list"); + +leak_free_ok( + insert_after => sub { + @list = qw{This is a list}; + insert_after { $_ eq 'a' } "longer" => @list; + } +); +leak_free_ok( + 'insert_after with exception' => sub { + eval { + my @list = (qw{This is}, DieOnStringify->new, qw{a list}); + insert_after { $_ eq 'a' } "longer" => @list; + }; + } +); +is_dying('insert_after without sub' => sub { &insert_after(42, 4711, [qw(die bart die)]); }); +is_dying('insert_after without sub and array' => sub { &insert_after(42, 4711, "13"); }); +is_dying( + 'insert_after without array' => sub { + &insert_after(sub { }, 4711, "13"); + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/lastidx.t liblist-moreutils-perl-0.430/t/xs/lastidx.t --- liblist-moreutils-perl-0.416/t/xs/lastidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/lastidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,40 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_index = __PACKAGE__->can("lastidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 10000); +is(9999, lastidx { $_ >= 5000 } @list); +is(-1, lastidx { not defined } @list); +is(9999, lastidx { defined } @list); +is(-1, lastidx {}); + +# Test aliases +is(9999, last_index { $_ >= 5000 } @list); +is(-1, last_index { not defined } @list); +is(9999, last_index { defined } @list); +is(-1, last_index {}); + +leak_free_ok( + lastidx => sub { + my $i = lastidx { $_ >= 5000 } @list; + my $i2 = lastidx { $_ >= 5000 } 1 .. 10000; + } +); +is_dying('lastidx without sub' => sub { &lastidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/lastres.t liblist-moreutils-perl-0.430/t/xs/lastres.t --- liblist-moreutils-perl-0.416/t/xs/lastres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/lastres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,38 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_result = __PACKAGE__->can("lastres"); +} + +use Test::More; +use Test::LMU; + +my $x = lastres { 2 * ($_ > 5) } 4 .. 9; +is($x, 2); +$x = lastres { $_ > 5 } 1 .. 4; +is($x, undef); + +# Test aliases +$x = last_result { $_ > 5 } 4 .. 9; +is($x, 1); +$x = last_result { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastres => sub { + $x = lastres { $_ > 5 } 4 .. 9; + } +); +is_dying('lastres without sub' => sub { &lastres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/lastval.t liblist-moreutils-perl-0.430/t/xs/lastval.t --- liblist-moreutils-perl-0.416/t/xs/lastval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/lastval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,39 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *last_value = __PACKAGE__->can("lastval"); +} + +use Test::More; +use Test::LMU; + +my $x = lastval { $_ > 5 } 4 .. 9; +is($x, 9); +$x = lastval { $_ > 5 } 1 .. 4; +is($x, undef); +is_undef(lastval { $_ > 5 }); + +# Test aliases +$x = last_value { $_ > 5 } 4 .. 9; +is($x, 9); +$x = last_value { $_ > 5 } 1 .. 4; +is($x, undef); + +leak_free_ok( + lastval => sub { + $x = lastval { $_ > 5 } 4 .. 9; + } +); +is_dying('lastval without sub' => sub { &lastval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/listcmp.t liblist-moreutils-perl-0.430/t/xs/listcmp.t --- liblist-moreutils-perl-0.416/t/xs/listcmp.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/listcmp.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,127 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen); + my @b = qw(two three five seven eleven thirteen seventeen); + my @c = qw(one one two three five eight thirteen twentyone); + + my %expected = ( + one => [0, 2], + two => [0, 1, 2], + three => [0, 1, 2], + four => [0], + five => [0, 1, 2], + six => [0], + seven => [0, 1], + eight => [0, 2], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1, 2], + seventeen => [1], + twentyone => [2], + ); + + my %cmped = listcmp @a, @b, @c; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime vs. Fibonacci sorted out correctly"); +} + +SCOPE: +{ + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + is_deeply(\%cmped, \%expected, "Sequence vs. Prime filled with undef sorted out correctly"); +} + +leak_free_ok( + listcmp => sub { + my @a = ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen"); + my @b = (undef, "two", "three", undef, "five", undef, "seven", undef, undef, undef, "eleven", undef, "thirteen"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + four => [0], + five => [0, 1], + six => [0], + seven => [0, 1], + eight => [0], + nine => [0], + ten => [0], + eleven => [0, 1], + twelve => [0], + thirteen => [0, 1], + ); + + my %cmped = listcmp @a, @b; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'listcmp with exception in overloading stringify at begin' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = (DieOnStringify->new, "two", "three"); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + }, + 'listcmp with exception in overloading stringify at end' => sub { + eval { + my @a = ("one", "two", "three"); + my @b = ("two", "three", DieOnStringify->new); + + my %expected = ( + one => [0], + two => [0, 1], + three => [0, 1], + ); + + my %cmped = listcmp @a, @b; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/lower_bound.t liblist-moreutils-perl-0.430/t/xs/lower_bound.t --- liblist-moreutils-perl-0.416/t/xs/lower_bound.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/lower_bound.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,65 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (lower_bound { $_ <=> 0 } @list), "lower bound 0"); +is(0, (lower_bound { $_ <=> 1 } @list), "lower bound 1"); +is(2, (lower_bound { $_ <=> 2 } @list), "lower bound 2"); +is(10, (lower_bound { $_ <=> 4 } @list), "lower bound 4"); +is(scalar @list, (lower_bound { $_ <=> 19 } @list), "lower bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i ? $i - 1 : 0, (lower_bound { $_ - $j } @list), "placed $j"); + is($i, (lower_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (lower_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (lower_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + lower_bound => sub { + my $elem = int(rand(1000)) + 1; + lower_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + lower_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'lower_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + lower_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('lower_bound without sub' => sub { &lower_bound(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/mesh.t liblist-moreutils-perl-0.430/t/xs/mesh.t --- liblist-moreutils-perl-0.416/t/xs/mesh.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/mesh.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,79 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *zip = __PACKAGE__->can("mesh"); +} + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "mesh two list with same count of elements"); +} + +SCOPE: +{ + # alias check + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip @x, @y; + is_deeply(\@z, ['a', 1, 'b', 2, 'c', 3, 'd', 4], "zip two list with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = mesh @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "mesh three list with increasing count of elements"); +} + +SCOPE: +{ + # alias check + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip @a, @b, @c; + is_deeply(\@z, ['x', 1, 'zip', undef, 2, 'zap', undef, undef, 'zot'], "zip three list with increasing count of elements"); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = mesh @a, @d; + is_deeply( + \@z, + [1, undef, 2, undef, 3, undef, 4, undef, 5, undef, 6, undef, 7, undef, 8, undef, 9, undef, 10, undef,], + "mesh one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + mesh => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = mesh @x, @y; + } +); +is_dying('mesh with a list, not at least two arrays' => sub { &mesh(1, 2); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/minmaxstr.t liblist-moreutils-perl-0.430/t/xs/minmaxstr.t --- liblist-moreutils-perl-0.416/t/xs/minmaxstr.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/minmaxstr.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,53 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +use Test::More; +use Test::LMU; + +use POSIX qw(setlocale LC_COLLATE); +setlocale(LC_COLLATE, "C"); + +my @list = reverse 'AA' .. 'ZZ'; +my ($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ'); + +# Odd number of elements +push @list, 'ZZ Top'; +($min, $max) = minmaxstr @list; +is($min, 'AA'); +is($max, 'ZZ Top'); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmaxstr(sprintf("%s", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmaxstr swallows max on COW"); + +# Test with a single list value +my $input = 'foo'; +($min, $max) = minmaxstr $input; +is($min, 'foo'); +is($max, 'foo'); + +# Confirm output are independant copies of input +$input = 'bar'; +is($min, 'foo'); +is($max, 'foo'); +$min = 'bar'; +is($max, 'foo'); + +leak_free_ok( + minmaxstr => sub { + @list = reverse 'AA' .. 'ZZ', 'ZZ Top'; + ($min, $max) = minmaxstr @list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/minmax.t liblist-moreutils-perl-0.430/t/xs/minmax.t --- liblist-moreutils-perl-0.416/t/xs/minmax.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/minmax.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,89 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = reverse 0 .. 10000; +my ($min, $max) = minmax @list; +is($min, 0); +is($max, 10000); + +# Even number of elements +push @list, 10001; +($min, $max) = minmax @list; +is($min, 0); +is($max, 10001); +$list[0] = 17; + +# Some floats +@list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); +($min, $max) = minmax @list; + +# Floating-point comparison cunningly avoided +is(sprintf("%.2f", $min), "-3.33"); +is($max, 10000); + +# Test with a single negative list value +my $input = -1; +($min, $max) = minmax $input; +is($min, -1); +is($max, -1); + +# COW causes missing max when optimization for 1 argument is applied +@list = grep { defined $_ } map { my ($min, $max) = minmax(sprintf("%.3g", rand)); ($min, $max) } (0 .. 19); +is(scalar @list, 40, "minmax swallows max on COW"); + +# Confirm output are independant copies of input +$input = 1; +is($min, -1); +is($max, -1); +$min = 2; +is($max, -1); + +# prove overrun +my $uvmax = ~0; +my $ivmax = $uvmax >> 1; +my $ivmin = (0 - $ivmax) - 1; +my @low_ints = map { $ivmin + $_ } (0 .. 10); +($min, $max) = minmax @low_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmin + 10, "minmax finds ivmin + 10"); + +my @high_ints = map { $ivmax - $_ } (0 .. 10); +($min, $max) = minmax @high_ints; +is($min, $ivmax - 10, "minmax finds ivmax-10"); +is($max, $ivmax, "minmax finds ivmax"); + +my @mixed_ints = map { ($ivmin + $_, $ivmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_ints; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $ivmax, "minmax finds ivmax"); + +my @high_uints = map { $uvmax - $_ } (0 .. 10); +($min, $max) = minmax @high_uints; +is($min, $uvmax - 10, "minmax finds uvmax-10"); +is($max, $uvmax, "minmax finds uvmax"); + +my @mixed_nums = map { ($ivmin + $_, $uvmax - $_) } (0 .. 10); +($min, $max) = minmax @mixed_nums; +is($min, $ivmin, "minmax finds ivmin"); +is($max, $uvmax, "minmax finds uvmax"); + +leak_free_ok( + minmax => sub { + @list = (0, -1.1, 3.14, 1 / 7, 10000, -10 / 3); + ($min, $max) = minmax @list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/mode.t liblist-moreutils-perl-0.430/t/xs/mode.t --- liblist-moreutils-perl-0.416/t/xs/mode.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/mode.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,452 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + my $fl = freeze(\@lorem); + + my $n_comma = scalar(split /,/, $lorem) - 1; + + my @m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_ARRAY lorem untouched"); + is_deeply([$n_comma, ','], \@m, "lorem mode as list"); + my $m = mode @lorem; + is($fl, freeze(\@lorem), "mode:G_SCALAR lorem untouched"); + is($n_comma, $m, "lorem mode as scalar"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "mode:G_ARRAY probes untouched"); + is_deeply([7, 4], \@m, "unimodal result in list context"); + my $m = mode @probes; + is($fp, freeze(\@probes), "mode:G_SCALAR probes untouched"); + is(7, $m, "unimodal result in scalar context"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $fp = freeze(\@probes); + my @m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_ARRAY probes untouched"); + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([7, 4, 8], \@m, "bimodal result in list context"); + $m = mode @probes; + is($fp, freeze(\@probes), "bimodal mode:G_SCALAR probes untouched"); + is(7, $m, "bimodal result in scalar context"); +} + +SCOPE: +{ + my %radio_ukw_nrw = ( + "87,6" => "WDR Eins Live", + "87,7" => "WDR 5", + "87,7" => "Welle Niederrhein", + "87,7" => "WDR 5", + "87,8" => "Welle West", + "87,8" => "WDR 4", + "87,8" => "WDR 2 Dortmund", + "87,9" => "Radio HERTZ", + "88,0" => "WDR 5", + "88,1" => "Radio Hochstift", + "88,2" => "Radio Kiepenkerl", + "88,2" => "Radio Siegen", + "88,3" => "WDR 5", + "88,3" => "Radio MK", + "88,4" => "WDR 2 Köln", + "88,4" => "Radio WMW", + "88,4" => "WDR 5", + "88,5" => "WDR 5", + "88,5" => "Werrepark Radio", + "88,5" => "WDR 5", + "88,6" => "WDR 5", + "88,7" => "WDR 3", + "88,8" => "WDR 5", + "88,9" => "Deutschlandradio Kultur", + "89,0" => "Lokalradio Olpe", + "89,1" => "Deutschlandfunk (DLF)", + "89,1" => "Radio Sauerland", + "89,2" => "WDR (Test)", + "89,3" => "Antenne Unna", + "89,4" => "NE-WS 89,4", + "89,4" => "L`UniCo FM", + "89,6" => "WDR 5", + "89,7" => "WDR 3", + "90,0" => "CT das radio", + "90,0" => "WDR 5", + "90,1" => "WDR 4", + "90,1" => "Deutschlandradio Kultur", + "90,1" => "Radio 90,1", + "90,3" => "WDR 5", + "90,6" => "WDR 5", + "90,7" => "WDR 4", + "90,8" => "Radio Herne", + "90,8" => "Radio MK", + "90,9" => "Radio Q", + "91,0" => "Deutschlandradio Kultur", + "91,0" => "Deutschlandfunk (DLF)", + "91,2" => "WDR (Test)", + "91,2" => "Radio 91,2", + "91,2" => "Radio Bonn/Rhein-Sieg", + "91,3" => "Radio Lippe (geplant)", + "91,3" => "Deutschlandfunk (DLF)", + "91,3" => "BFBS Radio 1", + "91,4" => "Radio Erft", + "91,5" => "Radio MK", + "91,5" => "Deutschlandfunk (DLF)", + "91,5" => "Radio Ennepe Ruhr", + "91,7" => "WDR 4", + "91,7" => "BFBS Radio 2", + "91,7" => "WDR 3", + "91,7" => "Radio K.W.", + "91,7" => "Radio Herford", + "91,8" => "WDR 2 Wuppertal", + "91,8" => "WDR 2 Bielefeld", + "91,9" => "WDR 4", + "92,0" => "WDR 5", + "92,0" => "domradio", + "92,1" => "Radius 92,1", + "92,2" => "Radio Duisburg", + "92,2" => "Deutschlandfunk (DLF)", + "92,2" => "Radio RSG", + "92,3" => "WDR 2 Siegen", + "92,5" => "BFBS Radio 1", + "92,5" => "Radio MK", + "92,6" => "Radio WAF", + "92,7" => "WDR 3", + "92,7" => "Radio Rur", + "92,7" => "Radio Ennepe Ruhr", + "92,9" => "Radio Mülheim", + "93,0" => "Radio WMW", + "93,0" => "elDOradio", + "93,1" => "WDR 3", + "93,2" => "WDR 2 Bielefeld", + "93,3" => "WDR 2 Rhein-Ruhr", + "93,5" => "WDR 2 Siegen", + "93,6" => "WDR Eins Live", + "93,7" => "Radio Hochstift", + "93,8" => "WDR 2 Siegen", + "93,9" => "WDR 4", + "93,9" => "Deutschlandfunk (DLF)", + "93,9" => "WDR 5", + "94,1" => "WDR 2 Münster", + "94,2" => "Radio Bonn/Rhein-Sieg", + "94,2" => "WDR 2 Aachen", + "94,2" => "Deutschlandfunk (DLF)", + "94,3" => "Antenne Bethel", + "94,3" => "Radio RSG", + "94,3" => "WDR 3", + "94,5" => "Deutschlandfunk (DLF)", + "94,6" => "Radio MK", + "94,6" => "Test FM", + "94,6" => "Deutschlandradio Kultur", + "94,6" => "Radio Vest", + "94,7" => "Radio FH", + "94,7" => "Radio WAF", + "94,8" => "WDR (Test)", + "94,8" => "Radio Sauerland", + "94,9" => "Radio Herford", + "95,1" => "WDR 3", + "95,1" => "Radio Westfalica", + "95,2" => "WDR 3", + "95,4" => "Antenne Münster", + "95,5" => "Deutschlandfunk (DLF)", + "95,6" => "Radio Vest", + "95,7" => "Radio WAF", + "95,7" => "Radio Westfalica", + "95,7" => "WDR 2 Wuppertal", + "95,8" => "WDR 5", + "95,9" => "WDR 3", + "95,9" => "Triquency", + "95,9" => "Radio Gütersloh", + "96,0" => "WDR Eins Live", + "96,0" => "WDR 2 Münster", + "96,0" => "WDR 2 Bielefeld", + "96,1" => "Radio Emscher Lippe", + "96,1" => "WDR 4", + "96,1" => "Triquency", + "96,2" => "Radio Sauerland", + "96,3" => "WDR 3", + "96,3" => "Radio WAF", + "96,3" => "Deutschlandradio Kultur", + "96,4" => "Radio Siegen (geplant)", + "96,4" => "WDR 2 Bielefeld", + "96,5" => "Deutschlandradio Kultur", + "96,8" => "bonn FM", + "96,9" => "Deutschlandradio Kultur", + "96,9" => "Radio Berg", + "97,0" => "WDR 3", + "97,1" => "Antenne GL", + "97,1" => "Hochschulradio Düsseldorf", + "97,1" => "WDR 2 Siegen", + "97,2" => "107.8 Antenne AC", + "97,2" => "Radio MK", + "97,3" => "Radio Siegen", + "97,3" => "WDR 3", + "97,3" => "WDR 3", + "97,4" => "Antenne Unna", + "97,5" => "WDR 3", + "97,5" => "Deutschlandradio Kultur", + "97,6" => "Radio WMW", + "97,6" => "WDR (Test)", + "97,6" => "Radio Bielefeld", + "97,6" => "Radio Neandertal", + "97,6" => "WDR 5", + "97,7" => "Deutschlandradio Kultur", + "97,8" => "Radio Bonn/Rhein-Sieg", + "97,8" => "WDR 3", + "98,0" => "Antenne Niederrhein", + "98,1" => "WDR 3", + "98,2" => "WDR 3", + "98,2" => "WDR Eins Live", + "98,3" => "Radio Bielefeld", + "98,4" => "WDR 3", + "98,5" => "Radio Bochum", + "98,6" => "WDR 2 + Messeradio Köln", + "98,6" => "WDR 5", + "98,7" => "Radio Emscher Lippe", + "98,9" => "Deutschlandradio Kultur", + "98,9" => "Lokalradio Olpe", + "98,9" => "Radio Siegen", + "99,1" => "Hochschulradio Aachen", + "99,1" => "WDR 2 Bielefeld", + "99,2" => "WDR 2 Rhein-Ruhr", + "99,4" => "WDR 2 Siegen", + "99,4" => "Triquency", + "99,5" => "WDR 4", + "99,5" => "Radio MK", + "99,6" => "WDR 4", + "99,7" => "Radio Euskirchen", + "99,7" => "WDR 5", + "99,7" => "Radio Berg", + "99,7" => "WDR Eins Live", + "99,8" => "WDR 2 Wuppertal", + "99,9" => "Radio Bonn/Rhein-Sieg", + "100,0" => "Kölncampus", + "100,0" => "WDR 4", + "100,1" => "107.8 Antenne AC", + "100,1" => "WDR Eins Live", + "100,2" => "Radio MK", + "100,2" => "Deutschlandradio Kultur", + "100,4" => "WDR 2 Köln", + "100,5" => "WDR 4", + "100,6" => "Welle Niederrhein", + "100,7" => "WDR 4", + "100,8" => "WDR 2 Aachen", + "100,9" => "Hellweg Radio", + "101,0" => "WDR 2 Aachen", + "101,0" => "Radio Lippe", + "101,1" => "WDR 4", + "101,1" => "Deutschlandradio Kultur", + "101,2" => "WDR 4", + "101,3" => "WDR 4", + "101,6" => "BFBS Radio 2", + "101,7" => "WDR 4", + "101,7" => "domradio", + "101,8" => "WDR 2 Siegen", + "101,9" => "WDR 5", + "101,9" => "BFBS Radio 1", + "102,1" => "NE-WS 89,4", + "102,1" => "WDR 2 Siegen", + "102,2" => "Radio Essen", + "102,2" => "BFBS Radio 2", + "102,3" => "Antenne Unna", + "102,4" => "WDR Eins Live", + "102,5" => "WDR Eins Live", + "102,7" => "Deutschlandfunk (DLF)", + "102,7" => "Deutschlandfunk (DLF)", + "102,8" => "Deutschlandfunk (DLF)", + "103,0" => "BFBS Radio 1", + "103,3" => "Funkhaus Europa", + "103,6" => "Radio WMW", + "103,6" => "Hellweg Radio", + "103,7" => "WDR Eins Live", + "103,8" => "WDR 4", + "103,9" => "Radio Q", + "104,0" => "BFBS Radio 1", + "104,0" => "Radio RST", + "104,1" => "WDR 4", + "104,2" => "Radio Bonn/Rhein-Sieg", + "104,2" => "Antenne Düsseldorf", + "104,2" => "Radio Ennepe Ruhr", + "104,3" => "BFBS Radio 2", + "104,4" => "WDR 4", + "104,4" => "Deutschlandfunk (DLF)", + "104,5" => "CampusFM", + "104,5" => "Deutschlandfunk (DLF)", + "104,5" => "WDR 4", + "104,7" => "WDR Eins Live", + "104,8" => "Radio Hochstift", + "104,8" => "Radio Hochstift", + "104,9" => "Radio Sauerland", + "105,0" => "Radio Essen", + "105,0" => "Radio Lippe Welle Hamm", + "105,0" => "107.8 Antenne AC", + "105,0" => "BFBS Radio 2", + "105,1" => "BFBS Radio 1", + "105,2" => "Radio Vest", + "105,2" => "Radio Berg", + "105,2" => "Radio RST", + "105,4" => "Radio Siegen", + "105,5" => "WDR Eins Live", + "105,5" => "WDR Eins Live", + "105,6" => "CampusFM", + "105,7" => "Antenne Niederrhein", + "105,7" => "Radio Ennepe Ruhr", + "105,7" => "WDR Eins Live", + "105,7" => "Radio Berg", + "105,8" => "Radio Erft", + "106,0" => "BFBS Radio 1", + "106,1" => "Deutschlandradio Kultur", + "106,1" => "Deutschlandradio Kultur", + "106,2" => "Deutschlandradio Kultur", + "106,2" => "106.2 Radio Oberhausen", + "106,3" => "Radio Kiepenkerl", + "106,4" => "WDR Eins Live", + "106,5" => "Radio Sauerland", + "106,5" => "Radio Sauerland", + "106,5" => "Radio St. Laurentius", + "106,6" => "Radio Lippe", + "106,6" => "Radio Westfalica", + "106,6" => "Deutschlandfunk (DLF)", + "106,7" => "WDR Eins Live", + "106,8" => "Radio Gütersloh", + "106,9" => "Radio Euskirchen", + "107,0" => "WDR Eins Live", + "107,1" => "Radio Köln", + "107,2" => "WDR Eins Live", + "107,2" => "Deutschlandfunk (DLF)", + "107,3" => "WDR Eins Live", + "107,3" => "Hellweg Radio", + "107,4" => "Radio Euskirchen", + "107,4" => "Radio Kiepenkerl", + "107,4" => "Radio Lippe", + "107,4" => "Radio Wuppertal", + "107,5" => "Radio Rur", + "107,5" => "Radio Gütersloh", + "107,5" => "WDR Eins Live", + "107,6" => "Radio Leverkusen", + "107,6" => "Radio Sauerland", + "107,6" => "Radio K.W.", + "107,7" => "WDR Eins Live", + "107,7" => "Hellweg Radio", + "107,7" => "107.7 Radio Hagen", + "107,8" => "107.8 Antenne AC", + "107,8" => "Lokalradio Olpe", + "107,9" => "Radio Bonn/Rhein-Sieg", + "107,9" => "WDR Eins Live", + "107,9" => "Radio RSG", + ); + + my @m = mode values %radio_ukw_nrw; + my $m = shift @m; + @m = sort @m; + unshift @m, $m; + is_deeply([14, 'WDR 5', 'WDR Eins Live'], \@m, "multimodal result in list context"); + $m = mode values %radio_ukw_nrw; + is(14, $m, "multimodal result in scalar context"); +} + +leak_free_ok( + 'mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @m = mode @probes; + }, + 'scalar mode (unimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $m = mode @probes; + }, + 'mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my @m = mode @probes; + }, + 'scalar mode (bimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7); + my $m = mode @probes; + }, + 'mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my @m = mode @probes; + }, + 'scalar mode (multimodal)' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7, (9) x 4, (10) x 3, (11) x 7); + my $m = mode @probes; + }, +); + +leak_free_ok( + 'mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @m = mode @probes; + }; + }, + 'scalar mode (unimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $m = mode @probes; + }; + }, + 'mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my @m = mode @probes; + }; + }, + 'scalar mode (bimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = + ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, (7) x 3, $obj, (8) x 7); + my $m = mode @probes; + }; + }, + 'mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my @m = mode @probes; + }; + }, + 'scalar mode (multimodal) with exception in overloading stringify' => sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ( + (1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4, $obj, + (7) x 3, $obj, (8) x 7, $obj, (9) x 4, $obj, (10) x 3, $obj, (11) x 7 + ); + my $m = mode @probes; + }; + }, +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/natatime.t liblist-moreutils-perl-0.430/t/xs/natatime.t --- liblist-moreutils-perl-0.416/t/xs/natatime.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/natatime.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,46 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @x = ('a' .. 'g'); +my $it = natatime 3, @x; +my @r; +local $" = " "; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "natatime with 3 elements"); + +my @a = (1 .. 1000); +$it = natatime 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "natatime with 1 element"); + +leak_free_ok( + natatime => sub { + my @y = 1; + my $it = natatime 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/none.t liblist-moreutils-perl-0.430/t/xs/none.t --- liblist-moreutils-perl-0.416/t/xs/none.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/none.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none { not defined } @list); +is_true(none { $_ > 10000 } @list); +is_false(none { defined } @list); +is_true(none {}); + +leak_free_ok( + none => sub { + my $ok = none { $_ == 5000 } @list; + my $ok2 = none { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none without sub' => sub { &none(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/none_u.t liblist-moreutils-perl-0.430/t/xs/none_u.t --- liblist-moreutils-perl-0.416/t/xs/none_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/none_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(none_u { not defined } @list); +is_true(none_u { $_ > 10000 } @list); +is_false(none_u { defined } @list); +is_undef(none_u {}); + +leak_free_ok( + none_u => sub { + my $ok = none_u { $_ == 5000 } @list; + my $ok2 = none_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('none_u without sub' => sub { &none_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/notall.t liblist-moreutils-perl-0.430/t/xs/notall.t --- liblist-moreutils-perl-0.416/t/xs/notall.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/notall.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall { !defined } @list); +is_true(notall { $_ < 10000 } @list); +is_false(notall { $_ <= 10000 } @list); +is_false(notall {}); + +leak_free_ok( + notall => sub { + my $ok = notall { $_ == 5000 } @list; + my $ok2 = notall { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall without sub' => sub { ¬all(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/notall_u.t liblist-moreutils-perl-0.430/t/xs/notall_u.t --- liblist-moreutils-perl-0.416/t/xs/notall_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/notall_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,31 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 10000); +is_true(notall_u { !defined } @list); +is_true(notall_u { $_ < 10000 } @list); +is_false(notall_u { $_ <= 10000 } @list); +is_undef(notall_u {}); + +leak_free_ok( + notall_u => sub { + my $ok = notall_u { $_ == 5000 } @list; + my $ok2 = notall_u { $_ == 5000 } 1 .. 10000; + } +); +is_dying('notall_u without sub' => sub { ¬all_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/occurrences.t liblist-moreutils-perl-0.430/t/xs/occurrences.t --- liblist-moreutils-perl-0.416/t/xs/occurrences.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/occurrences.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,92 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my $lorem = + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + my @lorem = grep { $_ } split /(?:\b|\s)/, $lorem; + + my $n_comma = scalar(split /,/, $lorem) - 1; + my $n_dot = scalar(split /\./, $lorem); # there is one at end ... mind the gap + my $n_et = scalar(split /\bet\b/, $lorem) - 1; + + my @l = @lorem; + my @o = occurrences @l; + + is(undef, $o[0], "Each word is counted"); + is(undef, $o[1], "Text to long, each word is there at least twice"); + is_deeply([','], $o[$n_comma], "$n_comma comma"); + is_deeply(['.'], $o[$n_dot], "$n_dot dots"); + is_deeply(['et'], $o[$n_et], "$n_et words 'et'"); + + @o = occurrences grep { /\w+/ } @lorem; + my $wc = reduce_0 { defined $b ? $a + $_ * scalar @$b : $a } @o; + is($wc, 124, "Words are as many as requested at www.loremipsum.de"); +} + +SCOPE: +{ + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { ref $_ ? [sort @$_] : $_ } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +SCOPE: +{ + my @probes = ((1) x 3, undef, (2) x 4, undef, (3) x 2, undef, (4) x 7, undef, (5) x 2, undef, (6) x 4); + my $fp = freeze(\@probes); + my @o = map { + ref $_ + ? [sort { (defined $a <=> defined $b) or $a <=> $b } @$_] + : $_ + } occurrences @probes; + is($fp, freeze(\@probes), "probes untouched"); + my @expectation = (undef, undef, [3, 5], [1], [2, 6], [undef], undef, [4]); + is_deeply(\@expectation, \@o, "occurrences of integer probes"); +} + +leak_free_ok( + occurrences => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my @o = occurrences @probes; + }, + 'scalar occurrences' => sub { + my @probes = ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4); + my $o = occurrences @probes; + } +); + +leak_free_ok( + 'occurrences with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my @o = occurrences @probes; + }; + eval { + my $obj = DieOnStringify->new; + my @probes = ((1) x 3, $obj, (2) x 4, $obj, (3) x 2, $obj, (4) x 7, $obj, (5) x 2, $obj, (6) x 4); + my $o = occurrences @probes; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/one.t liblist-moreutils-perl-0.430/t/xs/one.t --- liblist-moreutils-perl-0.416/t/xs/one.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/one.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,34 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one { 1 == $_ } @list); +is_true(one { 150 == $_ } @list); +is_true(one { 300 == $_ } @list); +is_false(one { 0 == $_ } @list); +is_false(one { 1 <= $_ } @list); +is_false(one { !(127 & $_) } @list); +is_false(one { 0 } ()); + +leak_free_ok( + one => sub { + my $ok = one { 150 <= $_ } @list; + my $ok2 = one { 150 <= $_ } 1 .. 300; + } +); +is_dying('one without sub' => sub { &one(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/one_u.t liblist-moreutils-perl-0.430/t/xs/one_u.t --- liblist-moreutils-perl-0.416/t/xs/one_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/one_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,34 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# Normal cases +my @list = (1 .. 300); +is_true(one_u { 1 == $_ } @list); +is_true(one_u { 150 == $_ } @list); +is_true(one_u { 300 == $_ } @list); +is_false(one_u { 0 == $_ } @list); +is_false(one_u { 1 <= $_ } @list); +is_false(one_u { !(127 & $_) } @list); +is_undef(one_u {}); + +leak_free_ok( + one_u => sub { + my $ok = one_u { 150 <= $_ } @list; + my $ok2 = one_u { 150 <= $_ } 1 .. 300; + } +); +is_dying('one_u without sub' => sub { &one_u(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/onlyidx.t liblist-moreutils-perl-0.430/t/xs/onlyidx.t --- liblist-moreutils-perl-0.416/t/xs/onlyidx.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/onlyidx.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,44 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_index = __PACKAGE__->can("onlyidx"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(0, onlyidx { 1 == $_ } @list); +is(149, onlyidx { 150 == $_ } @list); +is(299, onlyidx { 300 == $_ } @list); +is(-1, onlyidx { 0 == $_ } @list); +is(-1, onlyidx { 1 <= $_ } @list); +is(-1, onlyidx { !(127 & $_) } @list); + +# Test aliases +is(0, only_index { 1 == $_ } @list); +is(149, only_index { 150 == $_ } @list); +is(299, only_index { 300 == $_ } @list); +is(-1, only_index { 0 == $_ } @list); +is(-1, only_index { 1 <= $_ } @list); +is(-1, only_index { !(127 & $_) } @list); + +leak_free_ok( + onlyidx => sub { + my $ok = onlyidx { 150 <= $_ } @list; + my $ok2 = onlyidx { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyidx without sub' => sub { &onlyidx(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/onlyres.t liblist-moreutils-perl-0.430/t/xs/onlyres.t --- liblist-moreutils-perl-0.416/t/xs/onlyres.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/onlyres.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,42 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_result = __PACKAGE__->can("onlyres"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is("Hallelujah", onlyres { 150 == $_ and "Hallelujah" } @list); +is(1, onlyres { 300 == $_ } @list); +is(undef, onlyres { 0 == $_ } @list); +is(undef, onlyres { 1 <= $_ } @list); +is(undef, onlyres { !(127 & $_) } @list); + +# Test aliases +is(1, only_result { 150 == $_ } @list); +is("Hallelujah", only_result { 300 == $_ and "Hallelujah" } @list); +is(undef, only_result { 0 == $_ } @list); +is(undef, only_result { 1 <= $_ } @list); +is(undef, only_result { !(127 & $_) } @list); + +leak_free_ok( + onlyres => sub { + my $ok = onlyres { 150 <= $_ } @list; + my $ok2 = onlyres { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyres without sub' => sub { &onlyres(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/onlyval.t liblist-moreutils-perl-0.430/t/xs/onlyval.t --- liblist-moreutils-perl-0.416/t/xs/onlyval.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/onlyval.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,44 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *only_value = __PACKAGE__->can("onlyval"); +} + +use Test::More; +use Test::LMU; + +my @list = (1 .. 300); +is(1, onlyval { 1 == $_ } @list); +is(150, onlyval { 150 == $_ } @list); +is(300, onlyval { 300 == $_ } @list); +is(undef, onlyval { 0 == $_ } @list); +is(undef, onlyval { 1 <= $_ } @list); +is(undef, onlyval { !(127 & $_) } @list); + +# Test aliases +is(1, only_value { 1 == $_ } @list); +is(150, only_value { 150 == $_ } @list); +is(300, only_value { 300 == $_ } @list); +is(undef, only_value { 0 == $_ } @list); +is(undef, only_value { 1 <= $_ } @list); +is(undef, only_value { !(127 & $_) } @list); + +leak_free_ok( + onlyval => sub { + my $ok = onlyval { 150 <= $_ } @list; + my $ok2 = onlyval { 150 <= $_ } 1 .. 300; + } +); +is_dying('onlyval without sub' => sub { &onlyval(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/pairwise.t liblist-moreutils-perl-0.430/t/xs/pairwise.t --- liblist-moreutils-perl-0.416/t/xs/pairwise.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/pairwise.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,129 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @a = (1, 2, 3, 4, 5); +my @b = (2, 4, 6, 8, 10); +my @c = pairwise { $a + $b } @a, @b; +is_deeply(\@c, [3, 6, 9, 12, 15], "pw1"); + +@c = pairwise { $a * $b } @a, @b; # returns (2, 8, 18) +is_deeply(\@c, [2, 8, 18, 32, 50], "pw2"); + +# Did we modify the input arrays? +is_deeply(\@a, [1, 2, 3, 4, 5], "pw3"); +is_deeply(\@b, [2, 4, 6, 8, 10], "pw4"); + +# $a and $b should be aliases: test +@b = @a = (1, 2, 3); +@c = pairwise { $a++; $b *= 2 } @a, @b; +is_deeply(\@a, [2, 3, 4], "pw5"); +is_deeply(\@b, [2, 4, 6], "pw6"); +is_deeply(\@c, [2, 4, 6], "pw7"); + +# sub returns more than two items +@a = (1, 1, 2, 3, 5); +@b = (2, 3, 5, 7, 11, 13); +@c = pairwise { ($a) x $b } @a, @b; +is_deeply(\@c, [(1) x 2, (1) x 3, (2) x 5, (3) x 7, (5) x 11, (undef) x 13], "pw8"); +is_deeply(\@a, [1, 1, 2, 3, 5], "pw9"); +is_deeply(\@b, [2, 3, 5, 7, 11, 13], "pwX"); + +(@a, @b) = (); +push @a, int rand(1000) for 0 .. rand(1000); +push @b, int rand(1000) for 0 .. rand(1000); +SCOPE: +{ + local $SIG{__WARN__} = sub { }; # XXX + my @res1 = pairwise { $a + $b } @a, @b; + # Test this one more thoroughly: the XS code looks flakey + # correctness of pairwise_perl proved by human auditing. :-) + my $limit = $#a > $#b ? $#a : $#b; + my @res2 = map { $a[$_] + $b[$_] } 0 .. $limit; + is_deeply(\@res1, \@res2); +} + +@a = qw/a b c/; +@b = qw/1 2 3/; +@c = pairwise { ($a, $b) } @a, @b; +is_deeply(\@c, [qw/a 1 b 2 c 3/], "pw map"); + +SKIP: +{ + $ENV{PERL5OPT} and skip 'A defined PERL5OPT may inject extra deps crashing this test', 1; + # Test that a die inside the code-reference will not be trapped + eval { + pairwise { die "I died\n" } @a, @b; + }; + is($@, "I died\n"); +} + +leak_free_ok( + pairwise => sub { + @a = (1); + @b = (2); + @c = pairwise { $a + $b } @a, @b; + } +); + +leak_free_ok( + 'exceptional block' => sub { + @a = qw/a b c/; + @b = qw/1 2 3/; + eval { + @c = pairwise { $b == 3 and die "Primes suck!"; "$a:$b" } @a, @b; + }; + } +); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will warn here ...", 1; + my ($a, $b, @t); + eval { + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + }; + my $err = $@; + like($err, qr/Can't use lexical \$a or \$b in pairwise code block/, "pairwise die's on broken caller"); +} + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "XS will die on purpose here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, @_ }; + my ($a, $b, @t); + my @l1 = (1 .. 10); + @t = pairwise { $a + $b } @l1, @l1; + like(join("", @warns[0, 1]), qr/Use of uninitialized value.*? in addition/, "warning on broken caller"); +} + +is_dying('pairwise without sub' => sub { &pairwise(42, \@a, \@b); }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not core here ...", 2; + is_dying( + 'pairwise without first ARRAY' => sub { + @c = &pairwise(sub { }, 1, \@b); + } + ); + is_dying( + 'pairwise without second ARRAY' => sub { + @c = &pairwise(sub { }, \@a, 2); + } + ); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/part.t liblist-moreutils-perl-0.430/t/xs/part.t --- liblist-moreutils-perl-0.416/t/xs/part.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/part.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,90 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = 1 .. 12; +my $i = 0; +my @part = part { $i++ % 3 } @list; +is_deeply($part[0], [1, 4, 7, 10], " i: part % 3"); +is_deeply($part[1], [2, 5, 8, 11], " ii: part % 3"); +is_deeply($part[2], [3, 6, 9, 12], "iii: part % 3"); + +$list[2] = 0; +is($part[2][0], 3, 'Values are not aliases'); + +@list = 1 .. 12; +@part = part { 3 } @list; +is($part[0], undef, " i: part 3"); +is($part[1], undef, " ii: part 3"); +is($part[2], undef, "iii: part 3"); +is_deeply($part[3], [1 .. 12], " iv: part 3"); + +eval { + @part = part { -1 } @list; +}; +like($@, qr/^Modification of non-creatable array value attempted, subscript -1/); + +$i = 0; +@part = part { $i++ == 0 ? 0 : -1 } @list; +is_deeply($part[0], [1 .. 12], "part with negative indices"); + +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} and skip "Only PurePerl will warn here ...", 1; + my @warns = (); + local $SIG{__WARN__} = sub { push @warns, [@_] }; + @part = part { undef } @list; + is_deeply($part[0], [1 .. 12], "part with undef"); + like(join("\n", @{$warns[0]}), qr/Use of uninitialized value in array element.*line\s+\d+\.$/, "warning of undef"); + is_deeply(\@warns, [($warns[0]) x 12], "amount of similar undef warnings"); +} + +@part = part { 10000 } @list; +is_deeply($part[10000], [@list], " i: part 10_000"); +is($part[0], undef, " ii: part 10_000"); +is($part[@part / 2], undef, "iii: part 10_000"); +is($part[9999], undef, " iv: part 10_000"); + +# Changing the list in place used to destroy +# its elements due to a wrong refcnt +@list = 1 .. 10; +@list = part { $_ } @list; +foreach (1 .. 10) +{ + is_deeply($list[$_], [$_], "part \$_: $_"); +} + +leak_free_ok( + part => sub { + my @list = 1 .. 12; + my $i = 0; + my @part = part { $i++ % 3 } @list; + } +); + +leak_free_ok( + 'part with stack-growing' => sub { + # This test is from Kevin Ryde; see RT#38699 + my @part = part { grow_stack(); 1024 } 'one', 'two'; + } +); + +leak_free_ok( + 'part with exception' => sub { + my @long_list = int rand(1000) for 0 .. 1E7; + my @part = part { $_ == 1E7 and die "Too much!"; ($_ % 10) * 2 } @long_list; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/qsort.t liblist-moreutils-perl-0.430/t/xs/qsort.t --- liblist-moreutils-perl-0.416/t/xs/qsort.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/qsort.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,30 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +plan skip_all => "It's insane to use a pure-perl qsort" unless $INC{'List/MoreUtils/XS.pm'}; + +my @ltn_asc = qw(2 3 5 7 11 13 17 19 23 29 31 37); +my @ltn_des = reverse @ltn_asc; +my @l; + +@l = @ltn_des; +qsort sub { $a <=> $b }, @l; +is_deeply(\@l, \@ltn_asc, "sorted ascending"); + +@l = @ltn_asc; +qsort sub { $b <=> $a }, @l; +is_deeply(\@l, \@ltn_des, "sorted descending"); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/reduce_0.t liblist-moreutils-perl-0.430/t/xs/reduce_0.t --- liblist-moreutils-perl-0.416/t/xs/reduce_0.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/reduce_0.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,49 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_0' => sub { + my @exam_results = (2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_0 { $a + ($_ + 1) * $b / $pupil } @exam_results; + }, + 'reduce_0 X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_0 { $a + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_0 with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_0 { die } 1; + }; + } +); +is_dying('reduce_0 without sub' => sub { &reduce_0(42, 4711); }); + +done_testing + + + diff -Nru liblist-moreutils-perl-0.416/t/xs/reduce_1.t liblist-moreutils-perl-0.430/t/xs/reduce_1.t --- liblist-moreutils-perl-0.416/t/xs/reduce_1.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/reduce_1.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,42 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +use Scalar::Util qw(looks_like_number); + +# (this code shamelessly stolen from Math::Complex's t/Trig.t, with some mods to near) from BBYRD in RT#72638 and taken from SQL-Statement now +use Math::Trig; +my $eps = 1e-11; + +if ($^O eq 'unicos') +{ # See lib/Math/Complex.pm and t/lib/complex.t. + $eps = 1e-10; +} + +sub near ($$$;$) +{ + my $d = $_[1] ? abs($_[0] / $_[1] - 1) : abs($_[0]); + local $Test::Builder::Level = $Test::Builder::Level + 1; + looks_like_number($_[0]) or return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/nan/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + $_[0] =~ m/inf/i and return cmp_ok($_[0], "eq", $_[1], "near? $_[0] ~= $_[1]"); + my $e = defined $_[3] ? $_[3] : $eps; + cmp_ok($d, '<', $e, "$_[2] => near? $_[0] ~= $_[1]") or diag("near? $_[0] ~= $_[1]"); +} + +my $half_pi = reduce_1 { $a * ((4 * $b * $b) / ((2 * $b - 1) * (2 * $b + 1))) } 1 .. 750; + +near($half_pi, pi / 2, "Wallis product", 1e-2); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/reduce_u.t liblist-moreutils-perl-0.430/t/xs/reduce_u.t --- liblist-moreutils-perl-0.416/t/xs/reduce_u.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/reduce_u.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,48 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +use List::Util qw(sum); + +SCOPE: +{ + my @exam_results = (0, 2, 4, 6, 5, 3, 0); + my $pupil = sum @exam_results; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + $wa = sprintf("%0.2f", $wa); + is($wa, 3.15, "weighted average of exam"); +} + +leak_free_ok( + 'reduce_u' => sub { + my @exam_results = (undef, 2, 4, 6, 5, 3, 0); + my $pupil = 20; + my $wa = reduce_u { defined $a ? $a + $_ * $b / $pupil : 0 } @exam_results; + }, + 'reduce_u X' => sub { + my @w = map { int(rand(5)) + 1; } 1 .. 100; + my $c1 = reduce_u { ($a || 0) + $w[$_] * $b } 1 .. 100; + } +); +leak_free_ok( + 'reduce_u with a coderef that dies' => sub { + # This test is from Kevin Ryde; see RT#48669 + eval { + my $ok = reduce_u { die } 1; + }; + } +); +is_dying('reduce_u without sub' => sub { &reduce_u(42, 4711); }); + +done_testing + + diff -Nru liblist-moreutils-perl-0.416/t/xs/samples.t liblist-moreutils-perl-0.430/t/xs/samples.t --- liblist-moreutils-perl-0.416/t/xs/samples.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/samples.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,50 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @l = (1 .. 100); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 integer probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = (1 .. 10); + my @s = samples 10, @l; + is(scalar @s, 10, "samples delivers 10 out of 10 when used as shuffle"); + my @u = uniq grep { defined $_ } @s; + is(scalar @u, 10, "samples doesn't add any integer twice"); +} + +SCOPE: +{ + my @l = ('AA' .. 'ZZ'); + my @s = samples 10, @l; + is(scalar @s, 10, "samples stops correctly after 10 strings probes"); + my @u = uniq @s; + is(scalar @u, 10, "samples doesn't add any string twice"); +} + +is_dying('to much samples' => sub { my @l = (1 .. 3); samples 5, @l }); +SKIP: +{ + $INC{'List/MoreUtils/XS.pm'} or skip "PurePerl will not fail here ...", 1; + is_dying('samples without list' => sub { samples 5 }); +} + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/singleton.t liblist-moreutils-perl-0.430/t/xs/singleton.t --- liblist-moreutils-perl-0.416/t/xs/singleton.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/singleton.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,108 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @s = (1001 .. 1200); + my @d = map { (1 .. 1000) } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(200, $u); +} + +# Test strings +SCOPE: +{ + my @s = ("AA" .. "ZZ"); + my @d = map { ("aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + is_deeply(\@u, [@s]); + my $u = singleton @a; + is(scalar @s, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my $fs = freeze(\@s); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my $fa = freeze(\@a); + my @u = singleton map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [@s]); + is($fs, freeze(\@s)); + is($fa, freeze(\@a)); + is($fu, $fs); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + @a = (@d, @s); + my @u = singleton map { $_ } @a; + is_deeply(\@u, [@s]); + @a = (@d, @s); + my $u = singleton @a; + is(scalar @s, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @sfoo = ('a', undef, 'c'); + is_deeply([singleton @foo], \@sfoo, 'one undef is supported correctly by singleton'); + @foo = ('a', 'b', '', undef, 'b', 'c', undef); + @sfoo = ('a', '', 'c'); + is_deeply([singleton @foo], \@sfoo, 'twice undef is supported correctly by singleton'); + is((scalar singleton @foo), scalar @sfoo, 'scalar twice undef is supported correctly by singleton'); +} + +leak_free_ok( + singleton => sub { + my @s = (1001 .. 1200, "AA" .. "ZZ"); + my @d = map { (1 .. 1000, "aa" .. "zz") } 0 .. 1; + my @a = (@d, @s); + my @u = singleton @a; + scalar singleton @a; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'singleton with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = singleton $obj, $obj; + }; + eval { + my $obj = DieOnStringify->new; + my $u = singleton $obj, $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/slideatatime.t liblist-moreutils-perl-0.430/t/xs/slideatatime.t --- liblist-moreutils-perl-0.416/t/xs/slideatatime.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/slideatatime.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,75 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +local $" = " "; +my $it; +my @r; + +my @x = ('a' .. 'g'); +$it = slideatatime 3, 3, @x; +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'd e f', 'g']), 1, "slideatatime as natatime with 3 elements"); + +$it = slideatatime 2, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'c d e', 'e f g', 'g']), 1, "slideatatime moving 3 elements by 2 items"); + +$it = slideatatime 1, 3, @x; +@r = (); +while (my @vals = $it->()) +{ + push @r, "@vals"; +} +is(is_deeply(\@r, ['a b c', 'b c d', 'c d e', 'd e f', 'e f g', 'f g', 'g']), 1, "slideatatime moving 3 elements by 1 item"); + +my @a = (1 .. 1000); +$it = slideatatime 1, 1, @a; +@r = (); +while (my @vals = &$it) +{ + push @r, @vals; +} +is(is_deeply(\@r, \@a), 1, "slideatatime as natatime with 1 element"); + +leak_free_ok( + slideatatime => sub { + my @y = 1; + my $it = slideatatime 2, 2, @y; + while (my @vals = $it->()) + { + # do nothing + } + }, + 'slideatatime with exception' => sub { + my @r; + eval { + my $it = slideatatime 1, 3, @x; + while (my @vals = $it->()) + { + scalar @vals == 3 or die; + push @r, "@vals"; + } + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/slide.t liblist-moreutils-perl-0.430/t/xs/slide.t --- liblist-moreutils-perl-0.416/t/xs/slide.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/slide.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,22 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# use case provided my Michael Schwern +my @ol = (0 .. 3); +is(join(", ", slide { "$a and $b" } @ol), "0 and 1, 1 and 2, 2 and 3", "M. Schwern requested example"); + +is_dying('slide without sub' => sub { &slide(0 .. 3); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/true.t liblist-moreutils-perl-0.430/t/xs/true.t --- liblist-moreutils-perl-0.416/t/xs/true.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/true.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,36 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +# The null set should return zero +my $null_scalar = true {}; +my @null_list = true {}; +is($null_scalar, 0, 'true(null) returns undef'); +is_deeply(\@null_list, [0], 'true(null) returns undef'); + +# Normal cases +my @list = (1 .. 10000); +is(10000, true { defined } @list); +is(0, true { not defined } @list); +is(1, true { $_ == 5000 } @list); + +leak_free_ok( + true => sub { + my $n = true { $_ == 5000 } @list; + my $n2 = true { $_ == 5000 } 1 .. 10000; + } +); +is_dying('true without sub' => sub { &true(42, 4711); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/uniq.t liblist-moreutils-perl-0.430/t/xs/uniq.t --- liblist-moreutils-perl-0.416/t/xs/uniq.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/uniq.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,102 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + +BEGIN +{ + $INC{'List/MoreUtils.pm'} or *distinct = __PACKAGE__->can("uniq"); +} + +use Test::More; +use Test::LMU; +use Tie::Array (); + +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, [1 .. 10]); + my $u = uniq @a; + is(10, $u); +} + +# Test aliases +SCOPE: +{ + my @a = map { (1 .. 10) } 0 .. 1; + my @u = distinct @a; + is_deeply(\@u, [1 .. 10]); + my $u = distinct @a; + is(10, $u); +} + +# Test strings +SCOPE: +{ + my @a = map { ("a" .. "z") } 0 .. 1; + my @u = uniq @a; + is_deeply(\@u, ["a" .. "z"]); + my $u = uniq @a; + is(26, $u); +} + +# Test mixing strings and numbers +SCOPE: +{ + my @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $fa = freeze(\@a); + my @u = uniq map { $_ } @a; + my $fu = freeze(\@u); + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + is($fa, freeze(\@a)); + is($fu, freeze([1 .. 10, "a" .. "z"])); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @a; + tie @a, "Tie::StdArray"; + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my @u = uniq @a; + is_deeply(\@u, [1 .. 10, "a" .. "z"]); + @a = ((map { (1 .. 10) } 0 .. 1), (map { ("a" .. "z") } 0 .. 1)); + my $u = uniq @a; + is(10 + 26, $u); +} + +SCOPE: +{ + my @foo = ('a', 'b', '', undef, 'b', 'c', ''); + my @ufoo = ('a', 'b', '', undef, 'c'); + is_deeply([uniq @foo], \@ufoo, 'undef is supported correctly'); +} + +leak_free_ok( + uniq => sub { + my @a = map { (1 .. 1000) } 0 .. 1; + my @u = uniq @a; + uniq @a[1 .. 100]; + } +); + +# This test (and the associated fix) are from Kevin Ryde; see RT#49796 +leak_free_ok( + 'uniq with exception in overloading stringify', + sub { + eval { + my $obj = DieOnStringify->new; + my @u = uniq "foo", $obj, "bar", $obj; + }; + } +); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/upper_bound.t liblist-moreutils-perl-0.430/t/xs/upper_bound.t --- liblist-moreutils-perl-0.416/t/xs/upper_bound.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/upper_bound.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,65 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +my @list = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17); +is(0, (upper_bound { $_ <=> 0 } @list), "upper bound 0"); +is(2, (upper_bound { $_ <=> 1 } @list), "upper bound 1"); +is(4, (upper_bound { $_ <=> 2 } @list), "upper bound 2"); +is(14, (upper_bound { $_ <=> 4 } @list), "upper bound 4"); +is(scalar @list, (upper_bound { $_ <=> 19 } @list), "upper bound 19"); + +my @in = @list = 1 .. 100; +for my $i (0 .. $#in) +{ + my $j = $in[$i] - 1; + is($i, (upper_bound { $_ - $j } @list), "placed $j"); + is($i + 1, (upper_bound { $_ - $in[$i] } @list), "found $in[$i]"); +} +my @lout = ($in[0] - 11 .. $in[0] - 1); +for my $elem (@lout) +{ + is(0, (upper_bound { $_ - $elem } @list), "put smaller $elem in front"); +} +my @uout = ($in[-1] + 1 .. $in[-1] + 11); +for my $elem (@uout) +{ + is(scalar @list, (upper_bound { $_ - $elem } @list),, "put bigger $elem at end"); +} + +leak_free_ok( + upper_bound => sub { + my $elem = int(rand(1000)) + 1; + upper_bound { $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing' => sub { + my $elem = int(rand(1000)); + upper_bound { grow_stack(); $_ - $elem } @list; + } +); + +leak_free_ok( + 'upper_bound with stack-growing and exception' => sub { + my $elem = int(rand(1000)); + eval { + upper_bound { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list; + }; + } +); +is_dying('upper_bound without sub' => sub { &upper_bound(42, (1 .. 100)); }); + +done_testing; + + diff -Nru liblist-moreutils-perl-0.416/t/xs/XS.t liblist-moreutils-perl-0.430/t/xs/XS.t --- liblist-moreutils-perl-0.416/t/xs/XS.t 2016-07-06 14:21:34.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/XS.t 2020-10-21 14:47:09.000000000 +0000 @@ -1,10 +1,48 @@ #!perl -use lib ("t/lib"); -$ENV{LIST_MOREUTILS_PP} = 0; +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +$INC{'List/MoreUtils.pm'} or plan skip_all => "Unreasonable unless loaded via List::MoreUtils"; + +is(List::MoreUtils::_XScompiled(), 0 + defined($INC{'List/MoreUtils/XS.pm'}), "_XScompiled"); + +done_testing(); + +1; + +=head1 AUTHOR + +Jens Rehsack Erehsack AT cpan.orgE + +Adam Kennedy Eadamk@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2013 - 2017 by Jens Rehsack + +All code added with 0.417 or later is licensed under the Apache License, +Version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +All code until 0.416 is licensed under the same terms as Perl itself, +either Perl version 5.8.4 or, at your option, any later version of +Perl 5 you may have available. -require LMU::Test::XS; +=cut -LMU::Test::XS->run_tests; diff -Nru liblist-moreutils-perl-0.416/t/xs/zip6.t liblist-moreutils-perl-0.430/t/xs/zip6.t --- liblist-moreutils-perl-0.416/t/xs/zip6.t 1970-01-01 00:00:00.000000000 +0000 +++ liblist-moreutils-perl-0.430/t/xs/zip6.t 2020-10-21 14:47:09.000000000 +0000 @@ -0,0 +1,60 @@ +#!perl + +use strict ("subs", "vars", "refs"); +use warnings ("all"); +BEGIN { $ENV{LIST_MOREUTILS_PP} = 0; } +END { delete $ENV{LIST_MOREUTILS_PP} } # for VMS +use List::MoreUtils (":all"); +use lib ("t/lib"); + + +use Test::More; +use Test::LMU; + +SCOPE: +{ + my @x = qw/a b c d/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + is_deeply(\@z, [['a', 1], ['b', 2], ['c', 3], ['d', 4]], "zip6 two lists with same count of elements"); +} + +SCOPE: +{ + my @a = ('x'); + my @b = ('1', '2'); + my @c = qw/zip zap zot/; + my @z = zip6 @a, @b, @c; + is_deeply( + \@z, + [['x', 1, 'zip'], [undef, 2, 'zap'], [undef, undef, 'zot']], + "zip6 three list with increasing count of elements" + ); +} + +# Make array with holes +SCOPE: +{ + my @a = (1 .. 10); + my @d; + $#d = 9; + my @z = zip6 @a, @d; + is_deeply( + \@z, + [[1, undef], [2, undef], [3, undef], [4, undef], [5, undef], [6, undef], [7, undef], [8, undef], [9, undef], [10, undef]], + "zip6 one list with 9 elements with an empty list" + ); +} + +leak_free_ok( + zip6 => sub { + my @x = qw/a b c d e/; + my @y = qw/1 2 3 4/; + my @z = zip6 @x, @y; + } +); +is_dying('zip6 with a list, not at least two arrays' => sub { &zip6(1, 2); }); + +done_testing; + +