platform/upstream/perl.git
11 years agoStop the glob operator from leaking GVs
Father Chrysostomos [Mon, 5 Nov 2012 04:18:51 +0000 (20:18 -0800)]
Stop the glob operator from leaking GVs

It was adding GVs to the symbol table (via newGVgen), so they
would never be freed, even after the op was freed, unless done so
explicitly.

There is no reason for these GVs to be exposed.

11 years agoleakfinder.pl: Mair exceptions
Father Chrysostomos [Mon, 5 Nov 2012 02:33:52 +0000 (18:33 -0800)]
leakfinder.pl: Mair exceptions

11 years agoleakfinder.pl: Show file names
Father Chrysostomos [Mon, 5 Nov 2012 02:26:12 +0000 (18:26 -0800)]
leakfinder.pl: Show file names

It can take a *very* long time to run, so give some indication
that it is actually doing something.

11 years agoop.c:opslab_force_free: Make paranoid code reflect reality
Father Chrysostomos [Mon, 5 Nov 2012 02:21:34 +0000 (18:21 -0800)]
op.c:opslab_force_free: Make paranoid code reflect reality

When opslab_force_free is called, the CV still has a reference count
on the slab.  In fact, we don’t even bother lowering it if all goes
well, but simply free the slab with the reference count set to 1.
So the paranoid code that increments the reference count before free-
ing an op is not necessary.  Also, the shortcut out of the loop
was never triggered, as it was checking for a reference count of 0,
rather than 1.

11 years agoop.c: Stop SAVEFREEOP from leaking slabs
Father Chrysostomos [Mon, 5 Nov 2012 01:44:06 +0000 (17:44 -0800)]
op.c: Stop SAVEFREEOP from leaking slabs

When a CV is freed prematurely, it cleans up its op slab.  But
SAVEFREEOP may cause the savestack to point to an op in that slab
after the CV has been freed, so SAVEFREEOP is allowed to coun-
termand the freeing of the slab.  Every op that is not on the
savestack is freed.

The reference count of the slab was being left off by one.  The result
was that when the stack unwinding freed the op, it would leave the
slab behind and leak it.

11 years agoStop %! after syntax error from leaking the module name
Father Chrysostomos [Sun, 4 Nov 2012 22:57:49 +0000 (14:57 -0800)]
Stop %! after syntax error from leaking the module name

11 years agogv.c:S_require_tie_mod: remove SPAGAIN
Father Chrysostomos [Sun, 4 Nov 2012 22:39:07 +0000 (14:39 -0800)]
gv.c:S_require_tie_mod: remove SPAGAIN

We are not using SP after this point.

11 years agoDon’t leak BEGIN blocks after syntax errors
Father Chrysostomos [Sun, 4 Nov 2012 19:03:17 +0000 (11:03 -0800)]
Don’t leak BEGIN blocks after syntax errors

11 years agoleakfinder.pl: Use DD for output
Father Chrysostomos [Sun, 4 Nov 2012 07:38:45 +0000 (00:38 -0700)]
leakfinder.pl: Use DD for output

This solves the problem of binary code being dumped into the
terminal.

11 years agoDon’t leak pattern buffer when invalid flags croak
Father Chrysostomos [Sun, 4 Nov 2012 07:03:43 +0000 (00:03 -0700)]
Don’t leak pattern buffer when invalid flags croak

Normally if there is a syntax error yyerror just records it and pars-
ing continues anyway.  If there are too many syntax errors, it croaks.

It just happened that if it croaked when encountering invalid flags
for quote-like operators it would leak the buffer containing the pat-
tern (and the substitution for s///).

Since those are stored in the parser struct and are set to null when-
ever something else takes ownership of the SV, these struct members
will only ever be non-null in parser_free when they have leaked.  So
we can free them there.  (I.e., these slots have always been refer-
ence-counted, so treat them that way.)

11 years agosvleak.t: Enable syntax error tests under -Dmad
Father Chrysostomos [Sun, 4 Nov 2012 01:53:52 +0000 (18:53 -0700)]
svleak.t: Enable syntax error tests under -Dmad

Also use the fairly new eleak for brevity’s sake (and also because it
knows about the existing mad leak for string evals).

11 years agoUse shared memory for sv_debug_file
Father Chrysostomos [Sun, 4 Nov 2012 00:54:48 +0000 (17:54 -0700)]
Use shared memory for sv_debug_file

With -DDEBUGGING -Accflags=-DDEBUG_LEAKING_SCALARS -Duseithreads:

use threads;
use threads::shared;
my @shared_ary :shared;
$shared_ary[0] = &threads::shared::share({});
@shared_ary = ();
__END__
panic: free from wrong pool, 881c00!=800000.
Scalars leaked: 1

threads::shared has to juggle multiple interpreters.  Sometimes the
interpreter it is calling into (and passing as the first argument
via pTHX) is not actually the current thread as far as the OS is
concerned.

Perl_safesysfree in util.c does not take a pTHX parameter, so it
fetches the current interpreter from the data associated with the cur-
rent thread.

The result is that PERL_TRACK_MEMPOOL complains that the file name
associated with an SV under DEBUG_LEAKING_SCALARS is being freed from
the wrong interpreter.

Using shared memory for the file name solves the issue.

11 years agoStop require nonexistent::module from leaking
Father Chrysostomos [Sat, 3 Nov 2012 18:33:56 +0000 (11:33 -0700)]
Stop require nonexistent::module from leaking

This leak was caused by v5.17.4-125-gf7ee53b.

11 years agosvleak.t: re-evals leak under mad
Father Chrysostomos [Sat, 3 Nov 2012 16:28:54 +0000 (09:28 -0700)]
svleak.t: re-evals leak under mad

11 years agoFix invalid token warning with PERL_XMLDUMP and label
Father Chrysostomos [Sat, 3 Nov 2012 18:26:52 +0000 (11:26 -0700)]
Fix invalid token warning with PERL_XMLDUMP and label

Under mad builds, commit 5db1eb8 caused this warning:

$ PERL_XMLDUMP=/dev/null ./perl -Ilib -e 'foo:'
Invalid TOKEN object ignored at -e line 1.

Since I don’t understand the mad code so well, the easiest fix is to
revert back to using a PV, as we did before 5db1eb8.  To record the
utf8ness, we sneak it behind the trailing null.

11 years agoStop statement labels from leaking
Father Chrysostomos [Sat, 3 Nov 2012 13:50:04 +0000 (06:50 -0700)]
Stop statement labels from leaking

They have leaked since v5.15.9-35-g5db1eb8 (which probably broke mad
dumping of labels; to be addressed in the next commit).

11 years agoStop char classes from leaking
Father Chrysostomos [Sat, 3 Nov 2012 13:01:19 +0000 (06:01 -0700)]
Stop char classes from leaking

Since 5.10.0, this script has leaked:

$ perl -e 'warn$$; while(1){eval "/[:]/"}'

What exactly has leaked has changed over time.  In bleadperl
it is this:

SV = PV(0x8033c8) at 0x836170
  REFCNT = 1
  FLAGS = ()
  PV = 0x31c0b0 "\2\0\0\0\377\377\377\377\0\0\0\0\f\fS\21\1\0\0\0:\0\0\0;\0\0\0"\0
  CUR = 28
  LEN = 32

This only happens when the character class has only one character in
it, the same character repeated ([aa]), or a multicharacter fold.

A character class is usually compiled as an ANYOF node, but [A] is
optimised down to just A (and EXACT) and /[\xdf]/i is rewritten into a
more complex expression.

When the ANYOF node is abandoned, we need to free any temporary SVs
created in the mean time.  A few of them were leaking.

11 years agoleakfinder.pl
Father Chrysostomos [Sat, 3 Nov 2012 00:43:47 +0000 (17:43 -0700)]
leakfinder.pl

I wrote this to look for memory leaks.  Since it could be useful to
re-run it at some future time, I might as well put it somewhere where
it will not get lost.

It still needs a bit of work.  Currently, evaluating chunks of binary
code can cause memory leaks.  In those cases the binary code is dumped
straight to the terminal, which is not helpful.

11 years agosimplify GIMME_V
David Mitchell [Sun, 4 Nov 2012 18:23:25 +0000 (18:23 +0000)]
simplify GIMME_V

Since OPf_WANT_VOID == G_VOID etc, we can substantially simplify
the OP_GIMME macro (which is what implements GIMME_V).
This saves 588 bytes in the perl executable on my -O2 system.

11 years agoUpdate CGI to CPAN version 3.61
Chris 'BinGOs' Williams [Sun, 4 Nov 2012 13:05:12 +0000 (13:05 +0000)]
Update CGI to CPAN version 3.61

  [DELTA]

  Version 3.61 Nov 2nd, 2012

    (No code changes)

    [INTERNALS]
      - formatting of CGI::Carp documentation was improved. Thanks to benkasminbullock.
      - un-TODO some tests in t/tmpdir.t that were passing in most cases.
      More on this:
        https://github.com/markstos/CGI.pm/issues/19#
        https://github.com/markstos/CGI.pm/commit/cc73dc9807b0fabb56b3cdf1a9726588b2eda0f7

11 years agoUpdate Unicode-Normalize to CPAN version 1.16
Chris 'BinGOs' Williams [Sun, 4 Nov 2012 13:01:02 +0000 (13:01 +0000)]
Update Unicode-Normalize to CPAN version 1.16

  [DELTA]

  1.16  Sun Nov  4 17:23:03 2012
    - XSUB: use PERL_NO_GET_CONTEXT (see perlguts)
      (see [rt.cpan.org #80312])

11 years agoUpdate Unicode-Collate to CPAN version 0.91
Chris 'BinGOs' Williams [Sun, 4 Nov 2012 12:59:11 +0000 (12:59 +0000)]
Update Unicode-Collate to CPAN version 0.91

  [DELTA]

  0.91  Sun Nov  4 17:00:20 2012
    - XSUB: use PERL_NO_GET_CONTEXT (see perlguts)
      (see [rt.cpan.org #80313])

11 years agoUpdate Digest-SHA to CPAN version 5.73
Chris 'BinGOs' Williams [Sun, 4 Nov 2012 12:56:46 +0000 (12:56 +0000)]
Update Digest-SHA to CPAN version 5.73

  [DELTA]

  5.73  Wed Oct 31 04:32:44 MST 2012
    - provided workaround for DEC compiler bug (ref. Makefile.PL)

11 years agoSync Module-CoreList version in Maintainers.pl with CPAN
Chris 'BinGOs' Williams [Sun, 4 Nov 2012 12:52:43 +0000 (12:52 +0000)]
Sync Module-CoreList version in Maintainers.pl with CPAN

11 years agofix an epigraph typo
Ricardo Signes [Sat, 3 Nov 2012 23:14:26 +0000 (19:14 -0400)]
fix an epigraph typo

reported by Vadim Konovalov; thanks!

11 years agoRemove thread context from Perl_vmssetuserlnm.
Craig A. Berry [Sat, 3 Nov 2012 13:11:44 +0000 (08:11 -0500)]
Remove thread context from Perl_vmssetuserlnm.

This routine by its very nature applies to the whole process so
there is no way it can make use of a thread context, and it may need
to be called from places where there is no thread context, such
as very early in start-up.

It's not documented, was never intended to be part of the API, was
only made global so it could be called from doio.c, and no uses of
it turn up in a CPAN grep, so the change should be safe.

11 years agoIncrease $Module::CoreList::VERSION to 2.76
Father Chrysostomos [Fri, 2 Nov 2012 21:48:48 +0000 (14:48 -0700)]
Increase $Module::CoreList::VERSION to 2.76

11 years agoprint deprecation information in corelist
Alexandr Ciornii [Wed, 31 Oct 2012 10:31:47 +0000 (12:31 +0200)]
print deprecation information in corelist

11 years agosvleak.t: Suppress warning
Father Chrysostomos [Fri, 2 Nov 2012 19:36:23 +0000 (12:36 -0700)]
svleak.t: Suppress warning

11 years agoStop string eval from leaking ops
Father Chrysostomos [Fri, 2 Nov 2012 19:35:25 +0000 (12:35 -0700)]
Stop string eval from leaking ops

This was leaking:

$ ./miniperl  -Xe 'warn $$; while(1){eval "ok 8"};'
1915 at -e line 1.
^C

This was not:

$ ./miniperl  -Xe 'warn $$; while(1){eval "sub {ok 8}"};'
1916 at -e line 1.
^C

The sub is successfully taking care of its ops when it is freed.  The
eval is not.

I made the mistake of having the CV relinquish ownership of the op
slab after an eval syntax error.  That’s precisely the situation in
which the ops are likely to leak, and for which the slab allocator was
designed.  Duh.

11 years agoDon’t leak when printf causes wide warnings
Father Chrysostomos [Fri, 2 Nov 2012 13:17:36 +0000 (06:17 -0700)]
Don’t leak when printf causes wide warnings

11 years agoDon’t leak when printfing to bad handle under fatal warnings
Father Chrysostomos [Fri, 2 Nov 2012 13:12:27 +0000 (06:12 -0700)]
Don’t leak when printfing to bad handle under fatal warnings

11 years agoconcat2.t: Under miniperl only skip one test
Father Chrysostomos [Fri, 2 Nov 2012 12:59:31 +0000 (05:59 -0700)]
concat2.t: Under miniperl only skip one test

11 years agoFix $byte_overload .= $utf8 regression
Father Chrysostomos [Fri, 2 Nov 2012 12:48:34 +0000 (05:48 -0700)]
Fix $byte_overload .= $utf8 regression

This is a regression from 5.12.

This was probably broken by commit c5aa287237.

#!perl -lCS
{ package o; use overload '""' => sub { $_[0][0] } }

$x = bless[chr 256],o::;
"$x";
$x->[0] = "\xff";
$x.= chr 257;
$x.= chr 257;

use Devel::Peek;
Dump $x;
print $x;
__END__

Output under 5.12.4:

SV = PVIV(0x820604) at 0x825820
  REFCNT = 1
  FLAGS = (POK,pPOK,UTF8)
  IV = 0
  PV = 0x2139d0 "\303\277\304\201\304\201"\0 [UTF8 "\x{ff}\x{101}\x{101}"]
  CUR = 6
  LEN = 16
ÿāā

Output under 5.14.0:

SV = PVIV(0x820604) at 0x826490
  REFCNT = 1
  FLAGS = (POK,pPOK,UTF8)
  IV = 0
  PV = 0x316230 "\303\277\303\204\302\201\304\201"\0 [UTF8 "\x{ff}\x{c4}\x{81}\x{101}"]
  CUR = 8
  LEN = 16
ÿÄ\81ā

The UTF8 flag is only meaningful right after stringification.

If the $byte_overload scalar happens to have the flag on from last
time, but string overloading will turn the flag off, then pp_concat
gets confused as to whether it is dealing with bytes or utf8.  It
sees both sides as having the same utf8ness, so it concatenates,
which stringifies the lhs and turns off the flag.  The utf8 sequences
appended end up with no utf8 flag associated with them, the observable
effect being that the rhs is encoded as utf8.

If it weren’t for encoding.pm, we could use sv_catpvn_nomg_maybeutf8
and avoid determining the utf8ness of the lhs beforehand.  But see-
ing that encoding.pm still exists, we have to prevent double overload
stringification the other way, by force-stringification of the target.

11 years agoDon’t leak when pushing on to read-only array
Father Chrysostomos [Fri, 2 Nov 2012 04:48:22 +0000 (21:48 -0700)]
Don’t leak when pushing on to read-only array

$ ./miniperl -Ilib -w -e 'warn $$; while(1){eval {push @-, ""}}'

Croak first instead of creating a new element to store in the
array first and letting av_store croak.

11 years agoDon't leak stderr from 'git describe' in cmpVERSION
Hugo van der Sanden [Fri, 2 Nov 2012 09:42:52 +0000 (09:42 +0000)]
Don't leak stderr from 'git describe' in cmpVERSION

11 years agoDetect empty git tag in cmpVERSION
Hugo van der Sanden [Fri, 2 Nov 2012 10:39:34 +0000 (10:39 +0000)]
Detect empty git tag in cmpVERSION

11 years agotest.pl: allow for undefs in eq_hash
Hugo van der Sanden [Mon, 29 Oct 2012 23:31:21 +0000 (23:31 +0000)]
test.pl: allow for undefs in eq_hash

It should be possible to compare hashes with undef values without
triggering warnings.

11 years agoFix /a++(?{})+$code_block/
Father Chrysostomos [Thu, 1 Nov 2012 21:49:35 +0000 (14:49 -0700)]
Fix /a++(?{})+$code_block/

This I would expect:

$ perl5.16.0 -wMre=eval -e '$x = "(?{})"; /a++(?{})+$x/x'
(?{})+ matches null string many times in regex; marked by <-- HERE in m/a++(?{})+ <-- HERE (?{})/ at -e line 1.
Use of uninitialized value $_ in pattern match (m//) at -e line 1.

It warns, but it still runs.

This I would not,

$ perl5.17.5 -wMre=eval -e '$x = "(?{})"; /a++(?{})+$x/x'
Nested quantifiers in regex; marked by <-- HERE in m/a++     + <-- HERE (?{})/ at (eval 1) line 1.

were it not for the fact that I know how it works. :-)

To compile the blocks in $x without recompiling the blocks directly
inside /.../, the regexp compiler blanks out the ‘outer’ blocks with
spaces, and compiles qr'a++     +(?{})'x.  But /x can see through
those spaces, resulting in a change in behaviour.  So use under-
scores instead.

11 years agoDon’t leak with /(?{})$invalid_code_block/
Father Chrysostomos [Thu, 1 Nov 2012 20:08:17 +0000 (13:08 -0700)]
Don’t leak with /(?{})$invalid_code_block/

This script was leaking:

$ ./perl -Ilib -wMre=eval -e '$x = "(?{+})"; while(1){eval {/(?{})$x/}}'

The mallocked array that is allocated before compilation to hold the
code blocks was not being freed before the syntax error from the inner
pattern ($x) was propagated.

11 years agoFree detritus when croaking with /(?{})$invalid/
Father Chrysostomos [Thu, 1 Nov 2012 13:19:28 +0000 (06:19 -0700)]
Free detritus when croaking with /(?{})$invalid/

This script was leaking:

$ ./miniperl -e 'warn $$; $x = ")"; while( 1){ eval { /(?{})$x/ }; }'

The mallocked array that is allocated before compilation to hold the
code blocks was not being protected properly around the first pass of
compilation.

11 years agoStop run-time regexp blocks from leaking regexps
Father Chrysostomos [Wed, 31 Oct 2012 17:02:03 +0000 (10:02 -0700)]
Stop run-time regexp blocks from leaking regexps

This was leaking like a sieve: $var = '(?{})'; /stuff$var/;

When a run-time regular expression has code blocks in it,
those are compiled separately inside their own qr thingy (see
S_compile_runtime_code in regcomp.c).

In re_op_compile, the newly-compiled code blocks are stored in
pRExC_state->code_blocks, which is a mallocked array.  That array also
holds reference counts on the regular expressions from which the code
blocks derive their existence.  When the whole regular expression is
compiled, the code blocks are fetched from that array, and the new
regular expression ends up holding a reference count on those code
block’s originating regular expressions.

The reference counts that pRExC_state->code_blocks had were not low-
ered when pRExC_state->code_blocks was freed, except for qr/stuff$var/
(because the qr// would take ownership of those reference counts,
which would be lowered when the outer qr// itself was freed).

11 years agoStop / $looks_like_block/ from leaking
Father Chrysostomos [Tue, 30 Oct 2012 23:41:27 +0000 (16:41 -0700)]
Stop / $looks_like_block/ from leaking

If an interpolated string looks as though it contains a regexp code
block, the regexp compiler will evaluate it inside qr'...' and then
extract the code blocks from the resulting regexp object.

If it turned out to be a false positive (e.g., "[(?{})]"), then
the code to handle this returned without freeing the temporary reg-
exp object.

11 years agoadd perl5.16.2 to perlhist
Ricardo Signes [Thu, 1 Nov 2012 14:20:20 +0000 (10:20 -0400)]
add perl5.16.2 to perlhist

11 years agoadd perl5162delta
Ricardo Signes [Thu, 1 Nov 2012 14:19:47 +0000 (10:19 -0400)]
add perl5162delta

11 years agoadd the 5.16.2 epigraph
Ricardo Signes [Thu, 1 Nov 2012 14:07:46 +0000 (10:07 -0400)]
add the 5.16.2 epigraph

11 years agoInitial (incomplete) patch to start restoring WinCE build
Konovalov, Vadim (Vadim)** CTR ** [Thu, 1 Nov 2012 14:03:34 +0000 (14:03 +0000)]
Initial (incomplete) patch to start restoring WinCE build

Subject: RE: status of WinCE Perl port in 2012
From: "Konovalov, Vadim (Vadim)** CTR **" <vadim.konovalov@alcatel-lucent.com>
Date: Tue, 23 Oct 2012 14:26:49 +0200
Message-ID: <35BF8D9716175C43BB9D67CA60CC345E028EE0C899@FRMRSSXCHMBSC2.dc-m.alcatel-lucent.com>

11 years agoRemove __attribute__malloc__ from MYSWAP functions
Steve Hay [Thu, 1 Nov 2012 13:43:39 +0000 (13:43 +0000)]
Remove __attribute__malloc__ from MYSWAP functions

These functions are only used when the native sockets functions are not
available, e.g. when building miniperl on Windows following commit
19253ae62c, so gcc's warning about ignoring the __malloc__ attribute here
is not normally seen.

The addition of "a" to these functions in embed.fnc by
commit f54cb97a39 was presumably wrong since none of them actually
allocate any memory (nor did so at the time), so change it to just "R"
(which is implied by the "a" and is still appropriate).

11 years agoWin32 miniperl: delay loading for Winsock, and then remove it
Daniel Dragan [Sat, 13 Oct 2012 23:37:33 +0000 (19:37 -0400)]
Win32 miniperl: delay loading for Winsock, and then remove it

Slim down the image and speed up start up time for Win32 miniperl by
removing Winsock. Also if the build process on Win32 in the future
requires sockets, commenting one line in win32.h will turn sockets back on
for miniperl, but this time with delay loading on VC Perl. The only casulty
of no sockets for Win32 miniperl was figuring out the computer's name in
win32/config_sh.PL. A workaround by using an ENV var was implemented. The
purpose of this commit is to speed up the build process of Perl.

As said in the comment in win32.h, the WIN32_NO_SOCKETS macro is
incomplete in implementation. It is only removed winsock from being linked
in in miniperl, not full Perl. PERL_IMPLICIT_SYS (specifically PerlSock in
win32/perlhost.h) and makedef.pl's hard coded list of win32_* function
exports cause winsock to still be linked in with even with
WIN32_NO_SOCKETS on full perl. Both PERL_IMPLICIT_SYS (win32/perlhost.h)
and makedef.pl would require changes to remove winsock from being linked
in on full perl in the future.

11 years agoAdd the DynaLoader upgrade to perldelta
Steve Hay [Wed, 31 Oct 2012 08:37:41 +0000 (08:37 +0000)]
Add the DynaLoader upgrade to perldelta

11 years agoUse correct type to avoid a cast added by fe1c5936a5
Steve Hay [Wed, 31 Oct 2012 08:36:58 +0000 (08:36 +0000)]
Use correct type to avoid a cast added by fe1c5936a5

(Suggested by Tony Cook.)

11 years agoBump DynaLoader's $VERSION after commit fe1c5936a5
Steve Hay [Wed, 31 Oct 2012 08:25:25 +0000 (08:25 +0000)]
Bump DynaLoader's $VERSION after commit fe1c5936a5

11 years agoconsting in perl.c:S_Internals_V and Win32 DynaLoader
Daniel Dragan [Wed, 17 Oct 2012 15:56:29 +0000 (11:56 -0400)]
consting in perl.c:S_Internals_V and Win32 DynaLoader

These assorted static allocated variables were in RW memory in the perl
image. Move them to RO memory so they are sharable between different
Perl processes by the OS. The lack of consting in Win32 Dynaloader traces
to commit 0a753a76406 . S_Internals_V traces to commit 4a5df386486 .

11 years agoThree spelling corrections.
James E Keenan [Tue, 30 Oct 2012 23:25:39 +0000 (19:25 -0400)]
Three spelling corrections.

11 years agoutf8.c: Stop _core_swash_init from leaking
Father Chrysostomos [Tue, 30 Oct 2012 21:38:27 +0000 (14:38 -0700)]
utf8.c: Stop _core_swash_init from leaking

If an %INC hook or $@ assignment dies, then a scalar is leaked.  I
don’t know that it is possible to test this.

11 years agoAllow regexp-to-pvlv assignment
Father Chrysostomos [Tue, 30 Oct 2012 16:44:26 +0000 (09:44 -0700)]
Allow regexp-to-pvlv assignment

Since the xpvlv and regexp structs conflict, we have to find somewhere
else to put the regexp struct.

I was going to sneak it in SvPVX, allocating a buffer large
enough to fit the regexp struct followed by the string, and have
SvPVX - sizeof(regexp) point to the struct.  But that would make all
regexp flag-checking macros fatter, and those are used in hot code.

So I came up with another method.  Regexp stringification is not
speed-critical.  So we can move the regexp stringification out of
re->sv_u and put it in the regexp struct.  Then the regexp struct
itself can be pointed to by re->sv_u.  So SVt_REGEXPs will have
re->sv_any and re->sv_u pointing to the same spot.  PVLVs can then
have sv->sv_any point to the xpvlv body as usual, but have sv->sv_u
point to a regexp struct.  All regexp member access can go through
sv_u instead of sv_any, which will be no slower than before.

Regular expressions will no longer be SvPOK, so we give sv_2pv spec-
ial logic for regexps.  We don’t need to make the regexp struct
larger, as SvLEN is currently always 0 iff mother_re is set.  So we
can replace the SvLEN field with the pv.

SvFAKE is never used without SvPOK or SvSCREAM also set.  So we can
use that to identify regexps.

11 years agoregcomp.c: Really stop regexp-to-pv assignment from leaking
Father Chrysostomos [Mon, 29 Oct 2012 07:01:02 +0000 (00:01 -0700)]
regcomp.c: Really stop regexp-to-pv assignment from leaking

edd9fea2b8 was not enough.  A scalar may hold a PV even with the
SvPOKp flag off:

$ ./perl -Ilib -e 'warn $$; while(1){ $x = "a"; $x = 1; $x = ${qr//}}'

11 years agoTurn off OK flags when creating a regexp.
Father Chrysostomos [Mon, 29 Oct 2012 06:56:01 +0000 (23:56 -0700)]
Turn off OK flags when creating a regexp.

$ perl5.16.0 -le '$x = 1.1; $x = ${qr//}; print 0+$x'
4.15336878055219e-317
$ perl5.16.0 -le '$x = 1; $x = ${qr//}; print 0+$x'
1645024

Very strange.

Under debugging builds, both produce assertion failures.

By turning off all OK flags, we also prevent the destination’s utf8-
ness from sticking.

11 years agosv.c: Drop PV when assigning over regexp
Father Chrysostomos [Mon, 29 Oct 2012 06:49:48 +0000 (23:49 -0700)]
sv.c: Drop PV when assigning over regexp

    $x = ${qr//};
    $x = 3;

On the second line, we don’t need to copy the stringification of the
regexp, since we are just going to clobber it anyway.

11 years agoPrune dead code in sv.c:sv_force_normal_flags
Father Chrysostomos [Mon, 29 Oct 2012 06:47:22 +0000 (23:47 -0700)]
Prune dead code in sv.c:sv_force_normal_flags

When a regexp is unregexped, a new SV (temp) is created, so it
can swap bodies with the regular expression (sv), and then temp
can be freed.

If SvLEN is 0, then a scalar does not own its string buffer.  Copied
regexps use that mechanism to share strings; only the original regexp
owns the string.

This little bit of code for handling the SvPVX field is strange:

/* Remember that SvPVX is in the head, not the body. */
if (SvLEN(temp)) {
    SvLEN_set(temp, SvLEN(sv));
    /* This signals "buffer is owned by someone else" in sv_clear,
       which is the least effort way to stop it freeing the buffer.
    */
    SvLEN_set(sv, SvLEN(sv)+1);
} else {
    /* Their buffer is already owned by someone else. */
    SvPVX(sv) = savepvn(SvPVX(sv), SvCUR(sv));
    SvLEN_set(temp, SvCUR(sv)+1);
}

Checking SvLEN(temp) is pointless if we have just created temp.  That
check is always false.  Presumably it was meant to be SvLEN(sv).  But
the original regexp scalar (i.e., not a copy) can never make it to
this function.  So SvLEN(sv) is always 0, which is why this has
not caused any problem.  The SvLEN_set inside the apodosis is also
strange.  ‘This signals "buffer is owned by someone else"’.  No it
certainly does not!  It is not setting SvLEN to 0, but definitely to
non-zero.  I can only assume this is a copy-and-paste error, which has
never caused a problem because it is unreachable.

I hereby excise this code (leaving the contents of the else).

11 years agoregcomp.c: Don’t point mother_re to regexp copy
Father Chrysostomos [Mon, 29 Oct 2012 06:37:21 +0000 (23:37 -0700)]
regcomp.c: Don’t point mother_re to regexp copy

In code like this:

    $x = ${qr//};
    $y = $x
    undef $x;

We end up with $y’s mother_re pointer pointing to something that is
not a regexp.

This can cause thread cloning to create a new regexp with its SvPVX
pointing to the string buffer of the original regexp:

    $x = ${qr/abcd/};
    $y = $x;
    use Devel::Peek;
    Dump($y);
    $x = *3;
    use threads;
    async { Dump $y; print $y, "\n" }->join;

The dump shows that both $y’s share the same string buffer, and nei-
ther claims ownership to it.

I have not been able to make this crash or reuse the string for some-
thing else, but still this is walking a fine line.  Theoretically, it
should be possible for that string to be freed and reused in the par-
ent thread while the child thread is still using it.

Instead of pointing mother_re to the rhs of the assignment, point it
to the original re from which the rhs derives its existence.  I.e.,
copy the mother_re field.

11 years agoregcomp.c: Stop regexp-to-pv assignemnt from leaking
Father Chrysostomos [Sun, 28 Oct 2012 21:41:55 +0000 (14:41 -0700)]
regcomp.c: Stop regexp-to-pv assignemnt from leaking

SvPV_set will just set SvPVX, allowing the existing value to leak.

This leak was caused by f082678508, which allowed reg_temp_copy to
be called with an existing SV, but without modifying the contents of
reg_temp_copy to account.

11 years agosv.c: Fix code-before-declarations
Father Chrysostomos [Sun, 28 Oct 2012 14:00:23 +0000 (07:00 -0700)]
sv.c: Fix code-before-declarations

11 years agoDon’t crash with $tied[-1] when array is tied to non-obj
Father Chrysostomos [Sun, 28 Oct 2012 08:48:18 +0000 (01:48 -0700)]
Don’t crash with $tied[-1] when array is tied to non-obj

The code for checking to see whether $NEGATIVE_INDICES is defined in
the tie package was very fragile, and was repeated four times.

11 years agoDon’t skip tied EXISTS for negative array indices
Father Chrysostomos [Sun, 28 Oct 2012 08:44:31 +0000 (01:44 -0700)]
Don’t skip tied EXISTS for negative array indices

This was broken in 5.14.0 for those cases where $NEGATIVE_INDICES is
not true:

sub TIEARRAY{bless[]};
sub FETCHSIZE { 50 }
sub EXISTS { print "does $_[1] exist?\n" }
tie @a, "";
exists $a[1];
exists $a[-1];
$NEGATIVE_INDICES=1;
exists $a[-1];

$ pbpaste|perl5.12.0
does 1 exist?
does 49 exist?
does -1 exist?
$ pbpaste|perl5.14.0
does 1 exist?
does -1 exist?

This was broken by 54a4274e3c.

11 years agoyyerror->yyerror_pvn in toke.c:S_new_constant
Daniel Dragan [Sat, 27 Oct 2012 09:18:49 +0000 (05:18 -0400)]
yyerror->yyerror_pvn in toke.c:S_new_constant

Avoids a strlen.

11 years agormv a sv_2mortal and unused var in toke.c:Perl_yyerror_pvn
Daniel Dragan [Sat, 27 Oct 2012 05:44:13 +0000 (01:44 -0400)]
rmv a sv_2mortal and unused var in toke.c:Perl_yyerror_pvn

newSVpvn_flags is capable of mortalizing already, use that, is_utf8 is used
only once, waste of an auto var stack slot to calculate it so early,
instead create the flags arg to newSVpvn_flags at the point of usage.
flags param of yyerror_pvn will always be on the C stack.

11 years agosv.c: Allow blessed cows
Father Chrysostomos [Sun, 28 Oct 2012 06:53:46 +0000 (23:53 -0700)]
sv.c: Allow blessed cows

There is no reason kine should not receive blessings, too.

11 years agosv.c: Remove redundant Sv[INP]OK checks on fbm/regexps
Father Chrysostomos [Sun, 28 Oct 2012 06:51:42 +0000 (23:51 -0700)]
sv.c: Remove redundant Sv[INP]OK checks on fbm/regexps

These two code paths, sv_2iv and sv_2uv, used to be shared with gmag-
ical scalars in general, but now only apply to scalars that cannot
hold numeric values and are always SvPOK.

11 years agosv.c: Remove redundant sv_force_normal calls from sv_2[iun]v
Father Chrysostomos [Sun, 28 Oct 2012 06:42:09 +0000 (23:42 -0700)]
sv.c: Remove redundant sv_force_normal calls from sv_2[iun]v

The previous commit made it possible to nummify a string whose SvLEN
is 0.  So we don’t need to run shared hash key scalars through
sv_force_normal before nummifying them.  We still need to run COW sca-
lars through sv_force_normal under PERL_OLD_COPY_ON_WRITE, as it uses
the IVX field for COW bookkeeping.  For simplicity’s sake, I’m not
bothering to distinguish shared hash keys scalars from other COW sca-
lars under PERL_OLD_COPY_ON_WRITE.

11 years agosv.c: !SvLEN does not mean undefined
Father Chrysostomos [Sun, 28 Oct 2012 06:30:28 +0000 (23:30 -0700)]
sv.c: !SvLEN does not mean undefined

There are various SvPOKp(sv) && SvLEN(sv) checks in numeric
conversion routines in sv.c, which date back to perl 1.  (See
<http://perl5.git.perl.org/perl.git/blob/8d063cd8450e59e:/str.c#l89>.)
Back then it did not matter, as str->len (later SvLEN) was always set
when there was a PV.  It was not until perl 5.003_01 (1edc1566d5) that
we got the SvLEN==0 mechanism for PVs not owned by the scalar.  (I
don’t believe it was actually used till later, so when this became a
problem I don’t know--but that’s enough digging.)

A regexp returned by ${qr//} is POK but does not own its string.  This
means that nummifying a regexp will result in a uninitialized warning.

The SvLEN check is redundant and problematic, so I am removing it.
(This also means I can remove the sv_force_normal calls in the next
commit, since shared hash key scalars, which also have SvLEN==0 will
no longer need it to pass the SvLEN checks.)

This does mean, however, that SVt_REGEXP can reach code paths that
expect to be able to use Sv[IN]VX (not valid for regexps), so I actu-
ally have to check that the type != SVt_REGEXP as well.  We already
have code for handling fbm scalars (for which Sv[IN]VX fields are also
unusable), so we can send regexps through those paths.

11 years agoStop regexp assignment from clobbering magic
Father Chrysostomos [Sun, 28 Oct 2012 01:18:35 +0000 (18:18 -0700)]
Stop regexp assignment from clobbering magic

$ perl5.10.0 -le '$1 = ${qr||}; print "ok"'
Modification of a read-only value attempted at -e line 1.
$ perl5.12.0 -le '$1 = ${qr||}; print "ok"'
ok

Wonderful!

It can also cause blessings to be lost, or so I thought:

sub curse {
  for my $obj ( ${$_[0]} ) {
    my $save = $obj;
    $obj = ${qr||};
    $obj = $save;
  }
}
$y = bless \$x;
print $y, "\n"; # main=SCALAR(0x825b70)
curse $y;
print $y, "\n"; # Bus error

The OBJECT flag gets left on, but SvSTASH is null.

Commit b9ad13acb set SvSTASH to null after copying the regexp struct.
Commit 703c388dc did the same with SvMAGIC.  In both cases, this was
to avoid bugs involving magic and blessings being copied by = which
should not happen.  But both changes caused other bugs.

Three months later, 6e1287864cd changed the order of the struct, such
that SvMAGIC and SvSTASH are no longer copied from the parent regexp,
rendering the aforementioned changes no longer necessary.

11 years agoFix assertion failure with $float = $regexp assignment
Father Chrysostomos [Sat, 27 Oct 2012 05:59:10 +0000 (22:59 -0700)]
Fix assertion failure with $float = $regexp assignment

Commit b9ad13acb3 caused case SVt_REGEXP in sv_upgrade to fall
through to the assertions under case SVt_PVIV that are not relevant to
SVt_REGEXP.

We should really be setting the FAKE flag when actually making a sca-
lar a regexp, rather than in sv_upgrade.  (I will probably need it
there in future commits, too, since it really should be possible for
SVt_PVLVs to hold regular expressions.)

11 years agosv.c: No need to de-COW COWs on upgrade
Father Chrysostomos [Sat, 27 Oct 2012 05:42:51 +0000 (22:42 -0700)]
sv.c: No need to de-COW COWs on upgrade

I’ve taken the conservative approach of still de-COWing COWs for reg-
exps and anything above.  I’m not confident that it would be safe
for those.

11 years agoDon’t sv_force_normal in mg.c:S_save_magic
Father Chrysostomos [Sat, 27 Oct 2012 01:20:16 +0000 (18:20 -0700)]
Don’t sv_force_normal in mg.c:S_save_magic

This was added to make SvREADONLY_off safe.  (I think read-only is
turned off during magic so the magic scalar itself can be set without
the sv_set* functions getting upset.)  Since SvREADONLY doesn’t mean
read-only for COWs, we don’t actually need to do sv_force_normal, but
can simply skip SvREADONLY_off for COWs.

By leaving it to sv_set* functions to do sv_force_normal, we avoid
having to copy the string buffer if it is just going to be thrown away
anyway.  S_save_magic can’t know whether the scalar will actually be
overwritten, so it has to copy the buffer.

11 years agoWorkaround for VAX compiler optimizer bug in Digest::SHA.
Craig A. Berry [Sat, 27 Oct 2012 18:23:46 +0000 (13:23 -0500)]
Workaround for VAX compiler optimizer bug in Digest::SHA.

This was [perl #85932] and has been forwarded upstream as
[rt.cpan.org #80157].  The code is a near-verbatim copy of how
the same problem has been solved in Digest::MD5 since 2001.

After this change, the core build is now working again (slowly!)
on OpenVMS VAX.

11 years agoFix use of non-existent bareword filehandle in t/TEST.
Craig A. Berry [Sat, 27 Oct 2012 12:53:10 +0000 (07:53 -0500)]
Fix use of non-existent bareword filehandle in t/TEST.

The refactoring done in 84650816efdc42d6 was incomplete and left
a couple of VMS-specific instances of RESULT while replacing all
other occurrences with $result.

Spotted by Jim Cromie.

11 years agosilence warning in toke.c charnames support
Yves Orton [Fri, 26 Oct 2012 09:41:10 +0000 (11:41 +0200)]
silence warning in toke.c charnames support

In a C sprintf the expectation is that * parameters are type "int".

11 years agoRT #115488 cxstack -1 at nested scan_heredoc
Reini Urban [Fri, 26 Oct 2012 21:44:57 +0000 (16:44 -0500)]
RT #115488 cxstack -1 at nested scan_heredoc

print <<E1 eq "foo\n\n" ? "ok 19\n" : "not ok 19\n";
@{[ <<E2 ]}
foo
E2
E1
checked for a CxTYPE(cx) == CXt_EVAL with an invalid cxstack -1, detected by asan.

11 years agoAllow cow with $magic = $hashkey
Father Chrysostomos [Fri, 26 Oct 2012 23:23:11 +0000 (16:23 -0700)]
Allow cow with $magic = $hashkey

This was brought up in
<https://rt.perl.org/rt3/Ticket/Display.html?id=114820#txn-1165898>.

There is no reason we cannot assigned a shared hash key to a magical
scalar.  The only destination flag in CAN_COW_MASK that makes COW
assignment questionable is SVf_BREAK.  If such an assignment can hap-
pen (and I don’t believe it actually can), we will end up with unbal-
anced string table warnings.  So change the CAN_COW_MASK check to an
SVf_BREAK check.

11 years agoMake private variable static in regexec.c.
Craig A. Berry [Fri, 26 Oct 2012 15:01:13 +0000 (10:01 -0500)]
Make private variable static in regexec.c.

11 years agoDe-globalize regcomp inversion lists.
Craig A. Berry [Fri, 26 Oct 2012 21:33:26 +0000 (16:33 -0500)]
De-globalize regcomp inversion lists.

These lists are declared at file scope so will be global unless
made static.  Actual use of these lists is via the various PL_xxx
global variables that point to them and that (except for
NonL1_Perl_Non_Final_Folds_invlist) are initialized in
Perl_re_op_compile in regcomp.c (but not in its incarnation as
ext/re/re_comp.c).

So change the lists to be static, and also skip declaring and
initializing them in ext/re/re_comp.c except for the one case that
is actually used in the extension version.

11 years agostart to make ext/B work with 5.14.x
David Mitchell [Fri, 26 Oct 2012 09:14:06 +0000 (10:14 +0100)]
start to make ext/B work with 5.14.x

This fixes up a couple of test files to work under 5.14.x.
Lots more needs fixing up to make the whole distribution work
under 5.14.x, but I've lost the will for now.,

11 years agoB.xs: move all B::*OP methods to B::OP::next
David Mitchell [Thu, 25 Oct 2012 13:48:06 +0000 (14:48 +0100)]
B.xs: move all B::*OP methods to B::OP::next

The previous commit moved all B::*OP methods capable of using direct field
offsets into next(). This commit moves the remaining B::*OP methods onto
it too (apart from oplist(), which returns a list rather than a single
item).

This simplifies the code, reduces the object size, and will also make it
easier to add an overlay facility, which will be coming soon.

11 years agoB.xs: rationalise all methods aliased to next()
David Mitchell [Wed, 24 Oct 2012 20:53:38 +0000 (21:53 +0100)]
B.xs: rationalise all methods aliased to next()

The code for B::OP::next() actually implements all B::*OP::* methods
that work by directly returning a field at a known offset in the OP
structure. Methods that can't do direct access usually have their own
body, rather than sharing with next().

However, whether a method can do direct field access is often dependent on
threading and/or perl version; so the same method is sometimes implemented
by next(), and sometimes by one or more individual method bodies. This is
all very confusing.

This commit takes all methods that *may* be implemented within next(),
and makes them always implemented by next(), using a table of data that
describes each method's offset, or -1 if it needs special handling.

This makes it a lot easier to see what's going on, and will also make it
easier to add an overlay facility, which will be coming soon.

The following commit will consolidate the remaining B::*OP methods within
next().

11 years agoext/B: remove pre-5.10 support
David Mitchell [Wed, 24 Oct 2012 17:10:22 +0000 (18:10 +0100)]
ext/B: remove pre-5.10 support

Expunge all conditional code that supports 5.6.x through 5.9.x,
making 5.10.0 the oldest release notionally supported.
This simplifies things considerably.

See p5p thread starting at
    Message-ID: <20121018122941.GE1908@iabyn.com>

11 years agomake ext/B work with 5.16.x
David Mitchell [Wed, 24 Oct 2012 14:50:25 +0000 (15:50 +0100)]
make ext/B work with 5.16.x

The modules and tests under ext/B are notionally supposed to be
portable to older perl versions; in practice, extensive bit-rot
has occurred; often attempts have been made to add version-specific
code, which haven't actually been tested against older perl versions.

This commit does the minimum necessary to get the tests under ext/B
working with 5.16.0 and 5.16.1, threaded and unthreaded. It makes no
assertions as to whether it will work with the rest of the 5.16.x test
suite.

The side effects of this fix-up are:

* a facility has been added to OptreeCheck.pm (the test module that
checks the Concise output of various constructs) that allows
version-specific matching, e.g.:

    # 4  <$> const(PV "junk") s*      < 5.017002
    # 4  <$> const(PV "junk") s*/FOLD >=5.017002

* OptreeCheck.pm's skip mechanism was found to be broken: checkOptree()
allows you to specify skipping, but only skipped one test, even though
a single call to checkOptree() could generate multiple lines of test
output.

11 years agoBetter documentation for internal SV types
Father Chrysostomos [Fri, 26 Oct 2012 15:32:23 +0000 (08:32 -0700)]
Better documentation for internal SV types

11 years agofix a compile warning and refactor some diagnostics in regexec.c
Yves Orton [Sun, 21 Oct 2012 13:04:47 +0000 (15:04 +0200)]
fix a compile warning and refactor some diagnostics in regexec.c

11 years agoimprove diagnostics of dbm_filter_util.pl by using Data::Dumper::qquote
Yves Orton [Wed, 29 Aug 2012 07:38:07 +0000 (09:38 +0200)]
improve diagnostics of dbm_filter_util.pl by using Data::Dumper::qquote

We are testing things like packed strings. If we output the bytes raw
via diag we upset terminal layers expecting utf8, and generally output
unreadable garbage regardless. So use Data::Dumper::qqoute() to
preprocess diagnositics output.

11 years agoFix hash ordering dependency in DBM_Filter/t/int32.t
Yves Orton [Wed, 29 Aug 2012 07:47:03 +0000 (09:47 +0200)]
Fix hash ordering dependency in DBM_Filter/t/int32.t

Under the filtering rules in place undef() and "" and 0 map to a
packed representation of 0.

In the StoreData call we pass in an anonymous perl (untied) hash
containing an "undef" key (which is actually treated as "") with a
value of undef(), along with a key 0 with a value of 1. This hash
will store both values as distinct key/value pairs.

When this hash is used to set up the *tied* %h1 hash both the "" key
and the 0 key will be converted into the same packed value "\0\0\0\0",
which means that whichever is last in the each() of the input hashref
will be the one stored in %h1.

This means the test breaks if we change the PL_hash_seed or the hash
implementation in such a way that "" comes before 0 in the keys of
the hash.

This patch changes the input test hash to verify that undef() => 1 is
treated the same as 0 => 1, and eliminates the potential key collision.
The reason this test was reliable in the wild is that pretty well all
perls use a 0 hash seed and the same hash function.

This test probably would have broken in other enviornments as well.

11 years agofix hash key ordering dependency in t/warnings.t
Yves Orton [Mon, 27 Aug 2012 06:52:51 +0000 (08:52 +0200)]
fix hash key ordering dependency in t/warnings.t

Hash seed randomization causes these tests to fail occasionally.

11 years agofix a hash order dependency in t/re_funcs_u.t
Yves Orton [Tue, 28 Aug 2012 07:23:15 +0000 (09:23 +0200)]
fix a hash order dependency in t/re_funcs_u.t

11 years agofix hash order dependency in ext/B/t/b.t
Yves Orton [Mon, 27 Aug 2012 06:53:54 +0000 (08:53 +0200)]
fix hash order dependency in ext/B/t/b.t

Hash seed randomization causes these tests to fail occasionally.

11 years agofix a very subtle hash ordering dependency in op/smartkve.t
Yves Orton [Tue, 28 Aug 2012 08:15:40 +0000 (10:15 +0200)]
fix a very subtle hash ordering dependency in op/smartkve.t

Currently our hash implementation is order dependent on insertion.

When two keys collide and have to be stored in the same bucket the
order in which they are inserted into the hash will govern the order
in which they are fetched out by things like keys() and values().

This means that a copy of such a hash may be different. It is possible
this can be fixed with a low cost, but until then you cannot rely on
two hashes with the same keys having the same ordering of those keys

Depending on the hash algorithm and the seed values used this test
would fail. By changing it so there is one initial hash and then all
tests are done on copies of that hash we avoid the problem.

11 years agofix hash key ordering dependency in t/op/defins.t
Yves Orton [Mon, 27 Aug 2012 06:51:39 +0000 (08:51 +0200)]
fix hash key ordering dependency in t/op/defins.t

These tests break if we change the hash function or
randomly initialize the hash seed.

11 years agoperl5180delta: List mods broken by padlist changes
Father Chrysostomos [Fri, 26 Oct 2012 01:11:11 +0000 (18:11 -0700)]
perl5180delta: List mods broken by padlist changes

that have at least five dependents.

11 years agoRe-enable static op allocation with obslab
Reini Urban [Sun, 21 Oct 2012 23:56:11 +0000 (18:56 -0500)]
Re-enable static op allocation with obslab

obslab and the removal of the op_latefree logic, which allowed static
ops, removed support for the compiler modules, which allocates ops statically.
Add an op_static flag to replace the old latefree(d) op_free logic.

11 years agooptimize memory wrap croaks, often used in MEM_WRAP_CHECK
Daniel Dragan [Wed, 24 Oct 2012 20:15:51 +0000 (16:15 -0400)]
optimize memory wrap croaks, often used in MEM_WRAP_CHECK

Most perls are built with PERL_MALLOC_WRAP. This causes MEM_WRAP_CHECK
macro to perform some checks on the requested allocation size in macro
Newx. The checks are performed at the caller, not in the callee (for me
on Win32 perl the callee in Newx is Perl_safesysmalloc) of Newx.
If the check fails a "Perl_croak_nocontext("%s",PL_memory_wrap)" is done.
In x86 machine code,
"if(bad_alloc) Perl_croak_nocontext("%s",PL_memory_wrap); will be written
as "cond jmp ahead ~15 bytes", "push const pointer", "push const pointer",
"call const pointer". For each Newx where the allocation amount was not a
constant (constant folding would remove the croak memory wrap branch
compleatly), the branch takes 15-19 bytes depending on x86 compiler. There
are about 80 Newx'es in the interp (win32 dynamic linking perl) that do
the memory wrap check and have a
"Perl_croak_nocontext("%s",PL_memory_wrap)" in them after all optimizations
by the compiler.

This patch reduces the memory wrap branch from 15-19 to
5 bytes on x86. Since croak_memory_wrap is a static and a noreturn, a
compiler with IPO may optimize the whole branch to "cond jmp 32 bits
relative" at each callsite. A less optimal complier may do "cond jmp 8 bits
relative (jump past the "call S_croak_memory_wrap" instruction),
then "call S_croak_memory_wrap". Both ways are better than the current
situation. The reason why croak_memory_wrap is a static and not an export
is that the compiler has more opportunity to optimize/reduce the impact of
the memory wrap branch at the call site if the target is in the same image
rather than in a different image, which would require using the platform
specific dynamic linking mechanism/export table/etc, which often requires
a new stack frame per ABI of the platform. If a dynamic linked XS module
does not use S_croak_memory_wrap it will be removed from the image by the
C compiler. If it is included in the XS image, it is a very small block
of code and a 3 byte string litteral. A CPU cache line is typically
32 or 64 bytes and a memory read is typically 16. Cutting the
instructions by 10 to 16 bytes out of "hot code" (10 of the ~80 call
sites are pp_*) is a worthy goal. In a few places the memory wrap croak is
used explictly, not from a MEM_WRAP_CHECK, this patch converts those to use
the static. If PERL_MALLOC_WRAP is undef, there are still a couple uses of
croak memory wrap, so do not keep S_croak_memory_wrap in a ifdef
PERL_MALLOC_WRAP. Also see
http://www.nntp.perl.org/group/perl.perl5.porters/2012/10/msg194383.html
and [perl #115456].

11 years ago[perl #115440] Fix various leaks with fatal FETCH
Father Chrysostomos [Thu, 25 Oct 2012 20:00:55 +0000 (13:00 -0700)]
[perl #115440] Fix various leaks with fatal FETCH

Various pieces of code were creating an SV and then assigning to it
from a value that might be magical.  If the source scalar is magical,
it could die when magic is called, leaking the scalar that would have
been assigned to.

So we call get-magic before creating the new scalar, and then use a
non-magical assignment.

Also, anonhash and anonlist were doing nothing to protect the aggre-
gate if an argument should die on FETCH, resulting in a leak.