PATCH: [perl #113750] re.pm clobbers $_

Thanks to Jesse Luehrs and Father Chrysostomos for testing advice.

(cherry-picked from commit 48895a0d16aef33c200bc9a07f22e18c23597c2a)

Conflicts:

	ext/re/re.pm
	pod/perldelta.pod
Update List-Util to CPAN version 1.25

  [DELTA]

1.25 -- Sat Mar 24 13:10:13 UTC 2012

  * Restore back-compat. to perl 5.6 (thanks to Zefram)

1.24 -- Thu Mar 22 18:10:10 UTC 2012

  * Update to 1.24 release version (no other changes since 1.23_04).

1.23_04 -- Sat Mar 10 00:16:16 UTC 2012

  * RT#72700 Fix off-by-two on string literal length

1.23_03 -- Tue Sep 14 10:09:59 CDT 2010

  * Min perl version supported for build is not 5.008
  * Dropped the pure-Perl implementation of both Scalar::- and List::Util.
  * RT#61118 Fix assumption in sum() that once magic, always magic

1.23_02 -- Tue Mar 30 11:09:15 CDT 2010

  * Fix first() and reduce() to check the callback first; &first(1) is now illigal. [gfx]
  * Fix reduce() to allow XSUB callbacks [gfx]
  * Fix first() to allow XSUB callbacks [gfx]
  * Resolve RT #55763: tainted() doesn't do SvGETMAGIC(sv) [gfx]
  * define CvISXSUB so older perl versions will still compile

1.23_01 -- Mon Mar 22 08:24:11 CDT 2010

  * Add failing tests; SVt_RV is not directly SvROK [gfx]
  * Implement openhandle() in XS (with extra tests) [gfx]
  * Modernize *.pm [gfx]
  * Modernize ListUtil.xs [gfx]
  * Add ppport.h [gfx]
  * Fix an overloading issue on sum(), and add tests for overloading [gfx]
  * Small tweaks for minstr()/maxstr() [gfx]
  * Optimize dualvar() [gfx]
  * Use sv_copypv() instead of SvPV() and sv_setpv() [gfx]
  * avoid non-portable warnings
mktables: Handle typo in Unicode 6.1 data file

Unicode has published a correction to their data files for version 6.1.
This patch applies that correction.
PATCH: [perl #113584] tr/// multiple transliterations

Commit 4de6d205aeab9ec737ca35ba4eb61f37cebefc55 failed to take into
consideration tr///.
create perl5161delta
perldelta for RT #113584

(cherry-picked from commit fc67deb3641ae65505a02c4a7414556efc6b91f6)
[perl #113764] Make &= duping work with PerlIO::scalar

In trying to fix bug #112780, I made in-memory handle duplication tem-
porarily hide the underlying scalar so it wouldn’t be set to the empty
string (commit 49b69fb3a).

I used PerlIO_sv_dup in j rather than PerlIOScalar_arg.  The for-
mer is usually what is called anyway.  There is only one branch of
PerlIOScalar_arg that doesn’t call PerlIO_sv_dup.  I don’t remember
what I was thinking back then, but I think I thought that branch
was there for paranoia.  But actually, it is used for "&=", so this
started failing:

open FILE, '>', \my $content or die "Couldn't open scalar filehandle";
open my $fh, ">&=FILE" or die "Couldn't open: $!";
print $fh "Foo-Bar\n";
close $fh;
close FILE;
print $content;

This commit fixes the bug in the smallest way possible, which means
switching from PerlIO_sv_dup to PerlIOScalar_arg in PerlIOScalar_arg,
which, in turn, entails fiddling with RVs.
version bump for PerlIO::scalar
perldelta for 88052e3fd2 (VMS include files).

(cherry picked from commit 112b686)
omnibus perldelta updates for commits cherry-picked to maint
replace B::COP::stashflags by B::COP::stashlen

6379d4a9a (between 5.15.9 and 5.16.0) broke B::COP::stashflags which was added
in 5.15.4.
[perl #113060] Save cop_stashlen threaded even with shared cop pv

Perl_sv_compile_2op_is_broken() does at line 3354 a LEAVE_with_name("eval"),
a SSPOPSTR via SAVEt_SHARED_PVREF for the localized cop_stashpv, but
not for the cop_stashlen.
The cop in question is PL_compiling, which was "AutoSplit" before with
len=9 and restores it back to "main" but keeps len 9. Thus leading to a
heap-overflow in gv_stashpvn.
Make lvalue subs copy returned PADTMPs in rvalue cx

I was trying to write a JAPH, but did not get what I expected:

$ ./perl -Ilib -e '@UNIVERSAL::ISA = CORE; print "just another "->ucfirst, "perl hacker,\n"->ucfirst'
Perl hacker,
Perl hacker,

This happened because coresubs use leavesublv, to avoid copying the
return value wastefully.

But since this is exactly the same ucfirst op being called each time
(the one in &CORE::ucfirst’s op tree), and since ucfirst uses TARG, we
end up with the same scalar.

We have the same problem with lvalue subs:

$ ./perl -Ilib -e 'sub UNIVERSAL::ucfirst :lvalue { ucfirst $_[0] } print "just another "->ucfirst, "perl hacker,\n"->ucfirst'
Perl hacker,
Perl hacker,

(This is not a regression, as 5.14 gave ‘Can't modify ucfirst in
lvalue subroutine return’.)

So ‘fixing’ coresubs would not be a solution, but a workaround.

The solution therefore is for leavesublv to copy PADTMPs in
rvalue context.

Commit 80422e24c fixed this for potential lvalue list context (i.e.,
for(lvsub()) {...}), but it wasn’t sufficient.
Quieten B::Deparse warnings (fixes #113464).
Make __SUB__ work in special blocks
[perl #113798] Don’t hide PATH from perlglob

To fix another bug, miniperl was changed to clear out %ENV before
shelling out to call the underlying glob program (csh on Unix;
perlglob on Windows), in commit a3342be368.

That proved slightly problematic, as it stopped <~> from working on
Unix, so commit 93b2dae1 changed it to preserve just $ENV{HOME}.

That turns out not to have been enough.  For some compilers, Win-
dows needs PATH preserved for perlglob to find certain DLLs it
needs to load.
bump version of B::Deparse
perldelta: more updates from Father Chrysostomos
Don’t let formats outlive their outer subs

This began crashing in 5.11.3:

sub foo {
  sub bar {
    my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$x);
    format =
@||||||
$x
.
  }
}
undef *bar;
write;

(On some systems, you need more alphabet soup to make it crash.)

This commit (just the perly.y part shown) caused it to crash:

commit 421f30ed1e95009450bdc7905bf3433ee806ea4f
Author: Zefram <zefram@fysh.org>
Date:   Tue Dec 15 11:48:31 2009 +0100

    [perl #22977] Bug in format/write

diff --git a/perly.y b/perly.y
index 18e5875..a61a6b3 100644
--- a/perly.y
+++ b/perly.y
@@ -511,7 +511,9 @@ peg	:	PEG
 	;

 format	:	FORMAT startformsub formname block
-			{ SvREFCNT_inc_simple_void(PL_compcv);
+			{
+			  CV *fmtcv = PL_compcv;
+			  SvREFCNT_inc_simple_void(PL_compcv);
 #ifdef MAD
 			  $$ = newFORM($2, $3, $4);
 			  prepend_madprops($1->tk_mad, $$, 'F');
@@ -521,6 +523,10 @@ format	:	FORMAT startformsub formname block
 			  newFORM($2, $3, $4);
 			  $$ = (OP*)NULL;
 #endif
+			  if (CvOUTSIDE(fmtcv) && !CvUNIQUE(CvOUTSIDE(fmtcv))) {
+			    SvREFCNT_inc_simple_void(fmtcv);
+			    pad_add_anon((SV*)fmtcv, OP_NULL);
+			  }
 			}
 	;

Unfortunately, adding the format to the pad like that (to allow
pad_fixup_inner_anons to fix up formats as well as subs) is proble-
matic.  It causes the format’s CvOUTSIDE to be weak.  Since the for-
mat does not hold a reference count on its outer sub, that sub can be
freed before the format.  When that happens, regular subs are fixed
up by having CvOUTSIDE change to point to the grandparent.  If you
do that for formats, you run into a problem: Formats can be cloned
even when the outer sub is not running.  Formats are cloned whenever
invoked *by name* via write.  If CvOUTSIDE points to a different sub,
then closing over the scalars in specific pad offsets in that sub can
result in reading past the end of the pad.  If you don’t read past the
end of the pad, you are still making variables close over unrelated variables, so the inner $x could close over an outer @y, etc.  Subrou-
tines don’t have that problem, as they can only be cloned when they
have an outer sub.  (Even though the outer sub’s prototype, if it is a
closure, might have been freed, the outer sub itself is still running
and referenced by the context stack.)

This commit changes the direction of the weak reference between an
outer sub’s pad and an inner format, fixing the crash.

To do so, it has to store, not the format itself, but a weak RV point-
ing to the format, in the outer sub’s pad.
(cherry picked from commit e09ac076a1dab8e2c5712775f478fcfb61cb7eb3)
Formats in closures called outside closures → crash

If a format closing over lexical variables is defined inside a clo-
sure, it must only be called directly inside that closure, not from
any other eval, sub, or format.

Calling it from anywhere else started causing a crash in 5.10.0,
because the format would try to close over variables in the currently-
running sub, using padoffsets intended for a completely unrelated pad.

This commit stops it from crashing by checking whether the currently-
running sub is a clone of the format’s outer sub (a closure proto-
type).  If it is not, the outer closure prototype is used, resulting
in ‘Variable is not available’ warnings.

This makes things work as well as they did in 5.8.  Ideally, we should
search the call stack for the topmost clone of the format’s outer sub;
but I’m saving that for another commit.
(cherry picked from commit af41786fe5732d5ec7932b946eec99a695ac6e43)