List-MoreUtils-XS-0.430/0000755000175000017500000000000013743757362013105 5ustar snosnoList-MoreUtils-XS-0.430/lib/0000755000175000017500000000000013743757362013653 5ustar snosnoList-MoreUtils-XS-0.430/lib/List/0000755000175000017500000000000013743757362014566 5ustar snosnoList-MoreUtils-XS-0.430/lib/List/MoreUtils/0000755000175000017500000000000013743757362016511 5ustar snosnoList-MoreUtils-XS-0.430/lib/List/MoreUtils/XS.pm0000644000175000017500000000653713743756020017402 0ustar snosnopackage List::MoreUtils::XS; use 5.008_001; use strict; use warnings; use base ('Exporter'); use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS}; $VERSION = '0.430'; @EXPORT = (); @EXPORT_OK = qw(any all none notall one any_u all_u none_u notall_u one_u reduce_u reduce_0 reduce_1 true false insert_after insert_after_string apply indexes slide after after_incl before before_incl firstidx lastidx onlyidx firstval lastval onlyval firstres lastres onlyres singleton duplicates frequency occurrences mode each_array each_arrayref pairwise natatime slideatatime arrayify mesh zip6 uniq listcmp samples minmax minmaxstr part bsearch bsearchidx binsert bremove lower_bound upper_bound equal_range qsort); %EXPORT_TAGS = (all => \@EXPORT_OK); # 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::XS", "$VERSION"); =pod =head1 NAME List::MoreUtils::XS - Provide compiled List::MoreUtils functions =head1 SYNOPSIS use List::MoreUtils::XS (); # doesn't export anything use List::MoreUtils ':all'; # required to import functions my @procs = get_process_stats->fetchall_array; # sort by ppid, then pid qsort { $a->[3] <=> $b->[3] or $a->[2] <=> $b->[2] } @procs; while( @procs ) { my $proc = shift @procs; my @children = equal_range { $_->[3] <=> $proc->[2] } @procs; } my @left = qw(this is a test); my @right = qw(this is also a test); my %rlinfo = listcmp @left, @right; # on unsorted my $i = firstidx { $_ eq 'yeah' } @foo; # on sorted - always first, but might not be 'yeah' my $j = lower_bound { $_ cmp 'yeah' } @bar; # on sorted - any of occurrences, is surely 'yeah' my $k = bsearchidx { $_ cmp 'yeah' } @bar; =head1 DESCRIPTION List::MoreUtils::XS is a backend for List::MoreUtils. Even if it's possible (because of user wishes) to have it practically independent from L, it technically depend on C. Since it's only a backend, the API is not public and can change without any warning. =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 - 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 1; List-MoreUtils-XS-0.430/META.yml0000664000175000017500000000177413743757362014371 0ustar snosno--- abstract: 'Provide the stuff missing in List::Util in XS' author: - 'Tassilo von Parseval ' - 'Adam Kennedy ' - 'Jens Rehsack ' build_requires: Storable: '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.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' name: List-MoreUtils-XS no_index: directory: - t - inc requires: XSLoader: '0.22' resources: bugtracker: https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils-XS homepage: https://metacpan.org/release/List-MoreUtils-XS repository: https://github.com/perl5-utils/List-MoreUtils-XS.git version: '0.430' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' List-MoreUtils-XS-0.430/MANIFEST0000644000175000017500000000520113743757362014234 0ustar snosno.perltidyrc ARTISTIC-1.0 Changes GPL-1 inc/Config/AutoConf/LMU.pm inc/inc_Capture-Tiny/Capture/Tiny.pm inc/inc_Config-AutoConf/Config/AutoConf.pm inc/latest.pm inc/latest/private.pm lib/List/MoreUtils/XS.pm LICENSE MAINTAINER.md Makefile.PL MANIFEST This list of files MANIFEST.SKIP multicall.h ppport.h README.md 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/LICENSE 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 XS.xs META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) List-MoreUtils-XS-0.430/MAINTAINER.md0000644000175000017500000000337313735527357015064 0ustar snosno# Maintainers Guide for List::MoreUtils::XS List::MoreUtils and List::MoreUtils::XS have common submodules to share eg. tests. That's why it is a bit more complicated to setup a clone for hacking on the beast. # Get what you need At first one need to clone the project and all it's submodules: $ git clone --recurse-submodules https://github.com/perl5-utils/List-MoreUtils-XS.git # Prepare environment for configure stage Then some (typically bundled) modules are required for Makefile.PL itself: $ cpanm --with-recommends --with-suggests Test::WriteVariants Config::AutoConf Carp inc::latest JSON::PP # Start working The typical workflow for authoring modules with ExtUtils::MakeMaker... $ cpanm --with-recommends --with-suggests --with-develop --installdeps . $ perl Makefile.PL $ make manifest $ make test # Submitting contributions When submitting patches or proposals or ideas or whatever - you realize and agree the copyright and license conditions. Do not submit anything when you don't agree on that. # Copyright and License 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. List-MoreUtils-XS-0.430/inc/0000755000175000017500000000000013743757362013656 5ustar snosnoList-MoreUtils-XS-0.430/inc/Config/0000755000175000017500000000000013743757362015063 5ustar snosnoList-MoreUtils-XS-0.430/inc/Config/AutoConf/0000755000175000017500000000000013743757362016601 5ustar snosnoList-MoreUtils-XS-0.430/inc/Config/AutoConf/LMU.pm0000644000175000017500000000543613735527761017603 0ustar snosnopackage inc::Config::AutoConf::LMU; use strict; use warnings; use Config::AutoConf '0.315'; use base qw(Config::AutoConf); sub _have_feature_define_name { my $feature = $_[0]; my $have_name = "HAVE_FEATURE_" . uc($feature); $have_name =~ tr/ /_/; $have_name =~ tr/_A-Za-z0-9/_/c; $have_name; } sub check_statement_expression { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $header) = @_; $self = $self->_get_instance(); my $feature = "statement expression"; my $cache_name = $self->_cache_name(qw(feature statement expression)); my $check_sub = sub { my $prologue = defined $options->{prologue} ? $options->{prologue} : ""; my $decl = "#define STMT_EXPR ({ 1; })"; my $have_stmt_expr = $self->compile_if_else( $self->lang_build_bool_test($prologue, "STMT_EXPR", $decl), { ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); $have_stmt_expr; }; # Run the check and cache the results. return $self->check_cached( $cache_name, "for $feature feature", $check_sub, { action_on_true => sub { $self->define_var( _have_feature_define_name($feature), $self->cache_val($cache_name), "Defined when feature $feature 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_feature_define_name($feature), undef, "Defined when feature $feature is available"); $options->{action_on_cache_false} and ref $options->{action_on_cache_false} eq "CODE" and $options->{action_on_cache_false}->(); }, } ); } sub check_lmu_prerequisites { my $self = shift->_get_instance(); $self->check_produce_loadable_xs_build() or die "Can't produce loadable XS module"; $self->check_default_headers(); $self->check_all_headers(qw(time.h sys/time.h)); $self->check_funcs([qw(time)]); unless ($self->check_types([qw(size_t ssize_t)])) { $self->check_sizeof_types( ["int", "long", "long long", "ptr"], { prologue => $self->_default_includes . <check_builtin("expect"); $self->check_statement_expression(); } 1; List-MoreUtils-XS-0.430/inc/latest.pm0000644000175000017500000000023613743756025015504 0ustar snosno# This stub created by inc::latest 0.500 package inc::latest; use strict; use vars '@ISA'; require inc::latest::private; @ISA = qw/inc::latest::private/; 1; List-MoreUtils-XS-0.430/inc/inc_Capture-Tiny/0000755000175000017500000000000013743757362017033 5ustar snosnoList-MoreUtils-XS-0.430/inc/inc_Capture-Tiny/Capture/0000755000175000017500000000000013743757362020436 5ustar snosnoList-MoreUtils-XS-0.430/inc/inc_Capture-Tiny/Capture/Tiny.pm0000644000175000017500000007173013743756025021722 0ustar snosnouse 5.006; use strict; use warnings; package Capture::Tiny; # ABSTRACT: Capture STDOUT and STDERR from Perl, XS or external programs our $VERSION = '0.48'; use Carp (); use Exporter (); use IO::Handle (); use File::Spec (); use File::Temp qw/tempfile tmpnam/; use Scalar::Util qw/reftype blessed/; # Get PerlIO or fake it BEGIN { local $@; eval { require PerlIO; PerlIO->can('get_layers') } or *PerlIO::get_layers = sub { return () }; } #--------------------------------------------------------------------------# # create API subroutines and export them # [do STDOUT flag, do STDERR flag, do merge flag, do tee flag] #--------------------------------------------------------------------------# my %api = ( capture => [1,1,0,0], capture_stdout => [1,0,0,0], capture_stderr => [0,1,0,0], capture_merged => [1,1,1,0], tee => [1,1,0,1], tee_stdout => [1,0,0,1], tee_stderr => [0,1,0,1], tee_merged => [1,1,1,1], ); for my $sub ( keys %api ) { my $args = join q{, }, @{$api{$sub}}; eval "sub $sub(&;@) {unshift \@_, $args; goto \\&_capture_tee;}"; ## no critic } our @ISA = qw/Exporter/; our @EXPORT_OK = keys %api; our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); #--------------------------------------------------------------------------# # constants and fixtures #--------------------------------------------------------------------------# my $IS_WIN32 = $^O eq 'MSWin32'; ##our $DEBUG = $ENV{PERL_CAPTURE_TINY_DEBUG}; ## ##my $DEBUGFH; ##open $DEBUGFH, "> DEBUG" if $DEBUG; ## ##*_debug = $DEBUG ? sub(@) { print {$DEBUGFH} @_ } : sub(){0}; our $TIMEOUT = 30; #--------------------------------------------------------------------------# # command to tee output -- the argument is a filename that must # be opened to signal that the process is ready to receive input. # This is annoying, but seems to be the best that can be done # as a simple, portable IPC technique #--------------------------------------------------------------------------# my @cmd = ($^X, '-C0', '-e', <<'HERE'); use Fcntl; $SIG{HUP}=sub{exit}; if ( my $fn=shift ) { sysopen(my $fh, qq{$fn}, O_WRONLY|O_CREAT|O_EXCL) or die $!; print {$fh} $$; close $fh; } my $buf; while (sysread(STDIN, $buf, 2048)) { syswrite(STDOUT, $buf); syswrite(STDERR, $buf); } HERE #--------------------------------------------------------------------------# # filehandle manipulation #--------------------------------------------------------------------------# sub _relayer { my ($fh, $apply_layers) = @_; # _debug("# requested layers (@{$layers}) for @{[fileno $fh]}\n"); # eliminate pseudo-layers binmode( $fh, ":raw" ); # strip off real layers until only :unix is left while ( 1 < ( my $layers =()= PerlIO::get_layers( $fh, output => 1 ) ) ) { binmode( $fh, ":pop" ); } # apply other 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)); } sub _name { my $glob = shift; no strict 'refs'; ## no critic return *{$glob}{NAME}; } sub _open { open $_[0], $_[1] or Carp::confess "Error from open(" . join(q{, }, @_) . "): $!"; # _debug( "# open " . join( ", " , map { defined $_ ? _name($_) : 'undef' } @_ ) . " as " . fileno( $_[0] ) . "\n" ); } sub _close { # _debug( "# closing " . ( defined $_[0] ? _name($_[0]) : 'undef' ) . " on " . fileno( $_[0] ) . "\n" ); close $_[0] or Carp::confess "Error from close(" . join(q{, }, @_) . "): $!"; } my %dup; # cache this so STDIN stays fd0 my %proxy_count; sub _proxy_std { my %proxies; if ( ! defined fileno STDIN ) { $proxy_count{stdin}++; if (defined $dup{stdin}) { _open \*STDIN, "<&=" . fileno($dup{stdin}); # _debug( "# restored proxy STDIN as " . (defined fileno STDIN ? fileno STDIN : 'undef' ) . "\n" ); } else { _open \*STDIN, "<" . File::Spec->devnull; # _debug( "# proxied STDIN as " . (defined fileno STDIN ? fileno STDIN : 'undef' ) . "\n" ); _open $dup{stdin} = IO::Handle->new, "<&=STDIN"; } $proxies{stdin} = \*STDIN; binmode(STDIN, ':utf8') if $] >= 5.008; ## no critic } if ( ! defined fileno STDOUT ) { $proxy_count{stdout}++; if (defined $dup{stdout}) { _open \*STDOUT, ">&=" . fileno($dup{stdout}); # _debug( "# restored proxy STDOUT as " . (defined fileno STDOUT ? fileno STDOUT : 'undef' ) . "\n" ); } else { _open \*STDOUT, ">" . File::Spec->devnull; # _debug( "# proxied STDOUT as " . (defined fileno STDOUT ? fileno STDOUT : 'undef' ) . "\n" ); _open $dup{stdout} = IO::Handle->new, ">&=STDOUT"; } $proxies{stdout} = \*STDOUT; binmode(STDOUT, ':utf8') if $] >= 5.008; ## no critic } if ( ! defined fileno STDERR ) { $proxy_count{stderr}++; if (defined $dup{stderr}) { _open \*STDERR, ">&=" . fileno($dup{stderr}); # _debug( "# restored proxy STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" ); } else { _open \*STDERR, ">" . File::Spec->devnull; # _debug( "# proxied STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" ); _open $dup{stderr} = IO::Handle->new, ">&=STDERR"; } $proxies{stderr} = \*STDERR; binmode(STDERR, ':utf8') if $] >= 5.008; ## no critic } return %proxies; } sub _unproxy { my (%proxies) = @_; # _debug( "# unproxying: " . join(" ", keys %proxies) . "\n" ); for my $p ( keys %proxies ) { $proxy_count{$p}--; # _debug( "# unproxied " . uc($p) . " ($proxy_count{$p} left)\n" ); if ( ! $proxy_count{$p} ) { _close $proxies{$p}; _close $dup{$p} unless $] < 5.008; # 5.6 will have already closed this as dup delete $dup{$p}; } } } sub _copy_std { my %handles; for my $h ( qw/stdout stderr stdin/ ) { next if $h eq 'stdin' && ! $IS_WIN32; # WIN32 hangs on tee without STDIN copied my $redir = $h eq 'stdin' ? "<&" : ">&"; _open $handles{$h} = IO::Handle->new(), $redir . uc($h); # ">&STDOUT" or "<&STDIN" } return \%handles; } # In some cases we open all (prior to forking) and in others we only open # the output handles (setting up redirection) sub _open_std { my ($handles) = @_; _open \*STDIN, "<&" . fileno $handles->{stdin} if defined $handles->{stdin}; _open \*STDOUT, ">&" . fileno $handles->{stdout} if defined $handles->{stdout}; _open \*STDERR, ">&" . fileno $handles->{stderr} if defined $handles->{stderr}; } #--------------------------------------------------------------------------# # private subs #--------------------------------------------------------------------------# sub _start_tee { my ($which, $stash) = @_; # $which is "stdout" or "stderr" # setup pipes $stash->{$_}{$which} = IO::Handle->new for qw/tee reader/; pipe $stash->{reader}{$which}, $stash->{tee}{$which}; # _debug( "# pipe for $which\: " . _name($stash->{tee}{$which}) . " " . fileno( $stash->{tee}{$which} ) . " => " . _name($stash->{reader}{$which}) . " " . fileno( $stash->{reader}{$which}) . "\n" ); select((select($stash->{tee}{$which}), $|=1)[0]); # autoflush # setup desired redirection for parent and child $stash->{new}{$which} = $stash->{tee}{$which}; $stash->{child}{$which} = { stdin => $stash->{reader}{$which}, stdout => $stash->{old}{$which}, stderr => $stash->{capture}{$which}, }; # flag file is used to signal the child is ready $stash->{flag_files}{$which} = scalar( tmpnam() ) . $$; # execute @cmd as a separate process if ( $IS_WIN32 ) { my $old_eval_err=$@; undef $@; eval "use Win32API::File qw/GetOsFHandle SetHandleInformation fileLastError HANDLE_FLAG_INHERIT INVALID_HANDLE_VALUE/ "; # _debug( "# Win32API::File loaded\n") unless $@; my $os_fhandle = GetOsFHandle( $stash->{tee}{$which} ); # _debug( "# Couldn't get OS handle: " . fileLastError() . "\n") if ! defined $os_fhandle || $os_fhandle == INVALID_HANDLE_VALUE(); my $result = SetHandleInformation( $os_fhandle, HANDLE_FLAG_INHERIT(), 0); # _debug( $result ? "# set no-inherit flag on $which tee\n" : ("# can't disable tee handle flag inherit: " . fileLastError() . "\n")); _open_std( $stash->{child}{$which} ); $stash->{pid}{$which} = system(1, @cmd, $stash->{flag_files}{$which}); # not restoring std here as it all gets redirected again shortly anyway $@=$old_eval_err; } else { # use fork _fork_exec( $which, $stash ); } } sub _fork_exec { my ($which, $stash) = @_; # $which is "stdout" or "stderr" my $pid = fork; if ( not defined $pid ) { Carp::confess "Couldn't fork(): $!"; } elsif ($pid == 0) { # child # _debug( "# in child process ...\n" ); untie *STDIN; untie *STDOUT; untie *STDERR; _close $stash->{tee}{$which}; # _debug( "# redirecting handles in child ...\n" ); _open_std( $stash->{child}{$which} ); # _debug( "# calling exec on command ...\n" ); exec @cmd, $stash->{flag_files}{$which}; } $stash->{pid}{$which} = $pid } my $have_usleep = eval "use Time::HiRes 'usleep'; 1"; sub _files_exist { return 1 if @_ == grep { -f } @_; Time::HiRes::usleep(1000) if $have_usleep; return 0; } sub _wait_for_tees { my ($stash) = @_; my $start = time; my @files = values %{$stash->{flag_files}}; my $timeout = defined $ENV{PERL_CAPTURE_TINY_TIMEOUT} ? $ENV{PERL_CAPTURE_TINY_TIMEOUT} : $TIMEOUT; 1 until _files_exist(@files) || ($timeout && (time - $start > $timeout)); Carp::confess "Timed out waiting for subprocesses to start" if ! _files_exist(@files); unlink $_ for @files; } sub _kill_tees { my ($stash) = @_; if ( $IS_WIN32 ) { # _debug( "# closing handles\n"); close($_) for values %{ $stash->{tee} }; # _debug( "# waiting for subprocesses to finish\n"); my $start = time; 1 until wait == -1 || (time - $start > 30); } else { _close $_ for values %{ $stash->{tee} }; waitpid $_, 0 for values %{ $stash->{pid} }; } } sub _slurp { my ($name, $stash) = @_; my ($fh, $pos) = map { $stash->{$_}{$name} } qw/capture pos/; # _debug( "# slurping captured $name from " . fileno($fh) . " at pos $pos with layers: @{[PerlIO::get_layers($fh)]}\n"); seek( $fh, $pos, 0 ) or die "Couldn't seek on capture handle for $name\n"; my $text = do { local $/; scalar readline $fh }; return defined($text) ? $text : ""; } #--------------------------------------------------------------------------# # _capture_tee() -- generic main sub for capturing or teeing #--------------------------------------------------------------------------# sub _capture_tee { # _debug( "# starting _capture_tee with (@_)...\n" ); my ($do_stdout, $do_stderr, $do_merge, $do_tee, $code, @opts) = @_; my %do = ($do_stdout ? (stdout => 1) : (), $do_stderr ? (stderr => 1) : ()); Carp::confess("Custom capture options must be given as key/value pairs\n") unless @opts % 2 == 0; my $stash = { capture => { @opts } }; for ( keys %{$stash->{capture}} ) { my $fh = $stash->{capture}{$_}; Carp::confess "Custom handle for $_ must be seekable\n" unless ref($fh) eq 'GLOB' || (blessed($fh) && $fh->isa("IO::Seekable")); } # save existing filehandles and setup captures local *CT_ORIG_STDIN = *STDIN ; local *CT_ORIG_STDOUT = *STDOUT; local *CT_ORIG_STDERR = *STDERR; # find initial layers my %layers = ( stdin => [PerlIO::get_layers(\*STDIN) ], stdout => [PerlIO::get_layers(\*STDOUT, output => 1)], stderr => [PerlIO::get_layers(\*STDERR, output => 1)], ); # _debug( "# existing layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # get layers from underlying glob of tied filehandles if we can # (this only works for things that work like Tie::StdHandle) $layers{stdout} = [PerlIO::get_layers(tied *STDOUT)] if tied(*STDOUT) && (reftype tied *STDOUT eq 'GLOB'); $layers{stderr} = [PerlIO::get_layers(tied *STDERR)] if tied(*STDERR) && (reftype tied *STDERR eq 'GLOB'); # _debug( "# tied object corrected layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # bypass scalar filehandles and tied handles # localize scalar STDIN to get a proxy to pick up FD0, then restore later to CT_ORIG_STDIN my %localize; $localize{stdin}++, local(*STDIN) if grep { $_ eq 'scalar' } @{$layers{stdin}}; $localize{stdout}++, local(*STDOUT) if $do_stdout && grep { $_ eq 'scalar' } @{$layers{stdout}}; $localize{stderr}++, local(*STDERR) if ($do_stderr || $do_merge) && grep { $_ eq 'scalar' } @{$layers{stderr}}; $localize{stdin}++, local(*STDIN), _open( \*STDIN, "<&=0") if tied *STDIN && $] >= 5.008; $localize{stdout}++, local(*STDOUT), _open( \*STDOUT, ">&=1") if $do_stdout && tied *STDOUT && $] >= 5.008; $localize{stderr}++, local(*STDERR), _open( \*STDERR, ">&=2") if ($do_stderr || $do_merge) && tied *STDERR && $] >= 5.008; # _debug( "# localized $_\n" ) for keys %localize; # proxy any closed/localized handles so we don't use fds 0, 1 or 2 my %proxy_std = _proxy_std(); # _debug( "# proxy std: @{ [%proxy_std] }\n" ); # update layers after any proxying $layers{stdout} = [PerlIO::get_layers(\*STDOUT, output => 1)] if $proxy_std{stdout}; $layers{stderr} = [PerlIO::get_layers(\*STDERR, output => 1)] if $proxy_std{stderr}; # _debug( "# post-proxy layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # store old handles and setup handles for capture $stash->{old} = _copy_std(); $stash->{new} = { %{$stash->{old}} }; # default to originals for ( keys %do ) { $stash->{new}{$_} = ($stash->{capture}{$_} ||= File::Temp->new); seek( $stash->{capture}{$_}, 0, 2 ) or die "Could not seek on capture handle for $_\n"; $stash->{pos}{$_} = tell $stash->{capture}{$_}; # _debug("# will capture $_ on " . fileno($stash->{capture}{$_})."\n" ); _start_tee( $_ => $stash ) if $do_tee; # tees may change $stash->{new} } _wait_for_tees( $stash ) if $do_tee; # finalize redirection $stash->{new}{stderr} = $stash->{new}{stdout} if $do_merge; # _debug( "# redirecting in parent ...\n" ); _open_std( $stash->{new} ); # execute user provided code my ($exit_code, $inner_error, $outer_error, $orig_pid, @result); { $orig_pid = $$; local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN # _debug( "# finalizing layers ...\n" ); _relayer(\*STDOUT, $layers{stdout}) if $do_stdout; _relayer(\*STDERR, $layers{stderr}) if $do_stderr; # _debug( "# running code $code ...\n" ); my $old_eval_err=$@; undef $@; eval { @result = $code->(); $inner_error = $@ }; $exit_code = $?; # save this for later $outer_error = $@; # save this for later STDOUT->flush if $do_stdout; STDERR->flush if $do_stderr; $@ = $old_eval_err; } # restore prior filehandles and shut down tees # _debug( "# restoring filehandles ...\n" ); _open_std( $stash->{old} ); _close( $_ ) for values %{$stash->{old}}; # don't leak fds # shouldn't need relayering originals, but see rt.perl.org #114404 _relayer(\*STDOUT, $layers{stdout}) if $do_stdout; _relayer(\*STDERR, $layers{stderr}) if $do_stderr; _unproxy( %proxy_std ); # _debug( "# killing tee subprocesses ...\n" ) if $do_tee; _kill_tees( $stash ) if $do_tee; # return captured output, but shortcut in void context # unless we have to echo output to tied/scalar handles; my %got; if ( $orig_pid == $$ and ( defined wantarray or ($do_tee && keys %localize) ) ) { for ( keys %do ) { _relayer($stash->{capture}{$_}, $layers{$_}); $got{$_} = _slurp($_, $stash); # _debug("# slurped " . length($got{$_}) . " bytes from $_\n"); } print CT_ORIG_STDOUT $got{stdout} if $do_stdout && $do_tee && $localize{stdout}; print CT_ORIG_STDERR $got{stderr} if $do_stderr && $do_tee && $localize{stderr}; } $? = $exit_code; $@ = $inner_error if $inner_error; die $outer_error if $outer_error; # _debug( "# ending _capture_tee with (@_)...\n" ); return unless defined wantarray; my @return; push @return, $got{stdout} if $do_stdout; push @return, $got{stderr} if $do_stderr && ! $do_merge; push @return, @result; return wantarray ? @return : $return[0]; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Capture::Tiny - Capture STDOUT and STDERR from Perl, XS or external programs =head1 VERSION version 0.48 =head1 SYNOPSIS use Capture::Tiny ':all'; # capture from external command ($stdout, $stderr, $exit) = capture { system( $cmd, @args ); }; # capture from arbitrary code (Perl or external) ($stdout, $stderr, @result) = capture { # your code here }; # capture partial or merged output $stdout = capture_stdout { ... }; $stderr = capture_stderr { ... }; $merged = capture_merged { ... }; # tee output ($stdout, $stderr) = tee { # your code here }; $stdout = tee_stdout { ... }; $stderr = tee_stderr { ... }; $merged = tee_merged { ... }; =head1 DESCRIPTION Capture::Tiny provides a simple, portable way to capture almost anything sent to STDOUT or STDERR, regardless of whether it comes from Perl, from XS code or from an external program. Optionally, output can be teed so that it is captured while being passed through to the original filehandles. Yes, it even works on Windows (usually). Stop guessing which of a dozen capturing modules to use in any particular situation and just use this one. =head1 USAGE The following functions are available. None are exported by default. =head2 capture ($stdout, $stderr, @result) = capture \&code; $stdout = capture \&code; The C function takes a code reference and returns what is sent to STDOUT and STDERR as well as any return values from the code reference. In scalar context, it returns only STDOUT. If no output was received for a filehandle, it returns an empty string for that filehandle. Regardless of calling context, all output is captured -- nothing is passed to the existing filehandles. It is prototyped to take a subroutine reference as an argument. Thus, it can be called in block form: ($stdout, $stderr) = capture { # your code here ... }; Note that the coderef is evaluated in list context. If you wish to force scalar context on the return value, you must use the C keyword. ($stdout, $stderr, $count) = capture { my @list = qw/one two three/; return scalar @list; # $count will be 3 }; Also note that within the coderef, the C<@_> variable will be empty. So don't use arguments from a surrounding subroutine without copying them to an array first: sub wont_work { my ($stdout, $stderr) = capture { do_stuff( @_ ) }; # WRONG ... } sub will_work { my @args = @_; my ($stdout, $stderr) = capture { do_stuff( @args ) }; # RIGHT ... } Captures are normally done to an anonymous temporary filehandle. To capture via a named file (e.g. to externally monitor a long-running capture), provide custom filehandles as a trailing list of option pairs: my $out_fh = IO::File->new("out.txt", "w+"); my $err_fh = IO::File->new("out.txt", "w+"); capture { ... } stdout => $out_fh, stderr => $err_fh; The filehandles must be read/write and seekable. Modifying the files or filehandles during a capture operation will give unpredictable results. Existing IO layers on them may be changed by the capture. When called in void context, C saves memory and time by not reading back from the capture handles. =head2 capture_stdout ($stdout, @result) = capture_stdout \&code; $stdout = capture_stdout \&code; The C function works just like C except only STDOUT is captured. STDERR is not captured. =head2 capture_stderr ($stderr, @result) = capture_stderr \&code; $stderr = capture_stderr \&code; The C function works just like C except only STDERR is captured. STDOUT is not captured. =head2 capture_merged ($merged, @result) = capture_merged \&code; $merged = capture_merged \&code; The C function works just like C except STDOUT and STDERR are merged. (Technically, STDERR is redirected to the same capturing handle as STDOUT before executing the function.) Caution: STDOUT and STDERR output in the merged result are not guaranteed to be properly ordered due to buffering. =head2 tee ($stdout, $stderr, @result) = tee \&code; $stdout = tee \&code; The C function works just like C, except that output is captured as well as passed on to the original STDOUT and STDERR. When called in void context, C saves memory and time by not reading back from the capture handles, except when the original STDOUT OR STDERR were tied or opened to a scalar handle. =head2 tee_stdout ($stdout, @result) = tee_stdout \&code; $stdout = tee_stdout \&code; The C function works just like C except only STDOUT is teed. STDERR is not teed (output goes to STDERR as usual). =head2 tee_stderr ($stderr, @result) = tee_stderr \&code; $stderr = tee_stderr \&code; The C function works just like C except only STDERR is teed. STDOUT is not teed (output goes to STDOUT as usual). =head2 tee_merged ($merged, @result) = tee_merged \&code; $merged = tee_merged \&code; The C function works just like C except that output is captured as well as passed on to STDOUT. Caution: STDOUT and STDERR output in the merged result are not guaranteed to be properly ordered due to buffering. =head1 LIMITATIONS =head2 Portability Portability is a goal, not a guarantee. C requires fork, except on Windows where C is used instead. Not tested on any particularly esoteric platforms yet. See the L for test result by platform. =head2 PerlIO layers Capture::Tiny does its best to preserve PerlIO layers such as ':utf8' or ':crlf' when capturing (only for Perl 5.8.1+) . Layers should be applied to STDOUT or STDERR I the call to C or C. This may not work for tied filehandles (see below). =head2 Modifying filehandles before capturing Generally speaking, you should do little or no manipulation of the standard IO filehandles prior to using Capture::Tiny. In particular, closing, reopening, localizing or tying standard filehandles prior to capture may cause a variety of unexpected, undesirable and/or unreliable behaviors, as described below. Capture::Tiny does its best to compensate for these situations, but the results may not be what you desire. =head3 Closed filehandles Capture::Tiny will work even if STDIN, STDOUT or STDERR have been previously closed. However, since they will be reopened to capture or tee output, any code within the captured block that depends on finding them closed will, of course, not find them to be closed. If they started closed, Capture::Tiny will close them again when the capture block finishes. Note that this reopening will happen even for STDIN or a filehandle not being captured to ensure that the filehandle used for capture is not opened to file descriptor 0, as this causes problems on various platforms. Prior to Perl 5.12, closed STDIN combined with PERL_UNICODE=D leaks filehandles and also breaks tee() for undiagnosed reasons. So don't do that. =head3 Localized filehandles If code localizes any of Perl's standard filehandles before capturing, the capture will affect the localized filehandles and not the original ones. External system calls are not affected by localizing a filehandle in Perl and will continue to send output to the original filehandles (which will thus not be captured). =head3 Scalar filehandles If STDOUT or STDERR are reopened to scalar filehandles prior to the call to C or C, then Capture::Tiny will override the output filehandle for the duration of the C or C call and then, for C, send captured output to the output filehandle after the capture is complete. (Requires Perl 5.8) Capture::Tiny attempts to preserve the semantics of STDIN opened to a scalar reference, but note that external processes will not be able to read from such a handle. Capture::Tiny tries to ensure that external processes will read from the null device instead, but this is not guaranteed. =head3 Tied output filehandles If STDOUT or STDERR are tied prior to the call to C or C, then Capture::Tiny will attempt to override the tie for the duration of the C or C call and then send captured output to the tied filehandle after the capture is complete. (Requires Perl 5.8) Capture::Tiny may not succeed resending UTF-8 encoded data to a tied STDOUT or STDERR filehandle. Characters may appear as bytes. If the tied filehandle is based on L, then Capture::Tiny will attempt to determine appropriate layers like C<:utf8> from the underlying filehandle and do the right thing. =head3 Tied input filehandle Capture::Tiny attempts to preserve the semantics of tied STDIN, but this requires Perl 5.8 and is not entirely predictable. External processes will not be able to read from such a handle. Unless having STDIN tied is crucial, it may be safest to localize STDIN when capturing: my ($out, $err) = do { local *STDIN; capture { ... } }; =head2 Modifying filehandles during a capture Attempting to modify STDIN, STDOUT or STDERR I C or C is almost certainly going to cause problems. Don't do that. =head3 Forking inside a capture Forks aren't portable. The behavior of filehandles during a fork is even less so. If Capture::Tiny detects that a fork has occurred within a capture, it will shortcut in the child process and return empty strings for 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 is recommended. =head2 Limited support for Perl 5.6 Perl 5.6 predates PerlIO. UTF-8 data may not be captured correctly. =head1 ENVIRONMENT =head2 PERL_CAPTURE_TINY_TIMEOUT Capture::Tiny uses subprocesses internally for C. By default, Capture::Tiny will timeout with an error if such subprocesses are not ready to receive data within 30 seconds (or whatever is the value of C<$Capture::Tiny::TIMEOUT>). An alternate timeout may be specified by setting the C environment variable. Setting it to zero will disable timeouts. B, this does not timeout the code reference being captured -- this only prevents Capture::Tiny itself from hanging your process waiting for its child processes to be ready to proceed. =head1 SEE ALSO This module was inspired by L, which provides similar functionality without the ability to tee output and with more complicated code and API. L does not handle layers or most of the unusual cases described in the L section and I no longer recommend it. There are many other CPAN modules that provide some sort of output capture, albeit with various limitations that make them appropriate only in particular circumstances. I'm probably missing some. The long list is provided to show why I felt Capture::Tiny was necessary. =over 4 =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/Capture-Tiny.git =head1 AUTHOR David Golden =head1 CONTRIBUTORS =for stopwords Dagfinn Ilmari Mannsåker David E. Wheeler fecundf Graham Knop Peter Rabbitson =over 4 =item * Dagfinn Ilmari Mannsåker =item * David E. Wheeler =item * fecundf =item * Graham Knop =item * Peter Rabbitson =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2009 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut List-MoreUtils-XS-0.430/inc/inc_Config-AutoConf/0000755000175000017500000000000013743757362017430 5ustar snosnoList-MoreUtils-XS-0.430/inc/inc_Config-AutoConf/Config/0000755000175000017500000000000013743757362020635 5ustar snosnoList-MoreUtils-XS-0.430/inc/inc_Config-AutoConf/Config/AutoConf.pm0000644000175000017500000036324413743756026022721 0ustar snosnopackage Config::AutoConf; use warnings; use strict; use base 'Exporter'; our @EXPORT = ('$LIBEXT', '$EXEEXT'); use constant QUOTE => do { $^O eq "MSWin32" ? q["] : q['] }; use Config; use Carp qw/croak/; use File::Temp qw/tempfile/; use File::Basename; use File::Spec; use Text::ParseWords qw//; use Capture::Tiny qw/capture/; # in core since 5.7.3 eval "use Scalar::Util qw/looks_like_number/;"; __PACKAGE__->can("looks_like_number") or eval <<'EOP'; =begin private =head2 looks_like_number =end private =cut # 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; } 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; } EOP eval "use File::Slurper qw/read_binary/;"; __PACKAGE__->can("read_binary") or eval <<'EOP'; =begin private =head2 read_file =end private =cut sub read_binary { my $fn = shift; local $@ = ""; open( my $fh, "<", $fn ) or croak "Error opening $fn: $!"; my $fc = <$fh>; close($fh) or croak "I/O error closing $fn: $!"; return $fc; } EOP # PA-RISC1.1-thread-multi my %special_dlext = ( darwin => ".dylib", MSWin32 => ".dll", ($Config{archname} =~ m/PA-RISC/i ? ("hpux" => ".sl") : ()), ); our ($LIBEXT, $EXEEXT); defined $LIBEXT or $LIBEXT = defined $Config{so} ? "." . $Config{so} : defined $special_dlext{$^O} ? $special_dlext{$^O} : ".so"; defined $EXEEXT or $EXEEXT = ($^O eq "MSWin32") ? ".exe" : ""; =encoding UTF-8 =head1 NAME Config::AutoConf - A module to implement some of AutoConf macros in pure perl. =cut our $VERSION = '0.319'; $VERSION = eval $VERSION; =head1 ABSTRACT With this module I pretend to simulate some of the tasks AutoConf macros do. To detect a command, to detect a library, etc. =head1 SYNOPSIS use Config::AutoConf; Config::AutoConf->check_prog("agrep"); my $grep = Config::AutoConf->check_progs("agrep", "egrep", "grep"); Config::AutoConf->check_header("ncurses.h"); my $curses = Config::AutoConf->check_headers("ncurses.h","curses.h"); Config::AutoConf->check_prog_awk; Config::AutoConf->check_prog_egrep; Config::AutoConf->check_cc(); Config::AutoConf->check_lib("ncurses", "tgoto"); Config::AutoConf->check_file("/etc/passwd"); # -f && -r =head1 DESCRIPTION Config::AutoConf is intended to provide the same opportunities to Perl developers as L does for Shell developers. As Perl is the second most deployed language (mind: every Unix comes with Perl, several mini-computers have Perl and even lot's of Windows machines run Perl software - which requires deployed Perl there, too), this gives wider support than Shell based probes. The API is leaned against GNU Autoconf, but we try to make the API (especially optional arguments) more Perl'ish than m4 abilities allow to the original. =head1 CONSTRUCTOR =cut my $glob_instance; =head2 new 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. =cut sub new { my $class = shift; ref $class and $class = ref $class; my %args = @_; my %flags = map { my ($k, $v) = split("=", $_, 2); defined $v or $v = 1; ($k, $v) } split(":", $ENV{PERL5_AC_OPTS}) if ($ENV{PERL5_AC_OPTS}); my %instance = ( msg_prefix => 'configure: ', lang => "C", lang_stack => [], lang_supported => { "C" => $class->can("check_prog_cc"), }, cache => {}, defines => {}, extra_libs => [], extra_lib_dirs => [], extra_include_dirs => [], extra_preprocess_flags => [], extra_compile_flags => { "C" => [], }, extra_link_flags => [], logfile => "config.log", c_ac_flags => {%flags}, %args ); bless(\%instance, $class); } =head1 METHODS =head2 check_file This function checks if a file exists in the system and is readable by the user. Returns a boolean. You can use '-f $file && -r $file' so you don't need to use a function call. =cut sub check_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 This function checks if a set of files exist in the system and are readable by the user. Returns a boolean. =cut sub check_files { my $self = shift->_get_instance(); for (@_) { return 0 unless $self->check_file($_); } 1; } 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 { shift; join " ", map { _quote_shell_arg $_ } @_; } my @exe_exts = ($^O eq "MSWin32" ? qw(.exe .com .bat .cmd) : ("")); =head2 check_prog( $prog, \@dirlist?, \%options? ) This function checks for a program with the supplied name. In success returns the full path for the executable; An optional array reference containing a list of directories to be searched instead of $PATH is gracefully honored. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. =cut sub check_prog { my $self = shift->_get_instance(); # sanitize ac_prog 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}); for my $p (@dirlist) { for my $e (@exe_exts) { 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}->(); $is_executable and return $cmd; } } $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); return; } =head2 check_progs(progs, [dirlist]) This function takes a list of program names. Returns the full path for the first found on the system. Returns undef if none was found. An optional array reference containing a list of directories to be searched instead of $PATH is gracefully honored. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. The name of the I<$prog> to check and the found full path are passed as first and second argument to the I callback. =cut sub check_progs { 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}); my @progs = @_; foreach my $prog (@progs) { defined $prog or next; 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); $ans and return $ans; } $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); return; } =head2 check_prog_yacc From the L documentation, If `bison' is found, set [...] `bison -y'. Otherwise, if `byacc' is found, set [...] `byacc'. Otherwise set [...] `yacc'. The result of this test can be influenced by setting the variable YACC or the cache variable ac_cv_prog_YACC. Returns the full path, if found. =cut sub check_prog_yacc { my $self = shift->_get_instance(); # my ($self, $cache_name, $message, $check_sub) = @_; my $cache_name = $self->_cache_name("prog", "YACC"); $self->check_cached( $cache_name, "for yacc", sub { defined $ENV{YACC} and return $ENV{YACC}; 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"); return $binary; } ); } =head2 check_prog_awk 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 `gawk' first because that is reported to be the best implementation. The result can be overridden by setting the variable AWK or the cache variable ac_cv_prog_AWK. Note that it returns the full path, if found. =cut sub check_prog_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 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 setting the EGREP variable and is cached in the ac_cv_path_EGREP variable. Note that it returns the full path, if found. =cut sub check_prog_egrep { my $self = shift->_get_instance(); my $cache_name = $self->_cache_name("prog", "EGREP"); $self->check_cached( $cache_name, "for egrep", sub { defined $ENV{EGREP} and return $ENV{EGREP}; my $grep; $grep = $self->check_progs("egrep") and return $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"); } } ); } =head2 check_prog_lex 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 [...] to -ll, if found. If [...] packages [...] ship the generated file.yy.c alongside the source file.l, this [...] allows users without a lexer generator to still build the package even if the timestamp for file.l is inadvertently changed. Note that it returns the full path, if found. The structure $self->{lex} is set with attributes prog => $LEX lib => $LEXLIB root => $lex_root =cut 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/) }); if ($lex) { defined $self->{lex}->{prog} or $self->{lex}->{prog} = $lex; my $lex_root_var = $self->check_cached( "ac_cv_prog_lex_root", "for lex output file root", sub { my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.l', UNLINK => 0 ); my $src = <<'EOLEX'; %% a { ECHO; } b { REJECT; } c { yymore (); } d { yyless (1); } e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument. */ yyless ((input () != 0)); } f { unput (yytext[0]); } . { BEGIN INITIAL; } %% #ifdef YYTEXT_POINTER extern char *yytext; #endif int main (void) { return ! yylex () + ! yywrap (); } EOLEX print {$fh} $src; close $fh; my ($stdout, $stderr, $exit) = capture { system($lex, $filename); }; chomp $stdout; unlink $filename; -f "lex.yy.c" and return "lex.yy"; -f "lexyy.c" and return "lexyy"; $self->msg_error("cannot find output from $lex; giving up"); } ); defined $self->{lex}->{root} or $self->{lex}->{root} = $lex_root_var; my $conftest = read_binary($lex_root_var . ".c"); unlink $lex_root_var . ".c"; $cache_name = $self->_cache_name("lib", "lex"); my $check_sub = sub { my @save_libs = @{$self->{extra_libs}}; my $have_lib = 0; 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); $self->link_if_else($conftest) 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"); } else { $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); defined $self->{lex}->{lib} or $self->{lex}->{lib} = $lex_lib; } $lex; } =head2 check_prog_sed 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 acceptable Sed is found. See Limitations of Usual Tools, for more information about portability problems with Sed. The result of this test can be overridden by setting the SED variable and is cached in the ac_cv_path_SED variable. Note that it returns the full path, if found. =cut sub check_prog_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 Checks for C program. No additional tests are made for it ... =cut 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") }); } =head2 check_prog_cc Determine a C compiler to use. Currently the probe is delegated to L. =cut sub check_prog_cc { my $self = shift->_get_instance(); my $cache_name = $self->_cache_name("prog", "CC"); $self->check_cached( $cache_name, "for cc", sub { $self->{lang_supported}->{C} = undef; eval "use ExtUtils::CBuilder;"; $@ and return; my $cb = ExtUtils::CBuilder->new(quiet => 1); $cb->have_compiler or return; $self->{lang_supported}->{C} = "ExtUtils::CBuilder"; $cb->{config}->{cc}; } ); } =head2 check_cc (Deprecated) Old name of L. =cut sub check_cc { shift->check_prog_cc(@_) } =head2 check_valid_compiler This function checks for a valid compiler for the currently active language. At the very moment only C is understood (corresponding to your compiler default options, e.g. -std=gnu89). =cut sub check_valid_compiler { my $self = shift->_get_instance; my $lang = $self->{lang}; $lang eq "C" or $self->msg_error("Language $lang is not supported"); $self->check_prog_cc; } =head2 check_valid_compilers(;\@) Checks for valid compilers for each given language. When unspecified defaults to C<[ "C" ]>. =cut sub check_valid_compilers { my $self = shift; for my $lang (@{$_[0]}) { $self->push_lang($lang); my $supp = $self->check_valid_compiler; $self->pop_lang($lang); $supp or return 0; } 1; } =head2 msg_checking Prints "Checking @_ ..." =cut sub msg_checking { my $self = shift->_get_instance(); $self->{quiet} or print "Checking " . join(" ", @_) . "... "; $self->_add_log_entry("Checking " . join(" ", @_, "...")); return; } =head2 msg_result Prints result \n =cut my @_num_to_msg = qw/no yes/; sub _neat { defined $_[0] or return ""; looks_like_number($_[0]) and defined $_num_to_msg[$_[0]] and return $_num_to_msg[$_[0]]; $_[0]; } sub msg_result { my $self = shift->_get_instance(); $self->{quiet} or print join(" ", map { _neat $_ } @_), "\n"; $self->_add_log_entry(join(" ", map { _neat $_ } @_), "\n"); return; } =head2 msg_notice Prints "configure: " @_ to stdout =cut sub msg_notice { my $self = shift->_get_instance(); $self->{quiet} or print $self->{msg_prefix} . join(" ", @_) . "\n"; $self->_add_log_entry($self->{msg_prefix} . join(" ", @_) . "\n"); return; } =head2 msg_warn Prints "configure: " @_ to stderr =cut 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"); return; } =head2 msg_error Prints "configure: " @_ to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment) =cut 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"); exit(0); # #toolchain agreement: prevents configure stage to finish } =head2 msg_failure Prints "configure: " @_ to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment). Additional details are provides in config.log (probably more information in a later stage). =cut 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"); exit(0); # #toolchain agreement: prevents configure stage to finish } =head2 define_var( $name, $value [, $comment ] ) Defines a check variable for later use in further checks or code to compile. Returns the value assigned value =cut sub define_var { my $self = shift->_get_instance(); my ($name, $value, $comment) = @_; defined($name) or croak("Need a name to add a define"); $self->{defines}->{$name} = [$value, $comment]; $value; } =head2 write_config_h( [$target] ) Writes the defined constants into given target: Config::AutoConf->write_config_h( "config.h" ); =cut sub write_config_h { my $self = shift->_get_instance(); my $tgt; defined($_[0]) ? ( ref($_[0]) ? $tgt = $_[0] : open($tgt, ">", $_[0]) ) : open($tgt, ">", "config.h"); my $conf_h = <<'EOC'; /** * Generated from Config::AutoConf * * Do not edit this file, all modifications will be lost, * modify Makefile.PL or Build.PL instead. * * Inspired by GNU AutoConf. * * (c) 2011 Alberto Simoes & Jens Rehsack */ #ifndef __CONFIG_H__ EOC while (my ($defname, $defcnt) = each(%{$self->{defines}})) { if ($defcnt->[0]) { defined $defcnt->[1] and $conf_h .= "/* " . $defcnt->[1] . " */\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 .= "#endif /* ?__CONFIG_H__ */\n"; print {$tgt} $conf_h; return; } =head2 push_lang(lang [, implementor ]) Puts the current used language on the stack and uses specified language for subsequent operations until ending pop_lang call. =cut sub push_lang { my $self = shift->_get_instance(); push @{$self->{lang_stack}}, [$self->{lang}]; $self->_set_language(@_); } =head2 pop_lang([ lang ]) Pops the currently used language from the stack and restores previously used language. If I specified, it's asserted that the current used language equals to specified language (helps finding control flow bugs). =cut sub pop_lang { my $self = shift->_get_instance(); 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} . ")"); $self->_set_language(@{pop @{$self->{lang_stack}}}); } =head2 lang_build_program( prologue, body ) Builds program for current chosen language. If no prologue is given (I), the default headers are used. If body is missing, default body is used. Typical call of Config::AutoConf->lang_build_program( "const char hw[] = \"Hello, World\\n\";", "fputs (hw, stdout);" ) will create const char hw[] = "Hello, World\n"; /* Override any gcc2 internal prototype to avoid an error. */ #ifdef __cplusplus extern "C" { #endif int main (int argc, char **argv) { (void)argc; (void)argv; fputs (hw, stdout);; return 0; } #ifdef __cplusplus } #endif =cut sub lang_build_program { my ($self, $prologue, $body) = @_; ref $self or $self = $self->_get_instance(); defined($prologue) or $prologue = $self->_default_includes(); defined($body) or $body = ""; $body = $self->_build_main($body); $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 evaluates to false. If C<@decls> is given, it's prepended before the test code at the variable definition place. =cut sub lang_build_bool_test { my ($self, $prologue, $test, @decls) = @_; ref $self or $self = $self->_get_instance(); defined($test) or $test = "1"; my $test_code = <lang_build_program($prologue, $test_code); } =head2 push_includes Adds given list of directories to preprocessor/compiler invocation. This is not proved to allow adding directories which might be created during the build. =cut sub push_includes { my ($self, @includes) = @_; ref $self or $self = $self->_get_instance(); push(@{$self->{extra_include_dirs}}, @includes); return; } =head2 push_preprocess_flags Adds given flags to the parameter list for preprocessor invocation. =cut sub push_preprocess_flags { my ($self, @cpp_flags) = @_; ref $self or $self = $self->_get_instance(); push(@{$self->{extra_preprocess_flags}}, @cpp_flags); return; } =head2 push_compiler_flags Adds given flags to the parameter list for compiler invocation. =cut sub push_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")) { my $lang_opt = pop(@compiler_flags); 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'"); } push(@{$self->{extra_compile_flags}->{$lang}}, @compiler_flags); return; } =head2 push_libraries Adds given list of libraries to the parameter list for linker invocation. =cut sub push_libraries { my ($self, @libs) = @_; ref $self or $self = $self->_get_instance(); push(@{$self->{extra_libs}}, @libs); return; } =head2 push_library_paths Adds given list of library paths to the parameter list for linker invocation. =cut sub push_library_paths { my ($self, @libdirs) = @_; ref $self or $self = $self->_get_instance(); push(@{$self->{extra_lib_dirs}}, @libdirs); return; } =head2 push_link_flags Adds given flags to the parameter list for linker invocation. =cut sub push_link_flags { my ($self, @link_flags) = @_; ref $self or $self = $self->_get_instance(); push(@{$self->{extra_link_flags}}, @link_flags); return; } =head2 compile_if_else( $src, \%options? ) This function tries to compile specified code and returns a boolean value containing check success state. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. =cut sub compile_if_else { 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( "testXXXXXX", SUFFIX => '.c', UNLINK => 0 ); print {$fh} $src; close $fh; my ($obj_file, $outbuf, $errbuf, $exception); ($outbuf, $errbuf) = capture { eval { $obj_file = $builder->compile( source => $filename, include_dirs => $self->{extra_include_dirs}, extra_compiler_flags => $self->_get_extra_compiler_flags() ); }; $exception = $@; }; unlink $filename; $obj_file and !-f $obj_file and undef $obj_file; unlink $obj_file if $obj_file; if ($exception || !$obj_file) { $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); $outbuf and $self->_add_log_lines("stdout was :\n" . $outbuf); $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); return 0; } $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $options->{action_on_true}->(); 1; } =head2 link_if_else( $src, \%options? ) This function tries to compile and link specified code and returns a boolean value containing check success state. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. =cut sub link_if_else { 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( "testXXXXXX", SUFFIX => '.c', UNLINK => 0 ); print {$fh} $src; close $fh; my ($obj_file, $outbuf, $errbuf, $exception); ($outbuf, $errbuf) = capture { eval { $obj_file = $builder->compile( source => $filename, include_dirs => $self->{extra_include_dirs}, extra_compiler_flags => $self->_get_extra_compiler_flags() ); }; $exception = $@; }; $obj_file and !-f $obj_file and undef $obj_file; if ($exception || !$obj_file) { $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); $outbuf and $self->_add_log_lines("stdout was :\n" . $outbuf); unlink $filename; unlink $obj_file if $obj_file; $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); return 0; } my $exe_file; ($outbuf, $errbuf) = capture { eval { $exe_file = $builder->link_executable( objects => $obj_file, extra_linker_flags => $self->_get_extra_linker_flags() ); }; $exception = $@; }; $exe_file and !-f $exe_file and undef $exe_file; unlink $filename; unlink $obj_file if $obj_file; unlink $exe_file if $exe_file; if ($exception || !$exe_file) { $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); $outbuf and $self->_add_log_lines("stdout was :\n" . $outbuf); $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); return 0; } $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $options->{action_on_true}->(); 1; } =head2 check_cached( $cache-key, $check-title, \&check-call, \%options? ) Retrieves the result of a previous L invocation from C, or (when called for the first time) populates the cache by invoking C<\&check_call>. If the very last parameter contains a hash reference, C references to I or I are executed on B call to check_cached (not just the first cache-populating invocation), respectively. =cut sub check_cached { 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 @_; $self->msg_checking($message); defined $ENV{$cache_name} and not defined $self->{cache}->{$cache_name} 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->(); $self->msg_result(@cached_result, $self->{cache}->{$cache_name}); $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $self->{cache}->{$cache_name} and $options->{action_on_true}->(); $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and !$self->{cache}->{$cache_name} and $options->{action_on_false}->(); $self->{cache}->{$cache_name}; } =head2 cache_val This function returns the value of a previously check_cached call. =cut sub cache_val { my ($self, $cache_name) = @_; ref $self or $self = $self->_get_instance(); defined $self->{cache}->{$cache_name} or return; $self->{cache}->{$cache_name}; } =head2 check_decl( $symbol, \%options? ) This method actually tests whether symbol is defined as a macro or can be used as an r-value, not whether it is really declared, because it is much safer to avoid introducing extra declarations when they are not needed. In order to facilitate use of C++ and overloaded function declarations, it is possible to specify function argument types in parentheses for types which can be zero-initialized: Config::AutoConf->check_decl("basename(char *)") This method caches its result in the Cset langE>_symbol variable. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =cut sub check_decl { 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_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 $body = <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}) : ()) } ); $have_decl; }; $self->check_cached( $cache_name, "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}) : ()) } ); } =head2 check_decls( symbols, \%options? ) For each of the symbols (with optional function argument types for C++ overloads), run L. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_decls { my ($self, $symbols) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $have_syms = 1; foreach my $symbol (@$symbols) { $have_syms &= $self->check_decl( $symbol, { %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) }) : () ), ( $options->{action_on_symbol_false} && "CODE" eq ref $options->{action_on_symbol_false} ? (action_on_false => sub { $options->{action_on_symbol_false}->($symbol) }) : () ), } ); } $have_syms 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_syms and $options->{action_on_false}->(); $have_syms; } sub _have_func_define_name { my $func = $_[0]; my $have_name = "HAVE_" . uc($func); $have_name =~ tr/_A-Za-z0-9/_/c; $have_name; } =head2 check_func( $function, \%options? ) This method actually tests whether I<$funcion> can be linked into a program trying to call I<$function>. This method caches its result in the ac_cv_func_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 check_func { 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); # 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), { ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); $have_func; }; # Run the check and cache the results. return $self->check_cached( $cache_name, "for $function", $check_sub, { 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}->(); }, } ); } =head2 check_funcs( \@functions-list, $action-if-true?, $action-if-false? ) The same as check_func, but takes a list of functions in I<\@functions-list> to look for and checks for each in turn. Define HAVE_FUNCTION for each function that was found. 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. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_funcs { my ($self, $functions_ref) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my %pass_options; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; # Go through the list of functions and call check_func for each one. We # 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}) { # 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 { # Run the user-provided hook, if there is one. defined $options->{action_on_function_true} and ref $options->{action_on_function_true} eq "CODE" and $options->{action_on_function_true}->($function); }; defined $options->{action_on_function_false} 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 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_funcs and $options->{action_on_false}->(); 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]; my $have_name = "HAVE_" . uc($type); $have_name =~ tr/*/P/; $have_name =~ tr/_A-Za-z0-9/_/c; $have_name; } =head2 check_type( $symbol, \%options? ) Check whether type is defined. It may be a compiler builtin type or defined by the includes. In C, type must be a type-name, so that the expression C is valid (but C is not). If I type is defined, preprocessor macro HAVE_I (in all capitals, with "*" replaced by "P" and spaces and dots replaced by underscores) is defined. This method caches its result in the Ctype variable. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =cut sub check_type { my ($self, $type) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; 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 $body = <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}) : ()) } ); $have_type; }; $self->check_cached( $cache_name, "for $type", $check_sub, { 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}->(); }, } ); } =head2 check_types( \@type-list, \%options? ) For each type in I<@type-list>, call L is called to check for type and return the accumulated result (accumulation op is binary and). 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_types { my ($self, $types) = @_; $self = $self->_get_instance(); my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $have_types = 1; foreach my $type (@$types) { $have_types &= $self->check_type( $type, { %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) }) : () ), ( $options->{action_on_type_false} && "CODE" eq ref $options->{action_on_type_false} ? (action_on_false => sub { $options->{action_on_type_false}->($type) }) : () ), } ); } $have_types 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_types and $options->{action_on_false}->(); $have_types; } sub _compute_int_compile { my ($self, $expr, $prologue, @decls) = @_; $self = $self->_get_instance(); 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))) { $low = $mid = 0; while (1) { 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) { $low = 0; last; } $mid = $low * 2; } } 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))) { $low = $mid; last; } $high = $mid - 1; # avoid overflow if ($mid < $high) { $high = 0; last; } $mid = $high * 2; } } # perform binary search between $low and $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))) { $high = $mid - 1; } elsif ($self->compile_if_else($self->lang_build_bool_test($prologue, "((long int)($expr)) > $mid", @decls))) { $low = $mid + 1; } else { return $mid; } } return; } =head2 compute_int( $expression, @decls?, \%options ) Returns the value of the integer I. The value should fit in an initializer in a C variable of type signed long. It should be possible to evaluate the expression at compile-time. If no includes are specified, the default includes are used. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =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) = @_; $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); defined $val 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 !defined $val and $options->{action_on_false}->(); $val; }; $self->check_cached( $cache_name, "for compute result of ($expr)", $check_sub, { 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}->(); }, } ); } =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, e.g. $ac->check_sizeof_type( "SV.sv_refcnt", { prologue => $include_perl } ); # or $ac->check_sizeof_type( "struct utmpx.ut_id", { prologue => "#include " } ); This method caches its result in the Cset langE>_type variable. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =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) = @_; $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 @decls; if ($type =~ m/^([^.]+)\.([^.]+)$/) { my $struct = $1; $type = "_ac_test_aggr.$2"; my $decl = "static $struct _ac_test_aggr;"; push(@decls, $decl); } my $typesize = $self->_compute_int_compile("sizeof($type)", $options->{prologue}, @decls); $typesize 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 !$typesize and $options->{action_on_false}->(); $typesize; }; $self->check_cached( $cache_name, "for size of $type", $check_sub, { 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}->(); }, } ); } =head2 check_sizeof_types( type, \%options? ) For each type L is called to check for size of type. If I is given, it is additionally executed when all of the sizes of the types could determined. If I is given, it is executed when one size of the types could not determined. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_sizeof_types { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $types) = @_; $self = $self->_get_instance(); my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $have_sizes = 1; foreach my $type (@$types) { $have_sizes &= !!( $self->check_sizeof_type( $type, { %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) }) : () ), ( $options->{action_on_size_false} && "CODE" eq ref $options->{action_on_size_false} ? (action_on_false => sub { $options->{action_on_size_false}->($type) }) : () ), } ) ); } $have_sizes 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_sizes and $options->{action_on_false}->(); $have_sizes; } sub _alignof_type_define_name { my $type = $_[0]; my $have_name = "ALIGNOF_" . uc($type); $have_name =~ tr/*/P/; $have_name =~ tr/_A-Za-z0-9/_/c; $have_name; } =head2 check_alignof_type( type, \%options? ) Define ALIGNOF_type to be the alignment in bytes of type. I must be valid as a structure member declaration or I must be a structure member itself. This method caches its result in the Cset langE>_type variable, with I<*> mapped to C

and other characters not suitable for a variable name mapped to underscores. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =cut sub check_alignof_type { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; 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 @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)", "# endif", "#endif" ); my ($struct, $memb); if ($type =~ m/^([^.]+)\.([^.]+)$/) { $struct = $1; $memb = $2; } else { 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); $typealign 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 !$typealign and $options->{action_on_false}->(); $typealign; }; $self->check_cached( $cache_name, "for align of $type", $check_sub, { 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}->(); }, } ); } =head2 check_alignof_types (type, [action-if-found], [action-if-not-found], [prologue = default includes]) For each type L is called to check for align of type. If I is given, it is additionally executed when all of the aligns of the types could determined. If I is given, it is executed when one align of the types could not determined. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_alignof_types { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $types) = @_; $self = $self->_get_instance(); my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $have_aligns = 1; foreach my $type (@$types) { $have_aligns &= !!( $self->check_alignof_type( $type, { %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) }) : () ), ( $options->{action_on_align_false} && "CODE" eq ref $options->{action_on_align_false} ? (action_on_false => sub { $options->{action_on_align_false}->($type) }) : () ), } ) ); } $have_aligns 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_aligns and $options->{action_on_false}->(); $have_aligns; } sub _have_member_define_name { my $member = $_[0]; my $have_name = "HAVE_" . uc($member); $have_name =~ tr/_A-Za-z0-9/_/c; $have_name; } =head2 check_member( member, \%options? ) Check whether I is in form of I.I and I is a member of the I aggregate. which are used prior to the aggregate under test. Config::AutoConf->check_member( "struct STRUCT_SV.sv_refcnt", { action_on_false => sub { Config::AutoConf->msg_failure( "sv_refcnt member required for struct STRUCT_SV" ); }, prologue => "#include \n#include " } ); This function will return a true value (1) if the member is found. If I aggregate has I member, preprocessor macro HAVE_I_I (in all capitals, with spaces and dots replaced by underscores) is defined. This macro caches its result in the Caggr_member variable. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =cut sub check_member { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; 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"); $member =~ m/^([^.]+)\.([^.]+)$/ or return croak("check_member(\"struct foo.member\", \%options)"); my $type = $1; $member = $2; my $cache_name = $self->_cache_type_name("$type.$member"); my $check_sub = sub { my $body = <lang_build_program($options->{prologue}, $body); my $have_member = $self->compile_if_else($conftest); unless ($have_member) { $body = <lang_build_program($options->{prologue}, $body); $have_member = $self->compile_if_else($conftest); } $have_member 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 $options->{action_on_false}->() unless $have_member; $have_member; }; $self->check_cached( $cache_name, "for $type.$member", $check_sub, { 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}->(); }, } ); } =head2 check_members( members, \%options? ) For each member L is called to check for member of aggregate. This function will return a true value (1) if at least one member is found. 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 favored over C (represented by L). If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_members { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $members) = @_; $self = $self->_get_instance(); my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $have_members = 0; foreach my $member (@$members) { $have_members |= ( $self->check_member( $member, { %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) }) : () ), ( $options->{action_on_member_false} && "CODE" eq ref $options->{action_on_member_false} ? (action_on_false => sub { $options->{action_on_member_false}->($member) }) : () ), } ) ); } $have_members 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_members and $options->{action_on_false}->(); $have_members; } sub _have_header_define_name { my $header = $_[0]; my $have_name = "HAVE_" . uc($header); $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } sub _check_header { my $options = {}; scalar @_ > 4 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $header, $prologue, $body) = @_; $prologue .= <<"_ACEOF"; #include <$header> _ACEOF my $conftest = $self->lang_build_program($prologue, $body); $self->compile_if_else($conftest, $options); } =head2 check_header( $header, \%options? ) This function is used to check if a specific header file is present in the system: if we detect it and if we can compile anything with that header included. Note that normally you want to check for a header first, and then check for the corresponding library (not all at once). The standard usage for this module is: Config::AutoConf->check_header("ncurses.h"); This function will return a true value (1) on success, and a false value if the header is not present or not available for common usage. 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 prepended to the tested header. If any of I, I is defined, both callbacks are passed to L as I or I to C, respectively. =cut sub check_header { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; 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"); return 0 unless $header; my $cache_name = $self->_cache_name($header); my $check_sub = sub { my $prologue = defined $options->{prologue} ? $options->{prologue} : ""; my $have_header = $self->_check_header( $header, $prologue, "", { ($options->{action_on_true} ? (action_on_true => $options->{action_on_true}) : ()), ($options->{action_on_false} ? (action_on_false => $options->{action_on_false}) : ()) } ); $have_header; }; $self->check_cached( $cache_name, "for $header", $check_sub, { 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}->(); }, } ); } =head2 check_headers This function uses check_header to check if a set of include files exist in the system and can be included and compiled by the available compiler. Returns the name of the first header file found. Passes an optional \%options hash to each L call. =cut sub check_headers { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); $self->check_header($_, $options) and return $_ for (@_); return; } =head2 check_all_headers This function checks each given header for usability and returns true when each header can be used -- otherwise false. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. Each of existing key/value pairs using I, I or I as key are passed-through to each call of L. Given callbacks for I or I are called for each symbol checked using L receiving the symbol as first argument. =cut sub check_all_headers { my $options = {}; scalar @_ > 2 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); @_ or return; my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; my $all_headers = 1; foreach my $header (@_) { $all_headers &= $self->check_header( $header, { %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) }) : () ), } ); } $all_headers 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 !$all_headers and $options->{action_on_false}->(); $all_headers; } =head2 check_stdc_headers Checks for standard C89 headers, namely stdlib.h, stdarg.h, string.h and float.h. If those are found, additional all remaining C89 headers are checked: assert.h, ctype.h, errno.h, limits.h, locale.h, math.h, setjmp.h, signal.h, stddef.h, stdio.h and time.h. Returns a false value if it fails. Passes an optional \%options hash to each L call. =cut my @ansi_c_headers = qw(stdlib stdarg string float assert ctype errno limits locale math setjmp signal stddef stdio time); sub check_stdc_headers { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); # 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."); $rc; } =head2 check_default_headers This function checks for some default headers, the std c89 headers and sys/types.h, sys/stat.h, memory.h, strings.h, inttypes.h, stdint.h and unistd.h Passes an optional \%options hash to each L call. =cut sub check_default_headers { my $options = {}; 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); } =head2 check_dirent_header 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 The directory-library declarations in your source code should look something like the following: #include #ifdef HAVE_DIRENT_H # include # define NAMLEN(dirent) strlen ((dirent)->d_name) #else # define dirent direct # define NAMLEN(dirent) ((dirent)->d_namlen) # ifdef HAVE_SYS_NDIR_H # include # endif # ifdef HAVE_SYS_DIR_H # include # endif # ifdef HAVE_NDIR_H # include # endif #endif Using the above declarations, the program would declare variables to be of type C, not C, and would access the length 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<< 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 to I or I are executed, respectively. Each of existing key/value pairs using I, I (as I having the name of the tested header as first argument) or I (as I having the name of the tested header as first argument) as key are passed-through to each call of L. Given callbacks for I or I are passed to the call of L. =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 = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); my %pass_options; defined $options->{prologue} and $pass_options{prologue} = $options->{prologue}; my $have_dirent; foreach my $header (qw(dirent.h sys/ndir.h sys/dir.h ndir.h)) { if ($self->check_header($header)) { 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, { 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}->(); }, } ); $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; } =head2 _check_perlapi_program This method provides the program source which is suitable to do basic compile/link tests to prove perl development environment. =cut sub _check_perlapi_program { my $self = shift; my $includes = $self->_default_includes_with_perl(); my $perl_check_body = <<'EOB'; I32 rc; SV *foo = newSVpv("Perl rocks", 11); rc = SvCUR(foo); EOB $self->lang_build_program($includes, $perl_check_body); } =head2 _check_compile_perlapi This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, reasonable basic checks - types, etc.) =cut sub _check_compile_perlapi { my $self = shift; my $conftest = $self->_check_perlapi_program(); $self->compile_if_else($conftest); } =head2 check_compile_perlapi This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, reasonable basic checks - types, etc.) =cut sub check_compile_perlapi { 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 }); } =head2 check_compile_perlapi_or_die Dies when not being able to compile using the Perl API =cut sub check_compile_perlapi_or_die { my $self = shift; $self->check_compile_perlapi(@_) or $self->msg_error("Cannot use Perl API - giving up"); } =head2 check_linkable_xs_so Checks whether a dynamic loadable object containing an XS module can be linked or not. Due the nature of the beast, this test currently always succeed. =cut sub check_linkable_xs_so { 1 } =head2 check_linkable_xs_so_or_die Dies when L fails. =cut sub check_linkable_xs_so_or_die { my $self = shift; $self->check_linkable_xs_so(@_) or $self->msg_error("Cannot link XS dynamic loadable - giving up"); } =head2 check_loadable_xs_so Checks whether a dynamic loadable object containing an XS module can be loaded or not. Due the nature of the beast, this test currently always succeed. =cut sub check_loadable_xs_so { 1 } =head2 check_loadable_xs_so_or_die Dies when L fails. =cut sub check_loadable_xs_so_or_die { my $self = shift; $self->check_loadable_xs_so(@_) or $self->msg_error("Cannot load XS dynamic loadable - giving up"); } =head2 _check_link_perlapi This method can be used from other checks to prove whether we have a perl development environment including a suitable libperl or not (perl.h, reasonable basic checks - types, etc.) Caller must ensure that the linker flags are set appropriate (C<-lperl> or similar). =cut sub _check_link_perlapi { 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 $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}) { foreach my $perllib (split(" ", $Config{perllibs})) { $perllib =~ m/^\-l(\w+)$/ and push @{$self->{extra_libs}}, "$1" and next; push @{$self->{extra_link_flags}}, $perllib; } } my $have_libperl = $self->link_if_else($conftest); $have_libperl or $self->{extra_libs} = [@save_libs]; $have_libperl or $self->{extra_link_flags} = [@save_extra_link_flags]; $have_libperl; } =head2 check_link_perlapi This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, libperl.la, reasonable basic checks - types, etc.) =cut sub check_link_perlapi { 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 }); } sub _have_lib_define_name { my $lib = $_[0]; my $have_name = "HAVE_LIB" . uc($lib); $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_lib( lib, func, @other-libs?, \%options? ) This function is used to check if a specific library includes some function. Call it with the library name (without the lib portion), and the name of the function you want to test: Config::AutoConf->check_lib("z", "gzopen"); It returns 1 if the function exist, 0 otherwise. In case of function found, the HAVE_LIBlibrary (all in capitals) preprocessor macro is defined with 1 and $lib together with @other_libs are added to the list of libraries to link with. 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 routine may fail to detect that library is present, because linking the test program can fail with unresolved symbols. The other-libraries argument should be limited to cases where it is desirable to test for one library in the presence of another that is not already in LIBS. This method caches its result in the Clib_func 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. It's recommended to use L instead of check_lib these days. =cut sub check_lib { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); 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]}; 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 $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}) : ()) } ); $self->{extra_libs} = [@save_libs]; $have_lib; }; $self->check_cached( $cache_name, "for $func in -l$lib", $check_sub, { 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?, @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 Config::AutoConf->link_if_else( Config::AutoConf->lang_call( "", "$function" ) ); first with no libraries, then for each library listed in search-libs. I must be specified as an array reference to avoid confusion in argument order. Prepend -llibrary to LIBS for the first library found to contain function. 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)]> 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 library containing function was found, otherwise as the -llibrary option that needs to be prepended to LIBS. 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. Given callbacks for I or I are called for each library checked using L receiving the library as first argument and all C<@other_libs> subsequently. =cut sub search_libs { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); my ($func, $libs, @other_libs, @other_link_flags) = @_; (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]}; scalar(@other_link_flags) == 1 and ref($other_link_flags[0]) eq "ARRAY" and @other_link_flags = @{$other_link_flags[0]}; 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, @_) }) : () ), ( $options->{action_on_lib_false} && "CODE" eq ref $options->{action_on_lib_false} ? (action_on_false => sub { $options->{action_on_lib_false}->($libstest, @other, @_) }) : () ), } ) 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 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_lib and $options->{action_on_false}->(); $have_lib; }; return $self->check_cached( $cache_name, "for library containing $func", $check_sub, { 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}) : ()) } ); } sub _check_lm_funcs { qw(log2 pow log10 log exp sqrt) } =head2 check_lm( \%options? ) This method is used to check if some common C functions are available, and if C<-lm> is needed. Returns the empty string if no library is needed, or the "-lm" string if libm is needed. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. Each of existing key/value pairs using I (as I having the name of the tested functions as first argument), I (as I having the name of the tested functions as first argument), I (as I having the name of the tested functions as first argument), I (as I having the name of the tested functions as first argument) as key are passed- through to each call of L. Given callbacks for I, I, I or I are passed to the call of L. B that I and I or I and I cannot be used at the same time, respectively. =cut sub check_lm { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my $self = shift->_get_instance(); defined $options->{action_on_lib_true} and defined $options->{action_on_func_lib_true} and croak("action_on_lib_true and action_on_func_lib_true cannot be used together"); defined $options->{action_on_lib_false} and defined $options->{action_on_func_lib_false} and croak("action_on_lib_false and action_on_func_lib_false cannot be used together"); my %pass_options; defined $options->{action_on_cache_true} and $pass_options{action_on_cache_true} = $options->{action_on_cache_true}; defined $options->{action_on_cache_false} and $pass_options{action_on_cache_false} = $options->{action_on_cache_false}; defined $options->{action_on_lib_true} and $pass_options{action_on_lib_true} = $options->{action_on_lib_true}; defined $options->{action_on_lib_false} and $pass_options{action_on_lib_false} = $options->{action_on_lib_false}; my $fail = 0; my $required = ""; my @math_funcs = $self->_check_lm_funcs; for my $func (@math_funcs) { my $ans = $self->search_libs( $func, ['m'], { %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, @_) }) : () ), ( $options->{action_on_func_false} && "CODE" eq ref $options->{action_on_func_false} ? (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, @_) }) : () ), ( $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, @_) }) : () ), }, ); $ans or $fail = 1; $ans ne "none required" and $required = $ans; } !$fail and $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $options->{action_on_true}->(); $fail and $options->{action_on_false} and ref $options->{action_on_false} eq "CODE" and $options->{action_on_false}->(); $required; } =head2 pkg_config_package_flags($package, \%options?) 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, ); 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. If any of I, I is defined, both callbacks are passed to L as I or I to L, respectively. =cut my $_pkg_config_prog; sub _pkg_config_flag { 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); }; chomp $stdout; 0 == $exit and return $stdout; return $exit; } sub pkg_config_package_flags { my $options = {}; scalar @_ > 1 and ref $_[-1] eq "HASH" and $options = pop @_; my ($self, $package) = @_; $self = $self->_get_instance(); (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 $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 $CFLAGS = defined $ENV{$ENV_CFLAGS} ? $ENV{$ENV_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; # 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 not looks_like_number($LIBS) and @pkg_libs = ( map { $_ =~ s/^\s+//; $_ =~ s/\s+$//; Text::ParseWords::shellwords $_; } 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); $pkg_config_flags 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 !$pkg_config_flags and $options->{action_on_false}->(); $pkg_config_flags; }; $self->check_cached( $cache_name, "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}) : ()) } ); } =head2 _check_mm_pureperl_build_wanted This method proves the C<_argv> attribute and (when set) the C whether they contain I or not. The attribute C<_force_xs> is set as appropriate, which allows a compile test to bail out when C is called with I. =cut sub _check_mm_pureperl_build_wanted { my $self = shift->_get_instance; defined $ENV{PERL_MM_OPT} and my @env_args = split " ", $ENV{PERL_MM_OPT}; foreach my $arg (@{$self->{_argv}}, @env_args) { $arg =~ m/^PUREPERL_ONLY=(.*)$/ and return int($1); } 0; } =head2 _check_mb_pureperl_build_wanted This method proves the C<_argv> attribute and (when set) the C whether they contain I<--pureperl-only> or not. =cut sub _check_mb_pureperl_build_wanted { my $self = shift->_get_instance; defined $ENV{PERL_MB_OPT} and my @env_args = split " ", $ENV{PERL_MB_OPT}; foreach my $arg (@{$self->{_argv}}, @env_args) { $arg eq "--pureperl-only" and return 1; } 0; } =head2 _check_pureperl_required This method calls C<_check_mm_pureperl_build_wanted> when running under L (C) or C<_check_mb_pureperl_build_wanted> when running under a C (L compatible) environment. When neither is found (C<$0> contains neither C nor C), simply 0 is returned. =cut sub _check_pureperl_required { my $self = shift; $0 =~ m/Makefile\.PL$/i and return $self->_check_mm_pureperl_build_wanted(@_); $0 =~ m/Build\.PL$/i and return $self->_check_mb_pureperl_build_wanted(@_); 0; } =head2 check_pureperl_required This check method proves whether a pure perl build is wanted or not by cached-checking C<< $self->_check_pureperl_required >>. =cut sub check_pureperl_required { 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 }); } =head2 check_produce_xs_build This routine checks whether XS can be produced. Therefore it does following checks in given order: =over 4 =item * check pure perl environment variables (L) or command line arguments and return false when pure perl is requested =item * check whether a compiler is available (L) and return false if none found =item * check whether a test program accessing Perl API can be compiled and die with error if not =back When all checks passed successfully, return a true value. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. =cut sub check_produce_xs_build { 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 e.g. TuX, 99% likely return 0) $self->check_compile_perlapi_or_die(); $options->{action_on_true} and ref $options->{action_on_true} eq "CODE" and $options->{action_on_true}->(); return 1; } =head2 check_produce_loadable_xs_build This routine proves whether XS should be built and it's possible to create a dynamic linked object which can be loaded using Perl's Dynaloader. The extension over L can be avoided by adding the C to C<$ENV{PERL5_AC_OPTS}>. If the very last parameter contains a hash reference, C references to I or I are executed, respectively. =cut sub check_produce_loadable_xs_build { my $self = shift->_get_instance; $self->check_produce_xs_build(@_) and !$self->{c_ac_flags}->{notest_loadable_xs} and $self->check_linkable_xs_so_or_die and $self->check_loadable_xs_so_or_die; } # # # Auxiliary funcs # =head2 _set_argv Intended to act as a helper for evaluating given command line arguments. Stores given arguments in instances C<_argv> attribute. Call once at very begin of C or C: Your::Pkg::Config::AutoConf->_set_args(@ARGV); =cut sub _set_argv { my ($self, @argv) = @_; $self = $self->_get_instance; $self->{_argv} = \@argv; return; } sub _sanitize { # This is hard coded, and maybe a little stupid... my $x = shift; $x =~ s/ //g; $x =~ s/\///g; $x =~ s/\\//g; $x; } sub _get_instance { ref $_[0] and return $_[0]; defined $glob_instance or $glob_instance = $_[0]->new(); $glob_instance; } sub _get_builder { 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} . "\""); $self->{lang_supported}->{$self->{lang}}->new(); } sub _set_language { my $self = shift->_get_instance(); my ($lang, $impl) = @_; defined($lang) or croak("Missing language"); defined($impl) 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} . ")"); defined($impl) 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->{extra_compile_flags}->{$lang}) or $self->{extra_compile_flags}->{$lang} = []; $self->{lang} = $lang; return; } sub _on_return_callback_helper { my $callback = pop @_; my $options = pop @_; $options->{$callback} and ref $options->{$callback} eq "CODE" and $options->{$callback}->(); @_ and wantarray and return @_; 1 == scalar @_ and return $_[0]; return; } sub _fill_defines { 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}})) { $defcnt->[0] or next; defined $defcnt->[1] and $conftest .= "/* " . $defcnt->[1] . " */\n"; $conftest .= join(" ", "#define", $defname, $defcnt->[0]) . "\n"; } $conftest .= "/* end of conftest.h */\n"; $conftest; } # # default includes taken from autoconf/headers.m4 # =head2 _default_includes returns a string containing default includes for program prologue taken from C: #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif =cut my $_default_includes = <<"_ACEOF"; #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif _ACEOF sub _default_includes { $_default_includes } sub _default_main { $_[0]->_build_main("") } my $_main_tpl = <<"_ACEOF"; int main () { %s; return 0; } _ACEOF sub _build_main { my $self = shift->_get_instance(); my $body = shift || ""; sprintf($_main_tpl, $body); } =head2 _default_includes_with_perl returns a string containing default includes for program prologue containing I<_default_includes> plus #include #include =cut my $_include_perl = <<"_ACEOF"; #include #include #include /* for perl context in threaded perls */ _ACEOF sub _default_includes_with_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); $cache_name =~ tr/_A-Za-z0-9/_/c; $cache_name; } sub _get_log_fh { my $self = $_[0]->_get_instance(); 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}: $!"; $self->{logfh} = [$fh]; } $self->{logfh}; } sub _add_log_entry { my ($self, @logentries) = @_; ref($self) or $self = $self->_get_instance(); $self->_get_log_fh(); foreach my $logentry (@logentries) { foreach my $fh (@{$self->{logfh}}) { print {$fh} "$logentry"; } } return; } sub _add_log_lines { 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}}) { print {$fh} $logmsg; } return; } =head2 add_log_fh Push new file handles at end of log-handles to allow tee'ing log-output =cut sub add_log_fh { my ($self, @newh) = @_; $self->_get_log_fh(); SKIP_DUP: foreach my $fh (@newh) { foreach my $eh (@{$self->{logfh}}) { $fh == $eh and next SKIP_DUP; } push @{$self->{logfh}}, $fh; } return; } =head2 delete_log_fh Removes specified log file handles. This method allows you to shoot yourself in the foot - it doesn't prove whether the primary nor the last handle is removed. Use with caution. =cut sub delete_log_fh { my ($self, @xh) = @_; $self->_get_log_fh(); SKIP_DUP: foreach my $fh (@xh) { foreach my $ih (0 .. $#{$self->{logfh}}) { $fh == $self->{logfh}->[$ih] or next; splice @{$self->{logfh}}, $ih, 1; last; } } return; } sub _cache_type_name { 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(" ", 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 @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 Alberto Simões, C<< >> Jens Rehsack, C<< >> =head1 NEXT STEPS Although a lot of work needs to be done, these are the next steps I intend to take. - detect flex/lex - detect yacc/bison/byacc - detect ranlib (not sure about its importance) These are the ones I think not too much important, and will be addressed later, or by request. - detect an 'install' command - detect a 'ln -s' command -- there should be a module doing this kind of task. =head1 BUGS A lot. Portability is a pain. B<>. Please report any bugs or feature requests to C, or through the web interface at L. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Config::AutoConf You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * MetaCPAN L =item * Git Repository L =back =head1 ACKNOWLEDGEMENTS Michael Schwern for kind MacOS X help. Ken Williams for ExtUtils::CBuilder Peter Rabbitson for help on refactoring and making the API more Perl'ish =head1 COPYRIGHT & LICENSE 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. =head1 SEE ALSO ExtUtils::CBuilder(3) =cut 1; # End of Config::AutoConf List-MoreUtils-XS-0.430/inc/latest/0000755000175000017500000000000013743757362015152 5ustar snosnoList-MoreUtils-XS-0.430/inc/latest/private.pm0000644000175000017500000000601613743756025017160 0ustar snosnouse strict; use warnings; package inc::latest::private; # ABSTRACT: private implementation for inc::latest our $VERSION = '0.500'; use File::Spec; use IO::File; # must ultimately "goto" the import routine of the module to be loaded # so that the calling package is correct when $mod->import() runs. sub import { my ( $package, $mod, @args ) = @_; my $file = $package->_mod2path($mod); if ( $INC{$file} ) { # Already loaded, but let _load_module handle import args goto \&_load_module; } # A bundled copy must be present my ( $bundled, $bundled_dir ) = $package->_search_bundled($file) or die "No bundled copy of $mod found"; my $from_inc = $package->_search_INC($file); unless ($from_inc) { # Only bundled is available unshift( @INC, $bundled_dir ); goto \&_load_module; } if ( _version($from_inc) >= _version($bundled) ) { # Ignore the bundled copy goto \&_load_module; } # Load the bundled copy unshift( @INC, $bundled_dir ); goto \&_load_module; } sub _version { require ExtUtils::MakeMaker; return ExtUtils::MM->parse_version(shift); } # use "goto" for import to preserve caller sub _load_module { my $package = shift; # remaining @_ is ready for goto my ( $mod, @args ) = @_; eval "require $mod; 1" or die $@; if ( my $import = $mod->can('import') ) { goto $import; } return 1; } sub _search_bundled { my ( $self, $file ) = @_; my $mypath = 'inc'; local *DH; # Maintain 5.005 compatibility opendir DH, $mypath or die "Can't open directory $mypath: $!"; while ( defined( my $e = readdir DH ) ) { next unless $e =~ /^inc_/; my $try = File::Spec->catfile( $mypath, $e, $file ); return ( $try, File::Spec->catdir( $mypath, $e ) ) if -e $try; } return; } # Look for the given path in @INC. sub _search_INC { # TODO: doesn't handle coderefs or arrayrefs or objects in @INC, but # it probably should my ( $self, $file ) = @_; foreach my $dir (@INC) { next if ref $dir; my $try = File::Spec->catfile( $dir, $file ); return $try if -e $try; } return; } # Translate a module name into a directory/file.pm to search for in @INC sub _mod2path { my ( $self, $mod ) = @_; my @parts = split /::/, $mod; $parts[-1] .= '.pm'; return $parts[0] if @parts == 1; return File::Spec->catfile(@parts); } 1; # vim: ts=4 sts=4 sw=4 tw=75 et: __END__ =pod =encoding UTF-8 =head1 NAME inc::latest::private - private implementation for inc::latest =head1 VERSION version 0.500 =head1 DESCRIPTION This module has the private methods used to find and load bundled modules. It should not be used directly. =head1 AUTHORS =over 4 =item * David Golden =item * Eric Wilhelm =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2009 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut List-MoreUtils-XS-0.430/META.json0000664000175000017500000000465113743757362014536 0ustar snosno{ "abstract" : "Provide the stuff missing in List::Util in XS", "author" : [ "Tassilo von Parseval ", "Adam Kennedy ", "Jens Rehsack " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.46, CPAN::Meta::Converter version 2.150010", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "List-MoreUtils-XS", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "recommends" : { "Config::AutoConf" : "0.315", "inc::latest" : "0.500" }, "requires" : { "Carp" : "0", "ExtUtils::MakeMaker" : "0", "File::Basename" : "0", "File::Copy" : "0", "File::Path" : "0", "File::Spec" : "0", "IPC::Cmd" : "0", "base" : "0" } }, "develop" : { "requires" : { "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" } }, "runtime" : { "requires" : { "XSLoader" : "0.22" } }, "test" : { "recommends" : { "Test::LeakTrace" : "0" }, "requires" : { "Storable" : "0", "Test::More" : "0.96" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-List-MoreUtils-XS@rt.cpan.org", "web" : "https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils-XS" }, "homepage" : "https://metacpan.org/release/List-MoreUtils-XS", "repository" : { "type" : "git", "url" : "https://github.com/perl5-utils/List-MoreUtils-XS.git", "web" : "https://github.com/perl5-utils/List-MoreUtils-XS" } }, "version" : "0.430", "x_serialization_backend" : "JSON::PP version 4.05" } List-MoreUtils-XS-0.430/LICENSE0000644000175000017500000002613513735527357014121 0ustar snosno 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. List-MoreUtils-XS-0.430/MANIFEST.SKIP0000644000175000017500000000063013735541005014764 0ustar snosno\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 List-MoreUtils-XS-0.430/multicall.h0000644000175000017500000001255413735527357015253 0ustar snosno/* from vutil.h * Perl 5 license */ #ifndef PERL_VERSION_DECIMAL # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s) #endif #ifndef PERL_DECIMAL_VERSION # define PERL_DECIMAL_VERSION \ PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION) #endif #ifndef PERL_VERSION_LT # define PERL_VERSION_LT(r,v,s) \ (PERL_DECIMAL_VERSION < PERL_VERSION_DECIMAL(r,v,s)) #endif #ifndef PERL_VERSION_LE # define PERL_VERSION_LE(r,v,s) \ (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s)) #endif #ifndef PERL_VERSION_GE # define PERL_VERSION_GE(r,v,s) \ (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s)) #endif #ifndef PERL_VERSION_GT # define PERL_VERSION_GT(r,v,s) \ (PERL_DECIMAL_VERSION > PERL_VERSION_DECIMAL(r,v,s)) #endif /* 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. * */ #if PERL_VERSION_GE(5,8,8) && PERL_VERSION_LT(5,10,1) # undef dMULTICALL # undef MULTICALL_PUSHSUB # undef PUSH_MULTICALL # undef POP_MULTICALL #endif #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 List-MoreUtils-XS-0.430/ppport.h0000644000175000017500000060560113735527357014612 0ustar snosno#if 0 <<'SKIP'; #endif /* ---------------------------------------------------------------------- ppport.h -- Perl/Pollution/Portability Version 3.37 Automatically created by Devel::PPPort running under perl 5.027007. 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.37 =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 SvRX() NEED_SvRX NEED_SvRX_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 gv_fetchpvn_flags() NEED_gv_fetchpvn_flags NEED_gv_fetchpvn_flags_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.37; 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.024000| BhkENABLE||5.024000| BhkENTRY_set||5.024000| BhkENTRY||| BhkFLAGS||| CALL_BLOCK_HOOKS||| CLASS|||n CPERLscope|5.005000||p CX_CURPAD_SAVE||| CX_CURPAD_SV||| C_ARRAY_END|5.013002||p C_ARRAY_LENGTH|5.008001||p 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||| DECLARATION_FOR_LC_NUMERIC_MANIPULATION||5.021010|n DEFSV_set|5.010001||p DEFSV|5.004050||p DO_UTF8||5.006000| 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||| 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.024000| 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||p OpLASTSIB_set|5.021011||p OpMAYBESIB_set|5.021011||p OpMORESIB_set|5.021011||p OpSIBLING|5.021007||p 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.024000||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.024000||p PERL_MAGIC_isaelem|5.007002||p PERL_MAGIC_isa|5.007002||p PERL_MAGIC_mutex|5.024000||p PERL_MAGIC_nkeys|5.007002||p PERL_MAGIC_overload_elem|5.024000||p PERL_MAGIC_overload_table|5.007002||p PERL_MAGIC_overload|5.024000||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.024000| 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_RESULT|5.021001||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.024000||p PL_bufptr|5.024000||p PL_check||5.006000| PL_compiling|5.004050||p PL_comppad_name||5.017004| PL_comppad||5.008001| PL_copline|5.024000||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.024000||p PL_expect|5.024000||p PL_hexdigit|5.005000||p PL_hints|5.005000||p PL_in_my_stash|5.024000||p PL_in_my|5.024000||p PL_keyword_plugin||5.011002| PL_last_in_gv|||n PL_laststatval|5.005000||p PL_lex_state|5.024000||p PL_lex_stuff|5.024000||p PL_linestr|5.024000||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.024000||p PL_rsfp|5.024000||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.024000||p POP_MULTICALL||5.024000| POPi|||n POPl|||n POPn|||n POPpbytex||5.007001|n POPpx||5.005030|n POPp|||n POPs|||n POPul||5.006000|n POPu||5.004000|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.024000| PUSHi||| PUSHmortal|5.009002||p PUSHn||| PUSHp||| PUSHs||| PUSHu|5.004000||p PUTBACK||| PadARRAY||5.024000| PadMAX||5.024000| PadlistARRAY||5.024000| PadlistMAX||5.024000| PadlistNAMESARRAY||5.024000| PadlistNAMESMAX||5.024000| PadlistNAMES||5.024000| PadlistREFCNT||5.017004| PadnameIsOUR||| PadnameIsSTATE||| PadnameLEN||5.024000| PadnameOURSTASH||| PadnameOUTER||| PadnamePV||5.024000| PadnameREFCNT_dec||5.024000| PadnameREFCNT||5.024000| PadnameSV||5.024000| PadnameTYPE||| PadnameUTF8||5.021007| PadnamelistARRAY||5.024000| PadnamelistMAX||5.024000| PadnamelistREFCNT_dec||5.024000| PadnamelistREFCNT||5.024000| 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| RESTORE_LC_NUMERIC||5.024000| 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 STORE_LC_NUMERIC_FORCE_TO_UNDERLYING||5.024000| STORE_LC_NUMERIC_SET_TO_NEEDED||5.024000| 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||p SvRX|5.009005||p 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 UTF8SKIP||5.006000| UTF8_MAXBYTES|5.009002||p UVCHR_SKIP||5.022000| 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.024000||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.024000| XS_EXTERNAL||5.024000| XS_INTERNAL||5.024000| XS_VERSION_BOOTCHECK||5.024000| XS_VERSION||| XSprePUSH|5.006000||p XS||| XopDISABLE||5.024000| XopENABLE||5.024000| XopENTRYCUSTOM||5.024000| XopENTRY_set||5.024000| XopENTRY||5.024000| 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||| _invlistEQ||| _invlist_array_init|||n _invlist_contains_cp|||n _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 _setlocale_debug_string|||n _setup_canned_invlist||| _swash_inversion_hash||| _swash_to_invlist||| _to_fold_latin1||| _to_uni_fold_flags||5.014000| _to_upper_title_latin1||| _to_utf8_case||| _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.024000||p aTHXR|5.024000||p aTHX_|5.006000||p aTHX|5.006000||p 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_LB||| 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_LB||| 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| cBOOL|5.013000||p 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_defarray||5.023008| 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.024000| cophh_store_pvn||5.013007| cophh_store_pvs||5.013007| cophh_store_pv||5.013007| cophh_store_sv||5.013007| core_prototype||| coresub_op||| 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||| cx_popblock||5.023008| cx_popeval||5.023008| cx_popformat||5.023008| cx_popgiven||5.023008| cx_poploop||5.023008| cx_popsub_args||5.023008| cx_popsub_common||5.023008| cx_popsub||5.023008| cx_popwhen||5.023008| cx_pushblock||5.023008| cx_pusheval||5.023008| cx_pushformat||5.023008| cx_pushgiven||5.023008| cx_pushloop_for||5.023008| cx_pushloop_plain||5.023008| cx_pushsub||5.023008| cx_pushwhen||5.023008| cx_topblock||5.023008| 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.024000||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_compile||| dofile||| dofindlabel||| doform||| doing_taint||5.008001|n dooneliner||| doopen_pm||| doparseform||| dopoptoeval||| dopoptogivenfor||| dopoptolabel||| dopoptoloop||| dopoptosub_at||| dopoptowhen||| doref||5.009003| dounwind||| dowantarray||| drand48_init_r|||n drand48_r|||n dtrace_probe_call||| dtrace_probe_load||| dtrace_probe_op||| dtrace_probe_phase||| 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||| edit_distance|||n 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_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||| 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||| gv_fullname3||5.003070| gv_fullname4||5.006001| gv_fullname||| gv_handler||5.007001| gv_init_pvn||| 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_named_backref||| handle_possible_posix||| handle_regex_sets||| he_dup||| hek_dup||| hfree_next_entry||| 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_entries||| 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_clear||| invlist_clone||| invlist_contents||| 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_replace_list_destroys_src||| 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 isIDCONT||5.017008| isIDFIRST_lazy||5.021001| isIDFIRST||| isLB||| 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_adjust_stacks||5.023008| 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_alloc|||n mem_log_common|||n mem_log_free|||n mem_log_realloc|||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||5.004050|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.024000| 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.024000| 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|||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||| output_or_return_posix_warnings||| 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_common||| put_charclass_bitmap_innards_invlist||| 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_exec_indentf|||v re_indentf|||v re_intuit_start||5.019001| re_intuit_string||5.006000| re_op_compile||| re_printf|||v realloc||5.007002|n reentrant_free||5.024000| reentrant_init||5.024000| reentrant_retry||5.024000|vn reentrant_size||5.024000| 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.024000| 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||| regex_set_precedence|||n 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||| regpiece||| 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_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| savetmps||5.023008| 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||| skip_to_be_ignored_text||| 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.024000|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||5.015004| 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.024000| 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_utf8||5.019001| toFOLD_uvchr||5.023009| toFOLD||5.019001| toLOWER_L1||5.019001| toLOWER_LC||5.004000| toLOWER_utf8||5.015007| toLOWER_uvchr||5.023009| toLOWER||| toTITLE_utf8||5.015007| toTITLE_uvchr||5.023009| toTITLE||5.019001| toUPPER_utf8||5.015007| toUPPER_uvchr||5.023009| 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_MAGIC_qr # define PERL_MAGIC_qr 'r' #endif #ifndef cBOOL # define cBOOL(cbool) ((cbool) ? (bool)1 : (bool)0) #endif #ifndef OpHAS_SIBLING # define OpHAS_SIBLING(o) (cBOOL((o)->op_sibling)) #endif #ifndef OpSIBLING # define OpSIBLING(o) (0 + (o)->op_sibling) #endif #ifndef OpMORESIB_set # define OpMORESIB_set(o, sib) ((o)->op_sibling = (sib)) #endif #ifndef OpLASTSIB_set # define OpLASTSIB_set(o, parent) ((o)->op_sibling = NULL) #endif #ifndef OpMAYBESIB_set # define OpMAYBESIB_set(o, sib, parent) ((o)->op_sibling = (sib)) #endif #ifndef SvRX #if defined(NEED_SvRX) static void * DPPP_(my_SvRX)(pTHX_ SV *rv); static #else extern void * DPPP_(my_SvRX)(pTHX_ SV *rv); #endif #ifdef SvRX # undef SvRX #endif #define SvRX(a) DPPP_(my_SvRX)(aTHX_ a) #if defined(NEED_SvRX) || defined(NEED_SvRX_GLOBAL) void * DPPP_(my_SvRX)(pTHX_ SV *rv) { if (SvROK(rv)) { SV *sv = SvRV(rv); if (SvMAGICAL(sv)) { MAGIC *mg = mg_find(sv, PERL_MAGIC_qr); if (mg && mg->mg_obj) { return mg->mg_obj; } } } return 0; } #endif #endif #ifndef SvRXOK # define SvRXOK(sv) (!!SvRX(sv)) #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 PERL_UNUSED_RESULT # if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT) # define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END # else # define PERL_UNUSED_RESULT(v) ((void)(v)) # 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 #ifndef WIDEST_UTYPE # ifdef QUADKIND # ifdef U64TYPE # define WIDEST_UTYPE U64TYPE # else # define WIDEST_UTYPE Quad_t # endif # else # define WIDEST_UTYPE U32 # endif #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 C_ARRAY_LENGTH # define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) #endif #ifndef C_ARRAY_END # define C_ARRAY_END(a) ((a) + C_ARRAY_LENGTH(a)) #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 * doing. 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 gv_fetchpvn_flags #if defined(NEED_gv_fetchpvn_flags) static GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types); static #else extern GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types); #endif #ifdef gv_fetchpvn_flags # undef gv_fetchpvn_flags #endif #define gv_fetchpvn_flags(a,b,c,d) DPPP_(my_gv_fetchpvn_flags)(aTHX_ a,b,c,d) #define Perl_gv_fetchpvn_flags DPPP_(my_gv_fetchpvn_flags) #if defined(NEED_gv_fetchpvn_flags) || defined(NEED_gv_fetchpvn_flags_GLOBAL) GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types) { char *namepv = savepvn(name, len); GV* stash = gv_fetchpv(namepv, TRUE, SVt_PVHV); Safefree(namepv); return stash; } #endif #endif #ifndef GvSVn # define GvSVn(gv) GvSV(gv) #endif #ifndef isGV_with_GP # define isGV_with_GP(gv) isGV(gv) #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 gv_init_pvn # define gv_init_pvn(gv, stash, ptr, len, flags) gv_init(gv, stash, ptr, len, flags & GV_ADDMULTI ? TRUE : FALSE) #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 #ifndef MUTABLE_PTR #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 #endif #ifndef MUTABLE_SV # define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p)) #endif /* 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 */ List-MoreUtils-XS-0.430/ARTISTIC-1.00000644000175000017500000001426013735527357014551 0ustar snosno The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End List-MoreUtils-XS-0.430/.perltidyrc0000644000175000017500000000017413735527357015271 0ustar snosno-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 List-MoreUtils-XS-0.430/README.md0000644000175000017500000000440713735527357014371 0ustar snosno# NAME List::MoreUtils::XS - Provide compiled List::MoreUtils functions # SYNOPSIS use List::Moreutils::XS (); use List::MoreUtils ':all'; my @procs = get_process_stats->fetchall_array; # sort by ppid, then pid qsort { $a->[3] <=> $b->[3] or $a->[2] <=> $b->[2] } @procs; while( @procs ) { my $proc = shift @procs; my @children = equal_range { $_->[3] <=> $proc->[2] } @procs; } my @left = qw(this is a test); my @right = qw(this is also a test); my %rlinfo = listcmp @left, @right; # on unsorted my $i = firstidx { $_ eq 'yeah' } @foo; # on sorted - always first, but might not be 'yeah' my $j = lower_bound { $_ cmp 'yeah' } @bar; # on sorted - any of occurrences, is surely 'yeah' my $k = bsearchidx { $_ cmp 'yeah' } @bar; # DESCRIPTION List::MoreUtils::XS is a backend for List::MoreUtils. Even if it's possible (because of user wishes) to have it practically independent from [List::MoreUtils](https://metacpan.org/pod/List::MoreUtils), it technically depend on `List::MoreUtils`. Since it's only a backend, the API is not public and can change without any warning. # SEE ALSO [List::Util](https://metacpan.org/pod/List::Util), [List::AllUtils](https://metacpan.org/pod/List::AllUtils) # AUTHOR Jens Rehsack <rehsack AT cpan.org> Adam Kennedy <adamk@cpan.org> Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de> # COPYRIGHT AND LICENSE Some parts copyright 2011 Aaron Crane. Copyright 2004 - 2010 by Tassilo von Parseval 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. List-MoreUtils-XS-0.430/t/0000755000175000017500000000000013743757362013350 5ustar snosnoList-MoreUtils-XS-0.430/t/lib/0000755000175000017500000000000013743757362014116 5ustar snosnoList-MoreUtils-XS-0.430/t/lib/Test/0000755000175000017500000000000013743757362015035 5ustar snosnoList-MoreUtils-XS-0.430/t/lib/Test/LMU.pm0000644000175000017500000000677713735543236016043 0ustar snosnopackage Test::LMU; use strict; require Exporter; use Test::More import => ['!pass']; use Carp qw/croak/; use base qw(Test::Builder::Module Exporter); 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 sub is_true { @_ == 1 or croak "Expected 1 param"; my $tb = $CLASS->builder(); $tb->ok($_[0], "is_true ()"); } sub is_false { @_ == 1 or croak "Expected 1 param"; my $tb = $CLASS->builder(); $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 ()"); } sub is_undef { @_ <= 1 or croak "Expected 0..1 param"; my $tb = $CLASS->builder(); $tb->ok(!defined($_[0]), "is_undef()"); } sub is_dying { @_ == 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 { $code->(); }; my $except = $@; chomp $except; $tb->ok(!$except, "$name not_dying()") or diag($except); } my @bigary = (1) x 500; sub func { } sub grow_stack { func(@bigary); } my $have_test_leak_trace = eval { require Test::LeakTrace; 1 }; sub leak_free_ok { while (@_) { 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"); } } } { package DieOnStringify; use overload '""' => \&stringify; 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 List-MoreUtils-XS-0.430/t/LICENSE0000644000175000017500000002613513735527360014356 0ustar snosno 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. List-MoreUtils-XS-0.430/t/inline/0000755000175000017500000000000013743757362014626 5ustar snosnoList-MoreUtils-XS-0.430/t/inline/zip6.pm0000644000175000017500000000204613735540227016045 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/insert_after.pm0000644000175000017500000000221213735543236017640 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/reduce_1.pm0000644000175000017500000000200613735543236016643 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/false.pm0000644000175000017500000000112413735543236016246 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/bremove.pm0000644000175000017500000000565113735543236016624 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/arrayify.pm0000644000175000017500000000617713735543236017017 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/bsearchidx.pm0000644000175000017500000000153413735543236017275 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/bsearch.pm0000644000175000017500000000166713735543236016577 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/qsort.pm0000644000175000017500000000064113735543236016327 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/notall_u.pm0000644000175000017500000000067613735543236017004 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/samples.pm0000644000175000017500000000170213735540227016617 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/reduce_0.pm0000644000175000017500000000165213735543236016650 0ustar snosno 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 List-MoreUtils-XS-0.430/t/inline/duplicates.pm0000644000175000017500000000670613735543236017324 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/mode.pm0000644000175000017500000003770613735543236016117 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/notall.pm0000644000175000017500000000065413735543236016454 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/lastres.pm0000644000175000017500000000076113735543236016637 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/pairwise.pm0000644000175000017500000000622613735543236017007 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/insert_after_string.pm0000644000175000017500000000163013735540226021225 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/lastidx.pm0000644000175000017500000000124313735543236016626 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/reduce_u.pm0000644000175000017500000000172013735543236016751 0ustar snosno 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 List-MoreUtils-XS-0.430/t/inline/any.pm0000644000175000017500000000122213735543236015742 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/XS.pm0000644000175000017500000000215313735540227015506 0ustar snosno 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 List-MoreUtils-XS-0.430/t/inline/lastval.pm0000644000175000017500000000100613735543236016621 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/before.pm0000644000175000017500000000067013735543236016423 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/Import.pm0000644000175000017500000000407613735540226016433 0ustar snosno 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 List-MoreUtils-XS-0.430/t/inline/firstidx.pm0000644000175000017500000000146513735543236017020 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/frequency.pm0000644000175000017500000000731113735543236017161 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/singleton.pm0000644000175000017500000000437613735543236017172 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/indexes.pm0000644000175000017500000000363013735543236016617 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/part.pm0000644000175000017500000000420113735543236016121 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/slide.pm0000644000175000017500000000041513735540227016253 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/binsert.pm0000644000175000017500000000664413735543236016636 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/onlyval.pm0000644000175000017500000000154513735543236016647 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/equal_range.pm0000644000175000017500000000221413735543236017440 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/onlyidx.pm0000644000175000017500000000151513735543236016646 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/mesh.pm0000644000175000017500000000277513735540226016121 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/firstres.pm0000644000175000017500000000077313735543236017026 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/before_incl.pm0000644000175000017500000000075613735543236017435 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/onlyres.pm0000644000175000017500000000160413735543236016652 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/lower_bound.pm0000644000175000017500000000313513735543236017477 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/uniq.pm0000644000175000017500000000350213735543236016132 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/true.pm0000644000175000017500000000111413735543236016132 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/upper_bound.pm0000644000175000017500000000313513735543236017502 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/natatime.pm0000644000175000017500000000111013735543236016751 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/listcmp.pm0000644000175000017500000000632713735543236016641 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/one.pm0000644000175000017500000000076313735543236015745 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/slideatatime.pm0000644000175000017500000000247213735543236017630 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/occurrences.pm0000644000175000017500000000650713735543236017501 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/minmaxstr.pm0000644000175000017500000000166413735564553017214 0ustar snosnouse 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; List-MoreUtils-XS-0.430/t/inline/none.pm0000644000175000017500000000063013735543236016114 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/minmax.pm0000644000175000017500000000400113735543236016442 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/none_u.pm0000644000175000017500000000065313735543236016445 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/firstval.pm0000644000175000017500000000102113735543236017002 0ustar snosnoBEGIN { $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; List-MoreUtils-XS-0.430/t/inline/any_u.pm0000644000175000017500000000125413735543236016273 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/one_u.pm0000644000175000017500000000100513735543236016257 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/all.pm0000644000175000017500000000061113735543236015724 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/after_incl.pm0000644000175000017500000000075513735543236017273 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/all_u.pm0000644000175000017500000000063413735543236016255 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/each_array.pm0000644000175000017500000000614713735543236017264 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/apply.pm0000644000175000017500000000322713735543236016307 0ustar snosno 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; List-MoreUtils-XS-0.430/t/inline/after.pm0000644000175000017500000000103713735543236016260 0ustar snosno 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; List-MoreUtils-XS-0.430/t/.perltidyrc0000644000175000017500000000017413735527360015526 0ustar snosno-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 List-MoreUtils-XS-0.430/t/xs/0000755000175000017500000000000013743757362014002 5ustar snosnoList-MoreUtils-XS-0.430/t/xs/slide.t0000644000175000017500000000061013743756026015260 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/zip6.t0000644000175000017500000000224113743756026015052 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/reduce_u.t0000644000175000017500000000211313743756026015753 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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 List-MoreUtils-XS-0.430/t/xs/equal_range.t0000644000175000017500000000240713743756026016451 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/none_u.t0000644000175000017500000000104613743756026015447 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/samples.t0000644000175000017500000000207513743756026015633 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/mode.t0000644000175000017500000004010113743756026015103 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/all_u.t0000644000175000017500000000102713743756026015257 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/true.t0000644000175000017500000000130713743756026015143 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/reduce_0.t0000644000175000017500000000204513743756026015652 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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 List-MoreUtils-XS-0.430/t/xs/notall.t0000644000175000017500000000104713743756026015456 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/apply.t0000644000175000017500000000342213743756026015311 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/occurrences.t0000644000175000017500000000670213743756026016503 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/lower_bound.t0000644000175000017500000000333013743756026016501 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/one.t0000644000175000017500000000115613743756026014747 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/onlyidx.t0000644000175000017500000000171013743756026015650 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/firstres.t0000644000175000017500000000116613743756026016030 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/arrayify.t0000644000175000017500000000637213743756026016021 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/mesh.t0000644000175000017500000000317013743756026015120 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/lastres.t0000644000175000017500000000115413743756026015641 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/before_incl.t0000644000175000017500000000115113743756026016430 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/indexes.t0000644000175000017500000000402313743756026015621 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/onlyval.t0000644000175000017500000000174013743756026015651 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/minmax.t0000644000175000017500000000417413743756026015462 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/upper_bound.t0000644000175000017500000000333013743756026016504 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/reduce_1.t0000644000175000017500000000220113743756026015645 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/singleton.t0000644000175000017500000000457113743756026016174 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/one_u.t0000644000175000017500000000120013743756026015261 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/each_array.t0000644000175000017500000000634213743756026016266 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/XS.t0000644000175000017500000000234613743756026014522 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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. =cut List-MoreUtils-XS-0.430/t/xs/bsearchidx.t0000644000175000017500000000172713743756026016306 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/minmaxstr.t0000644000175000017500000000205713743756026016211 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/uniq.t0000644000175000017500000000367513743756026015152 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/duplicates.t0000644000175000017500000000710113743756026016317 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/any.t0000644000175000017500000000141513743756026014753 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/firstidx.t0000644000175000017500000000166013743756026016022 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/notall_u.t0000644000175000017500000000107113743756026015777 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/bsearch.t0000644000175000017500000000206213743756026015572 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/false.t0000644000175000017500000000131713743756026015257 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/onlyres.t0000644000175000017500000000177713743756026015672 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/part.t0000644000175000017500000000437413743756026015141 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/lastval.t0000644000175000017500000000120113743756026015623 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/lastidx.t0000644000175000017500000000143613743756026015637 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/insert_after.t0000644000175000017500000000240513743756026016651 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/all.t0000644000175000017500000000100413743756026014726 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/pairwise.t0000644000175000017500000000642113743756026016011 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/any_u.t0000644000175000017500000000144713743756026015304 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/frequency.t0000644000175000017500000000750413743756026016172 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/listcmp.t0000644000175000017500000000652213743756026015643 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/binsert.t0000644000175000017500000000703713743756026015640 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/insert_after_string.t0000644000175000017500000000202313743756026020233 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/slideatatime.t0000644000175000017500000000266513743756026016641 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/Import.t0000644000175000017500000000427113743756026015441 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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. =cut List-MoreUtils-XS-0.430/t/xs/natatime.t0000644000175000017500000000130313743756026015762 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/after.t0000644000175000017500000000123213743756026015262 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/after_incl.t0000644000175000017500000000115013743756026016266 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/firstval.t0000644000175000017500000000121413743756026016013 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/before.t0000644000175000017500000000106313743756026015425 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/none.t0000644000175000017500000000102313743756026015116 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/bremove.t0000644000175000017500000000604413743756026015626 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/t/xs/qsort.t0000644000175000017500000000103413743756026015331 0ustar snosno#!perl use strict ("subs", "vars", "refs"); use warnings ("all"); use lib ("t/lib"); use List::MoreUtils::XS (":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; List-MoreUtils-XS-0.430/GPL-10000644000175000017500000003053113735527357013612 0ustar snosno GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program 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 the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! List-MoreUtils-XS-0.430/Changes0000644000175000017500000000737613743756166014416 0ustar snosnoRevision history for Perl extension List-MoreUtils-XS 0.430 2020-10-21 - re-release 0.429_002 without further changes 0.429_002 2020-10-05 - fix parts of RT#132043: listcmp misbehave in XS implementation (thanks to Henrik Pauli for reporting) 0.429_001 2020-10-02 - fix parts of RT#123989: more $a/$b/$_ refcounting bugs since some bugs are simply reported wrong, dealing with them breaks more (including running code) than it solves. Way to heavy to feel better ... - introduce functions slide and slideatatime (wished by SCHWERN) - toolchain fixes - fix RT#133128 - LANG=nb_NO.utf8 related str tests fails (thanks, SJN for reporting and provide a reasonable fix) - fix issue#7 (Typo), thanks AMBS for reporting 0.428 2017-12-19 - release 0.427_002 without further changes 0.427_002 2017-12-14 - Update ppport.h to 3.37 for improved blead support - Fix RT#123869 - context arg to croak() reported by Zefram - fix RT#123870 - one() returns true on empty list reported by Andy Lester - pamper RT#123868 - $a/$b/$_ refcounting bugs reported by Zefram 0.427_001 2017-12-12 - Fix RT#123613 - build fails on perl >=5.27.4 with -DDEBUGGING, thanks for reporting and the suggested patch goes to Andreas Koenig and Tony Cook 0.426 2017-10-02 - release 0.425_001 as 0.426 0.425_001 2017-09-27 - Fix broken format in part (fixes issues/4, thanks Andreas Schwab for reporting and testing the fix) - Fix gcc 4.7 sequence point warning (fixes issues/5, thanks Andreas Schwab for reporting and testing the fix) - Fix incorrect padname resolving for perl > 5.21.6 (Fixes RT#122883, thanks Alexander Bluhm for reporting). - Fix compiling issue on CentOS 4 & CentOS 5 (thanks Alex Karelas for reporting and testing the fix) 0.423 2017-08-19 - Fix dealing with lists with one element on bremove/binsert. Thanks shawnlaffan for reporting this via issues#2 - add support for compilers before C99 - fix some 32-bit compiler warnings - add support for compilers without statement expression feature 0.422 2017-08-15 - Rename 'occurances' into 'occurrences' as requested in RT#122806 by Paul Howarth as a slightly late side-note in RT#91991. - Add DESCRIPTION to Pod clarifying the role of List::MoreUtils::XS - improve Makefile.PL regarding some build artifacts 0.421 2017-08-14 - correct license in META thanks to Chase Whitener (RT#122702) - fix issues with -DPERL_IMPLICIT_SYS on Windows with Strawberry-Perl 0.420_002 2017-08-03 - improve configure toolchain to use Config::AutoConf 0.315 - speed up some inner loops by hinting the expected result - fix mind screwed up issue in upper_bound and reduce elements visited in equal_range 0.420_001 2017-06-28 - fix a lot of potential memory leaks when callbacks throw exceptions - add some new functions: * qsort * binsert * bremove * listcmp * arrayify (RT#17230) * samples (RT#77562) * minmaxstr (RT#106401) * lower_bound * upper_bound * equal_range * frequencies * occurances * 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. 0.418 2017-03-29 - clarify license conditions 0.417_001 2017-03-22 - 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 List-MoreUtils-XS-0.430/Makefile.PL0000644000175000017500000001662513735527357015071 0ustar snosno#!perl use strict; use warnings; require 5.008_001; BEGIN { unless (grep { $_ eq "." } @INC) { use lib "."; } } use inc::latest 'Capture::Tiny'; use inc::latest 'Config::AutoConf'; if (inc::latest->can("write")) { inc::latest->write("inc"); for my $mod (inc::latest->loaded_modules) { inc::latest->bundle_module($mod, "inc"); } } use ExtUtils::MakeMaker; use inc::Config::AutoConf::LMU (); inc::Config::AutoConf::LMU->_set_argv(@ARGV); # XXX hack because we cannot construct for global use inc::Config::AutoConf::LMU->check_lmu_prerequisites(); inc::Config::AutoConf::LMU->write_config_h("LMUconfig.h"); if (-d "Sandbox") { eval "use Sandbox::Tumble ();"; $@ and die $@; eval "use File::Path ();"; File::Path->import; -d 't/xs' and rmtree('t/xs'); Sandbox::Tumble->tumble(qw(t)); } # Should we build the XS version? my %RUN_DEPS = ( 'XSLoader' => "0.22", ); my %BUNDLE_CONFIGURE_DEPS = ( 'inc::latest' => '0.500', '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(XS.xs); my $conflictMsg = < { 'meta-spec' => {version => 2}, resources => { homepage => 'https://metacpan.org/release/List-MoreUtils-XS', repository => { url => 'https://github.com/perl5-utils/List-MoreUtils-XS.git', web => 'https://github.com/perl5-utils/List-MoreUtils-XS', type => 'git', }, bugtracker => { web => 'https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils-XS', mailto => 'bug-List-MoreUtils-XS@rt.cpan.org', }, license => 'apache_2_0', }, prereqs => { develop => { requires => { "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, } }, configure => { requires => {%CONFIGURE_DEPS}, recommends => {%BUNDLE_CONFIGURE_DEPS}, }, build => {requires => {%BUILD_DEPS}}, test => { requires => {%TEST_DEPS}, recommends => {'Test::LeakTrace' => 0} }, runtime => { requires => {%RUN_DEPS}, }, }, }, NAME => 'List::MoreUtils::XS', ABSTRACT => 'Provide the stuff missing in List::Util in XS', VERSION_FROM => 'lib/List/MoreUtils/XS.pm', AUTHOR => [ 'Tassilo von Parseval ', 'Adam Kennedy ', 'Jens Rehsack ' ], LICENSE => 'apache_2_0', CONFIGURE_REQUIRES => \%CONFIGURE_DEPS, PREREQ_PM => \%RUN_DEPS, BUILD_REQUIRES => \%BUILD_DEPS, TEST_REQUIRES => \%TEST_DEPS, XS => {map { (my $tgt = $_) =~ s/\.xs$/\.c/; $_ => $tgt; } @XS_FILES}, MAGICXS => 1, INC => "-I.", (-d "Sandbox" ? (realclean => {FILES => "inc/latest* inc/inc_* t/xs config.log LMUconfig.h M*.bak"}) : ()), depend => {'$(FIRST_MAKEFILE)' => '$(VERSION_FROM)'}, test => {TESTS => join(' ', 't/*.t', 't/xs/*.t', 'xt/*.t')}, # Otherwise 'cxinc' isn't defined ($] < 5.012 ? (DEFINE => '-DPERL_EXT') : (),), ); sub CheckConflicts { my %params = @_; my %conflicts = %{$params{CONFLICTS}}; my $found = 0; while (my ($module, $version) = each(%conflicts)) { undef $@; eval "require $module"; next if $@; my $installed = eval "\$" . $module . "::VERSION"; if ($installed le $version) { ++$found; my $warning = (0 == index($module, $params{NAME}, 0)) ? sprintf($selfConflictMsg, $params{NAME}, $module, $installed) : sprintf($conflictMsg, $params{NAME}, $module, $installed, $params{NAME}); warn $warning; } } 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})); $params{TEST_REQUIRES} and $eumm_version < 6.6303 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}}}; 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); # more or less taken from Moose' Makefile.PL if ($params{CONFLICTS}) { my $ok = CheckConflicts(%params); 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}) { sleep 4 unless ($ok); } delete $params{CONFLICTS}; } WriteMakefile(%params); } List-MoreUtils-XS-0.430/XS.xs0000644000175000017500000020716613736625102014013 0ustar snosno/** * List::MoreUtils::XS * Copyright 2004 - 2010 by by Tassilo von Parseval * 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. */ #include "LMUconfig.h" #ifdef HAVE_TIME_H # include #endif #ifdef HAVE_SYS_TIME_H # include #endif #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "multicall.h" #define NEED_gv_fetchpvn_flags #include "ppport.h" #ifndef MAX # define MAX(a,b) ((a)>(b)?(a):(b)) #endif #ifndef MIN # define MIN(a,b) (((a)<(b))?(a):(b)) #endif #ifndef aTHX # define aTHX # define pTHX #endif #ifndef croak_xs_usage # ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE # define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params) # endif static void S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params) { const GV *const gv = CvGV(cv); PERL_ARGS_ASSERT_CROAK_XS_USAGE; if (gv) { const char *const gvname = GvNAME(gv); const HV *const stash = GvSTASH(gv); const char *const hvname = stash ? HvNAME(stash) : NULL; if (hvname) Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params); else Perl_croak_nocontext("Usage: %s(%s)", gvname, params); } else { /* Pants. I don't think that it should be possible to get here. */ Perl_croak_nocontext("Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params); } } # define croak_xs_usage(a,b) S_croak_xs_usage(aTHX_ a,b) #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 #ifndef SvTEMP_off # define SvTEMP_off(a) (a) #endif /* * Perl < 5.18 had some kind of different SvIV_please_nomg */ #if PERL_VERSION_LE(5,18,0) #undef SvIV_please_nomg # define SvIV_please_nomg(sv) \ (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv)) \ ? (SvIV_nomg(sv), SvIOK(sv)) \ : SvIOK(sv)) #endif #ifndef MUTABLE_GV # define MUTABLE_GV(a) (GV *)(a) #endif #if !defined(HAS_BUILTIN_EXPECT) && defined(HAVE_BUILTIN_EXPECT) # ifdef LIKELY # undef LIKELY # endif # ifdef UNLIKELY # undef UNLIKELY # endif # define LIKELY(x) __builtin_expect(!!(x), 1) # define UNLIKELY(x) __builtin_expect(!!(x), 0) #endif #ifndef LIKELY # define LIKELY(x) (x) #endif #ifndef UNLIKELY # define UNLIKELY(x) (x) #endif #ifndef GV_NOTQUAL # define GV_NOTQUAL 0 #endif #ifdef _MSC_VER # define inline __inline #endif #ifndef HAVE_SIZE_T # if SIZEOF_PTR == SIZEOF_LONG_LONG typedef unsigned long long size_t; # elif SIZEOF_PTR == SIZEOF_LONG typedef unsigned long size_t; # elif SIZEOF_PTR == SIZEOF_INT typedef unsigned int size_t; # else # error "Can't determine type for size_t" # endif #endif #ifndef HAVE_SSIZE_T # if SIZEOF_PTR == SIZEOF_LONG_LONG typedef signed long long ssize_t; # elif SIZEOF_PTR == SIZEOF_LONG typedef signed long ssize_t; # elif SIZEOF_PTR == SIZEOF_INT typedef signed int ssize_t; # else # error "Can't determine type for ssize_t" # endif #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; return ((UV)leftiv > SvUVX(right)) - ((UV)leftiv < SvUVX(right)); } if (SvUOK(right)) { /* ## UV <=> UV ## */ const UV leftuv = SvUVX(left); const UV rightuv = SvUVX(right); return (leftuv > rightuv) - (leftuv < rightuv); } /* ## UV <=> IV ## */ if (SvIVX(right) < 0) /* As (a) is a UV, it's >=0, so it cannot be < */ return 1; return (SvUVX(left) > SvUVX(right)) - (SvUVX(left) < SvUVX(right)); } 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_LE(5,8,0) typedef AV PADLIST; typedef AV PAD; # endif # define PadlistARRAY(pl) ((PAD **)AvARRAY(pl)) # define PadlistMAX(pl) av_len(pl) # define PadlistNAMES(pl) (*PadlistARRAY(pl)) # define PadnamelistARRAY(pnl) ((PADNAME **)AvARRAY(pnl)) # define PadnamelistMAX(pnl) av_len(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 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); 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 PERL_VERSION_LT(5,21,7) if (!SvOK(name_sv)) continue; #endif if (strEQ(name_str, "$a") || strEQ(name_str, "$b")) return 1; } } } return 0; } #define ASSERT_PL_defgv \ if(UNLIKELY(!GvSV(PL_defgv))) \ croak("panic: *_ disappeared"); #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::XS_ea", TRUE); \ CV *closure = newXS(NULL, XS_List__MoreUtils__XS__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(UNLIKELY(!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 dMULTICALLSVCV \ HV *stash; \ GV *gv; \ I32 gimme = G_SCALAR; \ CV *mc_cv = sv_2cv(code, &stash, &gv, 0) #define FOR_EACH(on_item) \ if(!codelike(code)) \ croak_xs_usage(cv, "code, ..."); \ \ if (items > 1) { \ dMULTICALL; \ dMULTICALLSVCV; \ int i; \ SV **args = &PL_stack_base[ax]; \ PUSH_MULTICALL(mc_cv); \ SAVESPTR(GvSV(PL_defgv)); \ \ for(i = 1 ; i < items ; ++i) { \ SV *def_sv; \ ASSERT_PL_defgv \ def_sv = GvSV(PL_defgv) = args[i]; \ SvTEMP_off(def_sv); \ 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; #define ROF_EACH(on_item) \ if(!codelike(code)) \ croak_xs_usage(cv, "code, ..."); \ \ if (items > 1) { \ dMULTICALL; \ dMULTICALLSVCV; \ int i; \ SV **args = &PL_stack_base[ax]; \ PUSH_MULTICALL(mc_cv); \ SAVESPTR(GvSV(PL_defgv)); \ \ for(i = items-1; i > 0; --i) { \ SV *def_sv; \ ASSERT_PL_defgv \ def_sv = GvSV(PL_defgv) = args[i]; \ SvTEMP_off(def_sv); \ MULTICALL; \ on_item; \ } \ POP_MULTICALL; \ } #define REDUCE_WITH(init) \ dMULTICALL; \ dMULTICALLSVCV; \ SV *rc, **args = &PL_stack_base[ax]; \ IV i; \ \ if(!codelike(code)) \ croak_xs_usage(cv, "code, list, list"); \ \ if (in_pad(aTHX_ code)) { \ croak("Can't use lexical $a or $b in pairwise code block"); \ } \ \ rc = (init); \ sv_2mortal(newRV_noinc(rc)); \ \ PUSH_MULTICALL(mc_cv); \ SAVESPTR(GvSV(PL_defgv)); \ \ /* Following code is stolen on request of */ \ /* Zefram from pp_sort.c of perl core 16ada23 */ \ /* I have no idea why it's necessary and there */\ /* is no reasonable documentation regarding */ \ /* deal with localized $a/$b/$_ */ \ SAVEGENERICSV(PL_firstgv); \ SAVEGENERICSV(PL_secondgv); \ PL_firstgv = MUTABLE_GV(SvREFCNT_inc( \ gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV) \ )); \ PL_secondgv = MUTABLE_GV(SvREFCNT_inc( \ gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV) \ )); \ save_gp(PL_firstgv, 0); save_gp(PL_secondgv, 0); \ GvINTRO_off(PL_firstgv); \ GvINTRO_off(PL_secondgv); \ SAVEGENERICSV(GvSV(PL_firstgv)); \ SvREFCNT_inc(GvSV(PL_firstgv)); \ SAVEGENERICSV(GvSV(PL_secondgv)); \ SvREFCNT_inc(GvSV(PL_secondgv)); \ \ for (i = 1; i < items; ++i) \ { \ SV *olda, *oldb; \ sv_setiv(GvSV(PL_defgv), i-1); \ \ olda = GvSV(PL_firstgv); \ oldb = GvSV(PL_secondgv); \ GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(rc); \ GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(args[i]); \ SvREFCNT_dec(olda); \ SvREFCNT_dec(oldb); \ MULTICALL; \ \ SvSetMagicSV(rc, *PL_stack_sp); \ } \ \ POP_MULTICALL; \ \ EXTEND(SP, 1); \ ST(0) = sv_2mortal(newSVsv(rc)); \ XSRETURN(1) #define COUNT_ARGS \ 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) { \ 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]; \ } \ } #define COUNT_ARGS_MAX \ do { \ 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) { \ args[count++] = args[i]; \ hv_store_ent(hv, tmp, newSViv(1), 0); \ } \ else { \ SV *v = HeVAL(he); \ IV how_many = SvIVX(v); \ if(UNLIKELY(max < ++how_many)) \ max = how_many; \ sv_setiv(v, how_many); \ } \ } \ else if(0 == seen_undef++) { \ args[count++] = args[i]; \ } \ } \ if(UNLIKELY(max < seen_undef)) max = seen_undef; \ } while(0) /* 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 and slideatatime_args */ typedef struct { SV **svs; int nsvs; int curidx; int window; int move; } slideatatime_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; } 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) static void LMUav2flat(pTHX_ AV *tgt, AV *args) { I32 k = 0, j = av_len(args) + 1; av_extend(tgt, AvFILLp(tgt) + j); while( --j >= 0 ) { SV *sv = *av_fetch(args, k++, FALSE); if(arraylike(sv)) { AV *av = (AV *)SvRV(sv); LMUav2flat(aTHX_ tgt, av); } else { // av_push(tgt, newSVsv(sv)); av_push(tgt, SvREFCNT_inc(sv)); } } } /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * FreeBSD's Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". * Modified for using Perl Sub (no XSUB) via MULTICALL and all values are SV ** */ static inline void swapfunc(SV **a, SV **b, size_t n) { SV **pa = a; SV **pb = b; while(n-- > 0) { SV *t = *pa; *pa++ = *pb; *pb++ = t; } } #define swap(a, b) \ do { \ SV *t = *(a); \ *(a) = *(b); \ *(b) = t; \ } while(0) #define vecswap(a, b, n) \ if ((n) > 0) swapfunc(a, b, n) #if HAVE_FEATURE_STATEMENT_EXPRESSION # define CMP(x, y) ({ \ SV *olda, *oldb; \ olda = GvSV(PL_firstgv); \ oldb = GvSV(PL_secondgv); \ GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(*(x)); \ GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(*(y)); \ SvREFCNT_dec(olda); \ SvREFCNT_dec(oldb); \ \ MULTICALL; \ SvIV(*PL_stack_sp); \ }) #else static inline int _cmpsvs(pTHX_ SV *x, SV *y, OP *multicall_cop ) { SV *olda, *oldb; olda = GvSV(PL_firstgv); oldb = GvSV(PL_secondgv); GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(x); GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(y); SvREFCNT_dec(olda); SvREFCNT_dec(oldb); MULTICALL; return SvIV(*PL_stack_sp); } # define CMP(x, y) _cmpsvs(aTHX_ *(x), *(y), multicall_cop) #endif #define MED3(a, b, c) ( \ CMP(a, b) < 0 ? \ (CMP(b, c) < 0 ? b : (CMP(a, c) < 0 ? c : a )) \ :(CMP(b, c) > 0 ? b : (CMP(a, c) < 0 ? a : c )) \ ) static void bsd_qsort_r(pTHX_ SV **ary, size_t nelem, OP *multicall_cop) { SV **pa, **pb, **pc, **pd, **pl, **pm, **pn; size_t d1, d2; int cmp_result, swap_cnt = 0; loop: if (nelem < 7) { for (pm = ary + 1; pm < ary + nelem; ++pm) for (pl = pm; pl > ary && CMP(pl - 1, pl) > 0; pl -= 1) swap(pl, pl - 1); return; } pm = ary + (nelem / 2); if (nelem > 7) { pl = ary; pn = ary + (nelem - 1); if (nelem > 40) { size_t d = (nelem / 8); pl = MED3(pl, pl + d, pl + 2 * d); pm = MED3(pm - d, pm, pm + d); pn = MED3(pn - 2 * d, pn - d, pn); } pm = MED3(pl, pm, pn); } swap(ary, pm); pa = pb = ary + 1; pc = pd = ary + (nelem - 1); for (;;) { while (pb <= pc && (cmp_result = CMP(pb, ary)) <= 0) { if (cmp_result == 0) { swap_cnt = 1; swap(pa, pb); pa += 1; } pb += 1; } while (pb <= pc && (cmp_result = CMP(pc, ary)) >= 0) { if (cmp_result == 0) { swap_cnt = 1; swap(pc, pd); pd -= 1; } pc -= 1; } if (pb > pc) break; swap(pb, pc); swap_cnt = 1; pb += 1; pc -= 1; } if (swap_cnt == 0) { /* Switch to insertion sort */ for (pm = ary + 1; pm < ary + nelem; pm += 1) for (pl = pm; pl > ary && CMP(pl - 1, pl) > 0; pl -= 1) swap(pl, pl - 1); return; } pn = ary + nelem; d1 = MIN(pa - ary, pb - pa); vecswap(ary, pb - d1, d1); d1 = MIN(pd - pc, pn - pd - 1); vecswap(pb, pn - d1, d1); d1 = pb - pa; d2 = pd - pc; if (d1 <= d2) { /* Recurse on left partition, then iterate on right partition */ if (d1 > 1) bsd_qsort_r(aTHX_ ary, d1, multicall_cop); if (d2 > 1) { /* Iterate rather than recurse to save stack space */ /* qsort(pn - d2, d2, multicall_cop); */ ary = pn - d2; nelem = d2; goto loop; } } else { /* Recurse on right partition, then iterate on left partition */ if (d2 > 1) bsd_qsort_r(aTHX_ pn - d2, d2, multicall_cop); if (d1 > 1) { /* Iterate rather than recurse to save stack space */ /* qsort(ary, d1, multicall_cop); */ nelem = d1; goto loop; } } } /* lower_bound algorithm from STL - see http://en.cppreference.com/w/cpp/algorithm/lower_bound */ #define LOWER_BOUND(at) \ while (count > 0) { \ ssize_t step = count / 2; \ ssize_t it = first + step; \ \ ASSERT_PL_defgv \ GvSV(PL_defgv) = at; \ MULTICALL; \ cmprc = SvIV(*PL_stack_sp); \ if (cmprc < 0) { \ first = ++it; \ count -= step + 1; \ } \ else \ count = step; \ } #define LOWER_BOUND_QUICK(at) \ while (count > 0) { \ ssize_t step = count / 2; \ ssize_t it = first + step; \ \ ASSERT_PL_defgv \ GvSV(PL_defgv) = at; \ MULTICALL; \ cmprc = SvIV(*PL_stack_sp); \ if(UNLIKELY(0 == cmprc)) { \ first = it; \ break; \ } \ if (cmprc < 0) { \ first = ++it; \ count -= step + 1; \ } \ else \ count = step; \ } /* upper_bound algorithm from STL - see http://en.cppreference.com/w/cpp/algorithm/upper_bound */ #define UPPER_BOUND(at) \ while (count > 0) { \ ssize_t step = count / 2; \ ssize_t it = first + step; \ \ ASSERT_PL_defgv \ GvSV(PL_defgv) = at; \ MULTICALL; \ cmprc = SvIV(*PL_stack_sp); \ if (cmprc <= 0) { \ first = ++it; \ count -= step + 1; \ } \ else \ count = step; \ } MODULE = List::MoreUtils::XS_ea PACKAGE = List::MoreUtils::XS_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::XS_sa PACKAGE = List::MoreUtils::XS_sa void DESTROY(sv) SV *sv; CODE: { int i; CV *code = (CV*)SvRV(sv); slideatatime_args *args = (slideatatime_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::XS PACKAGE = List::MoreUtils::XS 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_NO 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 } void reduce_u(code, ...) SV *code; PROTOTYPE: &@ CODE: { REDUCE_WITH(newSVsv(&PL_sv_undef)); } void reduce_0(code, ...) SV *code; PROTOTYPE: &@ CODE: { REDUCE_WITH(newSViv(0)); } void reduce_1(code, ...) SV *code; PROTOTYPE: &@ CODE: { REDUCE_WITH(newSViv(1)); } void slide(code, ...) SV *code; PROTOTYPE: &@ CODE: { if ((items <= 2) || (!codelike(code))) croak_xs_usage(cv, "code, item1, item2, ..."); else { /* keep original stack a bit smaller ... */ dMULTICALL; dMULTICALLSVCV; ssize_t i; SV **args = &PL_stack_base[ax]; AV *rc = newAV(); sv_2mortal(newRV_noinc((SV*)rc)); av_extend(rc, items-2); PUSH_MULTICALL(mc_cv); SAVEGENERICSV(PL_firstgv); SAVEGENERICSV(PL_secondgv); PL_firstgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV) )); PL_secondgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV) )); /* make sure the GP isn't removed out from under us for * the SAVESPTR() */ save_gp(PL_firstgv, 0); save_gp(PL_secondgv, 0); /* we don't want modifications localized */ GvINTRO_off(PL_firstgv); GvINTRO_off(PL_secondgv); SAVEGENERICSV(GvSV(PL_firstgv)); SvREFCNT_inc(GvSV(PL_firstgv)); SAVEGENERICSV(GvSV(PL_secondgv)); SvREFCNT_inc(GvSV(PL_secondgv)); for(i = 1 ; i < items - 1; ++i) { SV *olda, *oldb; olda = GvSV(PL_firstgv); oldb = GvSV(PL_secondgv); GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(args[i]); GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(args[i+1]); SvREFCNT_dec(olda); SvREFCNT_dec(oldb); MULTICALL; av_push(rc, newSVsv(*PL_stack_sp)); } POP_MULTICALL; for(i = av_len(rc); i >= 0; --i) { ST(i) = sv_2mortal(AvARRAY(rc)[i]); AvARRAY(rc)[i] = NULL; } AvFILLp(rc) = -1; } XSRETURN(items-2); } void _slideatatime_iterator () PROTOTYPE: CODE: { int i; /* 'cv' is the hidden argument with which XS_List__MoreUtils__XS__slideatatime_iterator (this XSUB) * is called. The closure_arg struct is stored in this CV. */ slideatatime_args *args = (slideatatime_args*)CvXSUBANY(cv).any_ptr; EXTEND(SP, args->window); for (i = 0; i < args->window; i++) if ((args->curidx + i) < args->nsvs) ST(i) = sv_2mortal(newSVsv(args->svs[args->curidx + i])); else break; args->curidx += args->move; XSRETURN(i); } SV * slideatatime (move, window, ...) int move; int window; PROTOTYPE: $@ CODE: { int i; slideatatime_args *args; HV *stash = gv_stashpv("List::MoreUtils::XS_sa", TRUE); CV *closure = newXS(NULL, XS_List__MoreUtils__XS__slideatatime_iterator, __FILE__); /* must NOT set prototype on iterator: * otherwise one cannot write: &$it */ /* !! sv_setpv((SV*)closure, ""); !! */ New(0, args, 1, slideatatime_args); New(0, args->svs, items-2, SV*); args->nsvs = items-2; args->curidx = 0; args->move = move; args->window = window; for (i = 2; i < items; i++) SvREFCNT_inc(args->svs[i-2] = 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 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: { RETVAL = -1; ROF_EACH(if (SvTRUE(*PL_stack_sp)){RETVAL = i-1;break;}) } OUTPUT: RETVAL SV * lastval (code, ...) SV *code; PROTOTYPE: &@ CODE: { RETVAL = &PL_sv_undef; ROF_EACH(if (SvTRUE(*PL_stack_sp)) { /* see comment in indexes() */ SvREFCNT_inc(RETVAL = args[i]); break; }); } OUTPUT: RETVAL SV * lastres (code, ...) SV *code; PROTOTYPE: &@ CODE: { RETVAL = &PL_sv_undef; ROF_EACH(if (SvTRUE(*PL_stack_sp)) { SvREFCNT_inc(RETVAL = *PL_stack_sp); break; }); } OUTPUT: RETVAL int insert_after (code, val, avref) SV *code; SV *val; SV *avref; PROTOTYPE: &$\@ CODE: { dMULTICALL; dMULTICALLSVCV; int i; int len; 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; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); for (i = 0; i <= len ; ++i) { ASSERT_PL_defgv 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, len; AV *av; RETVAL = 0; if(!arraylike(avref)) croak_xs_usage(cv, "string, val, \\@area_of_operation"); av = (AV*)SvRV(avref); len = av_len(av); for (i = 0; i <= len ; i++) { SV **sv = av_fetch(av, i, FALSE); if((SvFLAGS(*sv) & (SVf_OK & ~SVf_ROK)) && (0 == sv_cmp_locale(string, *sv))) { RETVAL = 1; break; } } if (RETVAL) { SvREFCNT_inc(val); insert_after(aTHX_ i, val, av); } } OUTPUT: RETVAL void apply (code, ...) SV *code; PROTOTYPE: &@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; int i; SV **args = &PL_stack_base[ax]; AV *rc = newAV(); sv_2mortal(newRV_noinc((SV*)rc)); av_extend(rc, items-1); PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); for(i = 1 ; i < items ; ++i) { av_push(rc, newSVsv(args[i])); GvSV(PL_defgv) = AvARRAY(rc)[AvFILLp(rc)]; MULTICALL; } POP_MULTICALL; for(i = items - 1; i > 0; --i) { ST(i-1) = sv_2mortal(AvARRAY(rc)[i-1]); AvARRAY(rc)[i-1] = NULL; } AvFILLp(rc) = -1; } XSRETURN(items-1); } void after (code, ...) SV *code; PROTOTYPE: &@ CODE: { int k = items, j; FOR_EACH(if (SvTRUE(*PL_stack_sp)) {k=i; break;}); for (j = k + 1; j < items; ++j) ST(j-k-1) = ST(j); j = items-k-1; XSRETURN(j > 0 ? j : 0); } void after_incl (code, ...) SV *code; PROTOTYPE: &@ CODE: { int k = items, j; FOR_EACH(if (SvTRUE(*PL_stack_sp)) {k=i; break;}); for (j = k; j < items; j++) ST(j-k) = ST(j); XSRETURN(items-k); } void before (code, ...) SV *code; PROTOTYPE: &@ CODE: { int k = items - 1; FOR_EACH(if (SvTRUE(*PL_stack_sp)) {k=i-1; break;}; args[i-1] = args[i];); XSRETURN(k); } void before_incl (code, ...) SV *code; PROTOTYPE: &@ CODE: { int k = items - 1; FOR_EACH(args[i-1] = args[i]; if (SvTRUE(*PL_stack_sp)) {k=i; break;}); XSRETURN(k); } void indexes (code, ...) SV *code; PROTOTYPE: &@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; int i; SV **args = &PL_stack_base[ax]; AV *rc = newAV(); sv_2mortal(newRV_noinc((SV*)rc)); av_extend(rc, items-1); PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); for(i = 1 ; i < items ; ++i) { GvSV(PL_defgv) = args[i]; MULTICALL; if (SvTRUE(*PL_stack_sp)) av_push(rc, newSViv(i-1)); } POP_MULTICALL; for(i = av_len(rc); i >= 0; --i) { ST(i) = sv_2mortal(AvARRAY(rc)[i]); AvARRAY(rc)[i] = NULL; } i = AvFILLp(rc) + 1; AvFILLp(rc) = -1; XSRETURN(i); } XSRETURN_EMPTY; } 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 void pairwise (code, list1, list2) SV *code; AV *list1; AV *list2; PROTOTYPE: &\@\@ PPCODE: { dMULTICALL; dMULTICALLSVCV; int i, maxitems; AV *rc = newAV(); sv_2mortal(newRV_noinc((SV*)rc)); if(!codelike(code)) 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 */ maxitems = MAX(av_len(list1),av_len(list2))+1; av_extend(rc, maxitems); gimme = G_ARRAY; PUSH_MULTICALL(mc_cv); SAVEGENERICSV(PL_firstgv); SAVEGENERICSV(PL_secondgv); PL_firstgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV) )); PL_secondgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV) )); /* make sure the GP isn't removed out from under us for * the SAVESPTR() */ save_gp(PL_firstgv, 0); save_gp(PL_secondgv, 0); /* we don't want modifications localized */ GvINTRO_off(PL_firstgv); GvINTRO_off(PL_secondgv); SAVEGENERICSV(GvSV(PL_firstgv)); SvREFCNT_inc(GvSV(PL_firstgv)); SAVEGENERICSV(GvSV(PL_secondgv)); SvREFCNT_inc(GvSV(PL_secondgv)); for (i = 0; i < maxitems; ++i) { SV **j; SV *olda = GvSV(PL_firstgv), *oldb = GvSV(PL_secondgv); SV **svp = av_fetch(list1, i, FALSE); GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(svp ? *svp : &PL_sv_undef); svp = av_fetch(list2, i, FALSE); GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(svp ? *svp : &PL_sv_undef); SvREFCNT_dec(olda); SvREFCNT_dec(oldb); MULTICALL; for (j = PL_stack_base+1; j <= PL_stack_sp; ++j) av_push(rc, newSVsv(*j)); } POP_MULTICALL; SPAGAIN; EXTEND(SP, AvFILLp(rc) + 1); for(i = AvFILLp(rc); i >= 0; --i) { ST(i) = sv_2mortal(AvARRAY(rc)[i]); AvARRAY(rc)[i] = NULL; } i = AvFILLp(rc) + 1; AvFILLp(rc) = -1; XSRETURN(i); } SV * natatime (n, ...) int n; PROTOTYPE: $@ CODE: { int i; slideatatime_args *args; HV *stash = gv_stashpv("List::MoreUtils::XS_sa", TRUE); CV *closure = newXS(NULL, XS_List__MoreUtils__XS__slideatatime_iterator, __FILE__); /* must NOT set prototype on iterator: * otherwise one cannot write: &$it */ /* !! sv_setpv((SV*)closure, ""); !! */ New(0, args, 1, slideatatime_args); New(0, args->svs, items-1, SV*); args->nsvs = items-1; args->curidx = 0; args->move = n; args->window = 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 arrayify(...) CODE: { I32 i; AV *rc = newAV(); AV *args = av_make(items, &PL_stack_base[ax]); sv_2mortal(newRV_noinc((SV *)rc)); sv_2mortal(newRV_noinc((SV *)args)); LMUav2flat(aTHX_ rc, args); i = AvFILLp(rc); EXTEND(SP, i+1); for(; i >= 0; --i) { ST(i) = sv_2mortal(AvARRAY(rc)[i]); AvARRAY(rc)[i] = NULL; } i = AvFILLp(rc) + 1; AvFILLp(rc) = -1; XSRETURN(i); } 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 zip6 (...) PROTOTYPE: \@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ CODE: { int i, j, maxidx = -1; AV **src; New(0, src, items, AV*); for (i = 0; i < items; i++) { if(!arraylike(ST(i))) croak_xs_usage(cv, "\\@\\@;\\@..."); src[i] = (AV*)SvRV(ST(i)); if (av_len(src[i]) > maxidx) maxidx = av_len(src[i]); } EXTEND(SP, maxidx + 1); for (i = 0; i <= maxidx; i++) { AV *av; ST(i) = sv_2mortal(newRV_noinc((SV *)(av = newAV()))); for (j = 0; j < items; j++) { SV **svp = av_fetch(src[j], i, FALSE); av_push(av, newSVsv( svp ? *svp : &PL_sv_undef )); } } Safefree(src); XSRETURN(maxidx + 1); } void listcmp (...) PROTOTYPE: \@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@ CODE: { I32 i; SV *tmp = sv_newmortal(); HV *rc = newHV(); SV *ret = sv_2mortal (newRV_noinc((SV *)rc)); HV *distinct = newHV(); sv_2mortal(newRV_noinc((SV*)distinct)); for (i = 0; i < items; i++) { AV *av; I32 j; if(!arraylike(ST(i))) croak_xs_usage(cv, "\\@\\@;\\@..."); av = (AV*)SvRV(ST(i)); hv_clear(distinct); for(j = 0; j <= av_len(av); ++j) { SV **sv = av_fetch(av, j, FALSE); AV *store; if(NULL == sv) continue; SvGETMAGIC(*sv); if(SvOK(*sv)) { SvSetSV_nosteal(tmp, *sv); if(hv_exists_ent(distinct, tmp, 0)) continue; hv_store_ent(distinct, tmp, &PL_sv_yes, 0); if(hv_exists_ent(rc, *sv, 0)) { HE *he = hv_fetch_ent(rc, *sv, 1, 0); store = (AV*)SvRV(HeVAL(he)); av_push(store, newSViv(i)); } else { store = newAV(); av_push(store, newSViv(i)); hv_store_ent(rc, tmp, newRV_noinc((SV *)store), 0); } } } } i = HvUSEDKEYS(rc); if (GIMME_V == G_SCALAR) { ST(0) = sv_2mortal(newSVuv(i)); XSRETURN(1); } else { EXTEND(SP, i * 2); i = 0; hv_iterinit(rc); for(;;) { HE *he = hv_iternext(rc); SV *key, *val; if(NULL == he) break; if(UNLIKELY(( NULL == (key = HeSVKEY_force(he)) ) || ( NULL == (val = HeVAL(he)) ))) continue; ST(i++) = key; ST(i++) = val; } XSRETURN(i); } } 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)); COUNT_ARGS /* 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) if( 1 == SvIVX(HeVAL(he)) ) ++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) if( 1 == SvIVX(HeVAL(he)) ) args[cnt++] = args[i]; } else if(1 == seen_undef) args[cnt++] = args[i]; } XSRETURN(cnt); } void duplicates (...) 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)); COUNT_ARGS /* 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) if( 1 < SvIVX(HeVAL(he)) ) ++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) if( 1 < SvIVX(HeVAL(he)) ) args[cnt++] = args[i]; } else if(1 < seen_undef) { args[cnt++] = args[i]; } } XSRETURN(cnt); } void frequency (...) 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)); COUNT_ARGS i = HvUSEDKEYS(hv); if(seen_undef) ++i; /* don't build return list in scalar context */ if (GIMME_V == G_SCALAR) { ST(0) = sv_2mortal(newSViv(i)); XSRETURN(1); } EXTEND(SP, i * 2); i = 0; hv_iterinit(hv); for(;;) { HE *he = hv_iternext(hv); SV *key, *val; if(NULL == he) break; if(UNLIKELY(( NULL == (key = HeSVKEY_force(he)) ) || ( NULL == (val = HeVAL(he)) ))) continue; ST(i++) = key; ST(i++) = val; } if(seen_undef) { ST(i++) = sv_2mortal(newRV(newSVsv(&PL_sv_undef))); ST(i++) = sv_2mortal(newSViv(seen_undef));; } XSRETURN(i); } void occurrences (...) PROTOTYPE: @ CODE: { I32 i; IV count = 0, seen_undef = 0, max = items > 0 ? 1 : 0; HV *hv = newHV(); SV **args = &PL_stack_base[ax]; SV *tmp = sv_newmortal(); sv_2mortal(newRV_noinc((SV*)hv)); COUNT_ARGS_MAX; /* don't build return list in scalar context */ if (GIMME_V == G_SCALAR) { ST(0) = sv_2mortal(newSViv(i)); XSRETURN(1); } EXTEND(SP, max + 1); for(i = 0; i <= max; ++i) ST(i) = &PL_sv_undef; hv_iterinit(hv); for(;;) { HE *he = hv_iternext(hv); SV *key, *val; AV *store; if(NULL == he) break; if(UNLIKELY(( NULL == (key = HeSVKEY_force(he)) ) || ( NULL == (val = HeVAL(he)) ))) continue; i = SvIVX(val); if(ST(i) == &PL_sv_undef) { store = newAV(); ST(i) = sv_2mortal(newRV_noinc((SV *)store)); } else store = (AV *)SvRV(ST(i)); av_push(store, newSVsv(key)); } if(seen_undef) { AV *store; if(ST(seen_undef) == &PL_sv_undef) { store = newAV(); ST(seen_undef) = sv_2mortal(newRV_noinc((SV *)store)); } else { store = (AV *)SvRV(ST(seen_undef)); } av_push(store, &PL_sv_undef); } XSRETURN(max+1); } void mode (...) PROTOTYPE: @ CODE: { I32 i; IV count = 0, seen_undef = 0, max = items > 0 ? 1 : 0; HV *hv = newHV(); SV **args = &PL_stack_base[ax]; SV *tmp = sv_newmortal(); sv_2mortal(newRV_noinc((SV*)hv)); COUNT_ARGS_MAX; EXTEND(SP, count = 1); ST(0) = sv_2mortal(newSViv(max)); /* don't build return list in scalar context */ if (GIMME_V == G_SCALAR) XSRETURN(1); hv_iterinit(hv); for(;;) { HE *he = hv_iternext(hv); SV *key, *val; if(NULL == he) break; if(UNLIKELY(( NULL == (key = HeSVKEY_force(he)) ) || ( NULL == (val = HeVAL(he)) ))) continue; i = SvIVX(val); if(max == i) { ++count; EXTEND(SP, count); ST(count-1) = sv_mortalcopy(key); } } if(seen_undef == max) { ++count; EXTEND(SP, count); ST(count-1) = &PL_sv_undef; } XSRETURN(count); } void samples (k, ...) I32 k; PROTOTYPE: $@ CODE: { I32 i; if( k > (items - 1) ) croak("Cannot get %" IVdf " samples from %" IVdf " elements", (IV)k, (IV)(items-1)); /* Initialize Drand01 unless rand() or srand() has already been called */ if(!PL_srand_called) { #ifdef HAVE_TIME /* using time(NULL) as seed seems to get better random numbers ... */ (void)seedDrand01((Rand_seed_t)time(NULL)); #else (void)seedDrand01((Rand_seed_t)Perl_seed(aTHX)); #endif PL_srand_called = TRUE; } /* optimzed Knuth-Shuffle since we move our stack one item downwards with each exchange */ for (i = items ; items - i < k ; ) { I32 index = items - i + 1; I32 swap = index + (I32)(Drand01() * (double)(--i)); ST(index-1) = ST(swap); ST(swap) = ST(index); } XSRETURN(k); } 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 minmaxstr (...) 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 = sv_cmp_locale(asv, bsv); if (cmp < 0) { int min_cmp = sv_cmp_locale(minsv, asv); int max_cmp = sv_cmp_locale(maxsv, bsv); if (min_cmp > 0) minsv = asv; if (max_cmp < 0) maxsv = bsv; } else { int min_cmp = sv_cmp_locale(minsv, bsv); int max_cmp = sv_cmp_locale(maxsv, asv); if (min_cmp > 0) minsv = bsv; if (max_cmp < 0) maxsv = asv; } } if (items & 1) { SV *rsv = ST(items-1); if (sv_cmp_locale(minsv, rsv) > 0) minsv = rsv; else if (sv_cmp_locale(maxsv, rsv) < 0) maxsv = rsv; } ST(0) = minsv; ST(1) = maxsv; XSRETURN(2); } void part (code, ...) SV *code; PROTOTYPE: &@ CODE: { dMULTICALL; dMULTICALLSVCV; int i; SV **args = &PL_stack_base[ax]; AV *tmp = newAV(); sv_2mortal(newRV_noinc((SV*)tmp)); if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items == 1) XSRETURN_EMPTY; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); for(i = 1 ; i < items ; ++i) { IV idx; SV **inner; AV *av; ASSERT_PL_defgv GvSV(PL_defgv) = args[i]; MULTICALL; idx = SvIV(*PL_stack_sp); if (UNLIKELY(idx < 0 && (idx += (AvFILLp(tmp)+1)) < 0)) croak("Modification of non-creatable array value attempted, subscript %" IVdf, idx); if(UNLIKELY(NULL == (inner = av_fetch(tmp, idx, FALSE)))) { av = newAV(); av_push(av, newSVsv(args[i])); av_store(tmp, idx, newRV_noinc((SV *)av)); } else { av = (AV*)SvRV(*inner); av_push(av, newSVsv(args[i])); } } POP_MULTICALL; EXTEND(SP, AvFILLp(tmp)+1); for(i = AvFILLp(tmp); i >= 0; --i) { SV *v = AvARRAY(tmp)[i]; ST(i) = v && is_array(v) ? sv_2mortal(v) : &PL_sv_undef; AvARRAY(tmp)[i] = NULL; } i = AvFILLp(tmp) + 1; AvFILLp(tmp) = -1; XSRETURN(i); } void bsearch (code, ...) SV *code; PROTOTYPE: &@ CODE: { I32 ret_gimme = GIMME_V; if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; ssize_t count = items - 1, first = 1; int cmprc = -1; SV **args = &PL_stack_base[ax]; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND_QUICK(args[it]) if(cmprc < 0 && first < items) { ASSERT_PL_defgv GvSV(PL_defgv) = args[first]; MULTICALL; cmprc = SvIV(*PL_stack_sp); } POP_MULTICALL; if(0 == cmprc) { if (ret_gimme != G_ARRAY) XSRETURN_YES; ST(0) = args[first]; XSRETURN(1); } } if(ret_gimme == G_ARRAY) XSRETURN_EMPTY; XSRETURN_UNDEF; } int bsearchidx (code, ...) SV *code; PROTOTYPE: &@ CODE: { I32 ret_gimme = GIMME_V; if(!codelike(code)) croak_xs_usage(cv, "code, ..."); RETVAL = -1; if (items > 1) { dMULTICALL; dMULTICALLSVCV; ssize_t count = items - 1, first = 1; int cmprc = -1; SV **args = &PL_stack_base[ax]; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND_QUICK(args[it]) if(cmprc < 0 && first < items) { ASSERT_PL_defgv GvSV(PL_defgv) = args[first]; MULTICALL; cmprc = SvIV(*PL_stack_sp); } POP_MULTICALL; if(0 == cmprc) RETVAL = --first; } } OUTPUT: RETVAL int lower_bound (code, ...) SV *code; PROTOTYPE: &@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; ssize_t count = items - 1, first = 1; int cmprc = -1; SV **args = &PL_stack_base[ax]; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND(args[it]) POP_MULTICALL; RETVAL = --first; } else RETVAL = -1; } OUTPUT: RETVAL int upper_bound (code, ...) SV *code; PROTOTYPE: &@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; ssize_t count = items - 1, first = 1; int cmprc = -1; SV **args = &PL_stack_base[ax]; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); UPPER_BOUND(args[it]) POP_MULTICALL; RETVAL = --first; } else RETVAL = -1; } OUTPUT: RETVAL void equal_range (code, ...) SV *code; PROTOTYPE: &@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (items > 1) { dMULTICALL; dMULTICALLSVCV; ssize_t count = items - 1, first = 1; ssize_t lb; int cmprc = -1; SV **args = &PL_stack_base[ax]; PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND(args[it]) lb = first - 1; count = items - first; UPPER_BOUND(args[it]) POP_MULTICALL; EXTEND(SP, 2); ST(0) = sv_2mortal(newSViv(lb)); ST(1) = sv_2mortal(newSViv(first - 1)); XSRETURN(2); } XSRETURN_EMPTY; } int binsert(code, item, list) SV *code; SV *item; AV *list; PROTOTYPE: &$\@ CODE: { if(!codelike(code)) croak_xs_usage(cv, "code, val, list"); RETVAL = -1; if (AvFILLp(list) == -1) { av_push(list, newSVsv(item)); RETVAL = 0; } else if (AvFILLp(list) >= 0) { dMULTICALL; dMULTICALLSVCV; ssize_t count = AvFILLp(list) + 1, first = 0; int cmprc = -1; SV **btree = AvARRAY(list); PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND(btree[it]) POP_MULTICALL; SvREFCNT_inc(item); insert_after(aTHX_ (RETVAL = first) - 1, item, list); } } OUTPUT: RETVAL void bremove(code, list) SV *code; AV *list; PROTOTYPE: &\@ CODE: { I32 ret_gimme = GIMME_V; if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (AvFILLp(list) >= 0) { dMULTICALL; dMULTICALLSVCV; ssize_t count = AvFILLp(list) + 1, first = 0; int cmprc = -1; SV **btree = AvARRAY(list); PUSH_MULTICALL(mc_cv); SAVESPTR(GvSV(PL_defgv)); LOWER_BOUND_QUICK(btree[it]) if(cmprc < 0 && first < items) { ASSERT_PL_defgv GvSV(PL_defgv) = btree[first]; MULTICALL; cmprc = SvIV(*PL_stack_sp); } POP_MULTICALL; if(0 == cmprc) { if(AvFILLp(list) == first) { ST(0) = sv_2mortal(av_pop(list)); XSRETURN(1); } if(0 == first) { ST(0) = sv_2mortal(av_shift(list)); XSRETURN(1); } ST(0) = av_delete(list, first, 0); count = AvFILLp(list); while(first < count) { btree[first] = btree[first+1]; ++first; } SvREFCNT_inc(btree[count]); av_delete(list, count, G_DISCARD); #if PERL_VERSION_LE(5,8,5) sv_2mortal(ST(0)); #endif XSRETURN(1); } } if (ret_gimme == G_ARRAY) XSRETURN_EMPTY; else XSRETURN_UNDEF; } void qsort(code, list) SV *code; AV *list; PROTOTYPE: &\@ CODE: { I32 gimme = GIMME_V; /* perl-5.5.4 bus-errors out later when using GIMME therefore we save its value in a fresh variable */ dMULTICALL; if(!codelike(code)) croak_xs_usage(cv, "code, ..."); if (in_pad(aTHX_ code)) croak("Can't use lexical $a or $b in qsort's cmp code block"); if (av_len(list) > 0) { HV *stash; GV *gv; CV *_cv = sv_2cv(code, &stash, &gv, 0); PUSH_MULTICALL(_cv); SAVEGENERICSV(PL_firstgv); SAVEGENERICSV(PL_secondgv); PL_firstgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV) )); PL_secondgv = MUTABLE_GV(SvREFCNT_inc( gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV) )); /* make sure the GP isn't removed out from under us for * the SAVESPTR() */ save_gp(PL_firstgv, 0); save_gp(PL_secondgv, 0); /* we don't want modifications localized */ GvINTRO_off(PL_firstgv); GvINTRO_off(PL_secondgv); SAVEGENERICSV(GvSV(PL_firstgv)); SvREFCNT_inc(GvSV(PL_firstgv)); SAVEGENERICSV(GvSV(PL_secondgv)); SvREFCNT_inc(GvSV(PL_secondgv)); bsd_qsort_r(aTHX_ AvARRAY(list), av_len(list) + 1, multicall_cop); POP_MULTICALL; } } void _XScompiled () CODE: XSRETURN_YES;