This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
4 years agoGet dist/Devel-PPPort/t/uv.t passing
Steve Hay [Sat, 20 Jul 2019 18:23:44 +0000 (19:23 +0100)]
Get dist/Devel-PPPort/t/uv.t passing

4 years agoModule::CoreList 5.20190720 is now on CPAN
Steve Hay [Sat, 20 Jul 2019 18:18:35 +0000 (19:18 +0100)]
Module::CoreList 5.20190720 is now on CPAN

4 years agoUpdate Module::CoreList for 5.31.3
Steve Hay [Sat, 20 Jul 2019 17:42:47 +0000 (18:42 +0100)]
Update Module::CoreList for 5.31.3

4 years agoBump version to 5.31.3
Steve Hay [Sat, 20 Jul 2019 17:34:21 +0000 (18:34 +0100)]
Bump version to 5.31.3

4 years agoCreate new perldelta for 5.31.3
Steve Hay [Sat, 20 Jul 2019 17:24:37 +0000 (18:24 +0100)]
Create new perldelta for 5.31.3

4 years agoTick off 5.31.2
Steve Hay [Sat, 20 Jul 2019 17:23:13 +0000 (18:23 +0100)]
Tick off 5.31.2

4 years agoAdd epigraph for 5.31.2
Steve Hay [Sat, 20 Jul 2019 17:22:58 +0000 (18:22 +0100)]
Add epigraph for 5.31.2

4 years ago5.31.2 today v5.31.2
Steve Hay [Sat, 20 Jul 2019 12:04:34 +0000 (13:04 +0100)]
5.31.2 today

4 years agoFinalize perldelta
Steve Hay [Sat, 20 Jul 2019 12:01:46 +0000 (13:01 +0100)]
Finalize perldelta

4 years agoUpdate Module::CoreList for 5.31.2
Steve Hay [Sat, 20 Jul 2019 11:52:53 +0000 (12:52 +0100)]
Update Module::CoreList for 5.31.2

4 years agoperldelta tidy-ups
Steve Hay [Sat, 20 Jul 2019 11:06:42 +0000 (12:06 +0100)]
perldelta tidy-ups

4 years agoVC6 support is likely to be removed soon
Steve Hay [Sat, 20 Jul 2019 10:55:24 +0000 (11:55 +0100)]
VC6 support is likely to be removed soon

4 years agoperldelta - Document a couple more changes
Steve Hay [Sat, 20 Jul 2019 10:54:44 +0000 (11:54 +0100)]
perldelta - Document a couple more changes

4 years agoNo need to list CUSTOMIZED files for anything but upstream=>CPAN modules
Steve Hay [Sat, 20 Jul 2019 10:36:12 +0000 (11:36 +0100)]
No need to list CUSTOMIZED files for anything but upstream=>CPAN modules

The vast majority of upstream=>BLEAD modules having modifications over the
given CPAN release aren't listed in Maintainers.pl. Net::Ping was the only
anomaly, and was out of date too -- t/001_new.t and t/010_pingecho.t are
also modified but weren't listed.

4 years agoRevert the Module::CoreList part of 7872aa47f6
Steve Hay [Sat, 20 Jul 2019 10:27:11 +0000 (11:27 +0100)]
Revert the Module::CoreList part of 7872aa47f6

5.31.1 contained B::Op_private 5.031001 and Module::CoreList* 5.20190620

4 years agoRevert the Module::CoreList part of e01077d94e
Steve Hay [Sat, 20 Jul 2019 10:20:51 +0000 (11:20 +0100)]
Revert the Module::CoreList part of e01077d94e

5.15.0 contained CGI::Util 3.53
5.21.7 contained File::Spec 3.53
5.31.1 contained Devel::PPPort 3.53

4 years agoperldelta - Remove boilerplate stuff
Steve Hay [Sat, 20 Jul 2019 10:00:32 +0000 (11:00 +0100)]
perldelta - Remove boilerplate stuff

4 years agoperldelta - Documentation and Diagnostics
Steve Hay [Sat, 20 Jul 2019 09:50:51 +0000 (10:50 +0100)]
perldelta - Documentation and Diagnostics

4 years agoperldelta - Modules and Pragmata
Steve Hay [Sat, 20 Jul 2019 09:43:32 +0000 (10:43 +0100)]
perldelta - Modules and Pragmata

4 years agoDocument known problems on Windows
Steve Hay [Fri, 19 Jul 2019 21:08:55 +0000 (22:08 +0100)]
Document known problems on Windows

4 years agoFix upgrade notes in INSTALL
Steve Hay [Fri, 19 Jul 2019 20:06:09 +0000 (21:06 +0100)]
Fix upgrade notes in INSTALL

Each BLEAD release is potentially not binary compatible with the previous
release.

4 years agoRMG - Fix a couple of typos
Steve Hay [Fri, 19 Jul 2019 20:01:03 +0000 (21:01 +0100)]
RMG - Fix a couple of typos

4 years agoConfig::Perl::V is ahead of CPAN
Steve Hay [Fri, 19 Jul 2019 19:55:09 +0000 (20:55 +0100)]
Config::Perl::V is ahead of CPAN

4 years agoCorrect an epigraph link
Steve Hay [Fri, 19 Jul 2019 19:54:25 +0000 (20:54 +0100)]
Correct an epigraph link

4 years agoFill in missing epigraphs links
Steve Hay [Thu, 18 Jul 2019 19:52:48 +0000 (20:52 +0100)]
Fill in missing epigraphs links

4 years ago(perl #134221) MSVC doesn't define O_ACCMODE
Tony Cook [Fri, 19 Jul 2019 00:08:30 +0000 (10:08 +1000)]
(perl #134221) MSVC doesn't define O_ACCMODE

4 years agoperldelta for ae73d7ec2329, 0424723402ef, 74b421cc877e
Tony Cook [Tue, 16 Jul 2019 06:30:58 +0000 (16:30 +1000)]
perldelta for ae73d7ec23290424723402ef74b421cc877e

4 years ago(perl #134221) preserve O_APPEND for open ... undef calls.
Tony Cook [Tue, 16 Jul 2019 05:59:29 +0000 (15:59 +1000)]
(perl #134221) preserve O_APPEND for open ... undef calls.

For most systems this means switching from mkstemp() to mkostemp(),
which Zefram helpfully added an emulation for.

For Win32 the append seems to happen in the POSIX emulation, not in
WriteFile(), so we can simply supply the flags to _open_osfhandle().

After some discussion with Craig Berry, the VMS version of the code
now uses largely the same mkostemp() code, with some special code in
the mkostemp() emulation to allow marking the file to be deleted
automatically when closed.

4 years ago(perl #134221) support O_APPEND for open ..., undef on VMS
Tony Cook [Mon, 15 Jul 2019 01:53:23 +0000 (11:53 +1000)]
(perl #134221) support O_APPEND for open ..., undef on VMS

VMS doesn't allow you to delete an open file like POSIXish systems
do, but you can mark a file to be deleted once it's closed, but
only when you open it.

Since VMS doesn't (yet) have mkostemp() we can add our own flag to
our mkostemp() emulation to pass the necessary magic to open() call
to delete the file on close.

4 years ago(perl #134221) support append mode temp files on Win32 too
Tony Cook [Tue, 2 Jul 2019 05:22:26 +0000 (15:22 +1000)]
(perl #134221) support append mode temp files on Win32 too

4 years ago(perl #134221) support append mode for open .. undef
Tony Cook [Tue, 2 Jul 2019 04:16:35 +0000 (14:16 +1000)]
(perl #134221) support append mode for open .. undef

4 years agoUpdate IPC-Cmd to CPAN version 1.04
Chris 'BinGOs' Williams [Sun, 14 Jul 2019 14:40:03 +0000 (15:40 +0100)]
Update IPC-Cmd to CPAN version 1.04

  [DELTA]

1.04 Sat Jul 13 10:08:08 BST 2019

  Bug fixes:
  - Fixed usage of setsid()

4 years agoSupport Bison version 3.1 through 3.4
Dagfinn Ilmari Mannsåker [Thu, 11 Jul 2019 15:27:29 +0000 (16:27 +0100)]
Support Bison version 3.1 through 3.4

No significant changes in the generated code since 3.0.

4 years agoPerlIO-encoding/t/encoding.t: improve test skip
David Mitchell [Thu, 11 Jul 2019 14:40:03 +0000 (15:40 +0100)]
PerlIO-encoding/t/encoding.t: improve test skip

One test is skipped if $PERL_DESTRUCT_LEVEL is set and its a DEBUGGING
build, as it produces a spurious "Unbalanced string table" warning.

However, this warning is emitted on non-DEBUGGING builds too: It's just
that until a couple of weeks ago, $PERL_DESTRUCT_LEVEL wasn't honoured
on non-DEBUGGING builds, so this was never spotted.

4 years agothreads::shared: fix leak
David Mitchell [Thu, 11 Jul 2019 14:17:48 +0000 (15:17 +0100)]
threads::shared: fix leak

When assigning a shared reference value to a variable containing a
shared string, the PV buffer in the shared space was leaked. For
example:

    my $s :shared = "foo";
    my $t :shared  = shared_clone(\"bar");
    $s = $t; # "foo" in shared space leaked

This was showing up as failed smokes under ASan.

4 years agoCorrect typo in POSIX.pod
James E Keenan [Wed, 10 Jul 2019 02:33:42 +0000 (22:33 -0400)]
Correct typo in POSIX.pod

For RT #134272, as suggested by Paul Townsend.

4 years agoavoid SEGV with uninit warning with multideref
David Mitchell [Wed, 10 Jul 2019 11:59:06 +0000 (12:59 +0100)]
avoid SEGV with uninit warning with multideref

RT #134275

When the 'uninitialized warning' code in S_find_uninit_var() comes
across an OP_MULTIDEREF node, it scans it to see if any part of that op
(e.g. the indices or the returned value) could have been the source of
the uninitialized value which triggered the warning.  Unfortunately when
getting an AV or HV from a GV, it wasn't checking whether gp_av/gp_hv
contained a NULL value. If so, it would SEGV.

The test code is a bit contrived; you have to "pull the rug" from under
the GV at just the right moment with *foo = *bar, then trigger an uninit
warning on an op whose subtree includes an OP_MULTIDEREF.

4 years agoAllow -Uusedtrace / -Dusedtrace=false / -Dusedtrace=no
H.Merijn Brand [Tue, 9 Jul 2019 15:16:04 +0000 (17:16 +0200)]
Allow -Uusedtrace / -Dusedtrace=false / -Dusedtrace=no

4 years agopp_sys.c: fix the position of HAS_SETNETENT definement
Alexandr Savca [Thu, 4 Jul 2019 11:55:38 +0000 (14:55 +0300)]
pp_sys.c: fix the position of HAS_SETNETENT definement

Else, DIE() will bever be executed.

4 years agoperldelta for 2773b4f50f99
Tony Cook [Tue, 9 Jul 2019 04:51:03 +0000 (14:51 +1000)]
perldelta for 2773b4f50f99

4 years agoRevert "postpone perl_parse() exit(0) bugfix"
Tony Cook [Thu, 4 Jul 2019 05:02:46 +0000 (15:02 +1000)]
Revert "postpone perl_parse() exit(0) bugfix"

This reverts commit 857320cbf85e762add18885ae8a197b5e0c21b69,
re-instating the [perl #2754] fix, which was reverted in late
2017 to allow Module::Install based distributions to update or
re-work per [perl #132577].

# Conflicts:
# t/op/blocks.t

4 years agomake apidoc error reporting a little more explicit
Tony Cook [Mon, 8 Jul 2019 05:39:26 +0000 (15:39 +1000)]
make apidoc error reporting a little more explicit

4 years ago(perl #120841) document some errno macros for internal use
Tony Cook [Thu, 4 Jul 2019 01:12:20 +0000 (11:12 +1000)]
(perl #120841) document some errno macros for internal use

4 years ago(perl #120841) document ERRSV and CLEAR_ERRSV()
Tony Cook [Thu, 4 Jul 2019 00:39:19 +0000 (10:39 +1000)]
(perl #120841) document ERRSV and CLEAR_ERRSV()

4 years agoperldelta for fb81daf0179f, 66ff4fb58270
Tony Cook [Mon, 8 Jul 2019 01:56:27 +0000 (11:56 +1000)]
perldelta for fb81daf0179f66ff4fb58270

4 years agouse hex for the call_*()/eval_sv() flag definitions
Tony Cook [Mon, 24 Jun 2019 00:01:42 +0000 (10:01 +1000)]
use hex for the call_*()/eval_sv() flag definitions

while I expect most C programmers have these powers of two engraved
into their brains, using hex makes this more obvious

4 years ago(perl #134177) add G_RETHROW flag to eval_sv()
Tony Cook [Thu, 20 Jun 2019 05:26:22 +0000 (15:26 +1000)]
(perl #134177) add G_RETHROW flag to eval_sv()

and update eval_pv() to use it.

4 years agoCommit df09255f was by new contributor
James E Keenan [Sat, 6 Jul 2019 22:31:35 +0000 (18:31 -0400)]
Commit df09255f was by new contributor

Update AUTHORS to keep make test_porting happy.

4 years agoPVS-Studio: fixed warning in ternary operator.
Svyatoslav [Fri, 5 Oct 2018 14:16:54 +0000 (17:16 +0300)]
PVS-Studio: fixed warning in ternary operator.

(from https://github.com/Perl/perl5/pull/17)

4 years agomake variable names consistent in this example
Karen Etheridge [Fri, 5 Jul 2019 21:02:06 +0000 (14:02 -0700)]
make variable names consistent in this example

..as suggested by Andre Schultz at https://github.com/OpusVL/perldoc.perl.org/issues/57

4 years agoFix "it it" typos
Dagfinn Ilmari Mannsåker [Thu, 4 Jul 2019 10:19:45 +0000 (11:19 +0100)]
Fix "it it" typos

And regen affected files

4 years agoUpdate META.json following JSON::PP update
Steve Hay [Thu, 4 Jul 2019 07:22:12 +0000 (08:22 +0100)]
Update META.json following JSON::PP update

4 years agoUpdate Pod::Simple from version 3.38 to 3.39
Steve Hay [Wed, 3 Jul 2019 12:57:52 +0000 (13:57 +0100)]
Update Pod::Simple from version 3.38 to 3.39

4 years agoUpdate JSON::PP from version 4.02 to 4.04
Steve Hay [Wed, 3 Jul 2019 12:55:33 +0000 (13:55 +0100)]
Update JSON::PP from version 4.02 to 4.04

4 years agoperldelta: fix typo
David Mitchell [Thu, 4 Jul 2019 06:00:23 +0000 (07:00 +0100)]
perldelta: fix typo

4 years agoperldelta entry for v5.31.1-101-g5c696bd319
David Mitchell [Wed, 3 Jul 2019 20:16:53 +0000 (21:16 +0100)]
perldelta entry for v5.31.1-101-g5c696bd319

4 years agoPrint a more helpful UNREACHABLE message when NOT_REACHED assertion fails
Paul "LeoNerd" Evans [Wed, 3 Jul 2019 16:19:10 +0000 (17:19 +0100)]
Print a more helpful UNREACHABLE message when NOT_REACHED assertion fails

4 years agoutf8_to_uvchr_buf() make behavior match docs
Karl Williamson [Sat, 29 Jun 2019 05:57:31 +0000 (23:57 -0600)]
utf8_to_uvchr_buf() make behavior match docs

For well formed input, there is no change.  But for malformed it wasn't
returning the documented length when warnings were enabled, and not
always the documented value when they were disabled.

This is implemented as an inline function, called from both the macro
and the Perl_ form.

Devel::PPPort has sufficient tests for this.

4 years agoperl.h: Add a comment about tainting
Karl Williamson [Thu, 18 Apr 2019 16:10:41 +0000 (10:10 -0600)]
perl.h: Add a comment about tainting

4 years ago(perl #134187) how do we know it's a Turkic locale
Tony Cook [Thu, 27 Jun 2019 01:48:25 +0000 (11:48 +1000)]
(perl #134187) how do we know it's a Turkic locale

Not by name.

4 years agoperldelta for c0ad3f089909e
Tony Cook [Mon, 1 Jul 2019 01:36:05 +0000 (11:36 +1000)]
perldelta for c0ad3f089909e

4 years ago(perl #134218) make sure ECHO is defined
Tony Cook [Thu, 27 Jun 2019 05:00:47 +0000 (15:00 +1000)]
(perl #134218) make sure ECHO is defined

This is used in dtrace rules originally needed on FreeBSD,
which appears to define ECHO to echo by default for Makefiles.

But this isn't the case for Solaris-derived system makes.

4 years agoPATCH: [perl #133996] reword diagnostic
Karl Williamson [Thu, 27 Jun 2019 17:09:43 +0000 (11:09 -0600)]
PATCH: [perl #133996] reword diagnostic

4 years agoAdd some defensive coding to av_store()
Karl Williamson [Sat, 1 Jun 2019 20:39:55 +0000 (14:39 -0600)]
Add some defensive coding to av_store()

Don't decrement the reference count of the element about to be stored
into.

Likely, this is an error in the caller, but doing this action blindly is
like shooting yourself in the foot.  The branch prediction also added
ensures this shouldn't slow things down.

See http://nntp.perl.org/group/perl.perl5.porters/254974

4 years agoperldelta for 1ef28cc363ae
Tony Cook [Thu, 27 Jun 2019 00:35:57 +0000 (10:35 +1000)]
perldelta for 1ef28cc363ae

4 years ago(perl #134125) make no digits after 0x/0b fatal
Tony Cook [Thu, 20 Jun 2019 01:06:13 +0000 (11:06 +1000)]
(perl #134125) make no digits after 0x/0b fatal

My original change in 7259f4194 silently adjusted the parse
position to immediately after the 0 in an incomplete hex or binary
literal.  In most cases this leads to a syntax error, but in some
cases, especially with 0x, this can lead to a silent change in
behaviour.

So throw an error instead.

4 years agoClean up after previous commit
Dagfinn Ilmari Mannsåker [Wed, 26 Jun 2019 23:17:52 +0000 (00:17 +0100)]
Clean up after previous commit

- Two empty lines betwen tests
- Remove unused $err variable

4 years agoFix leading spaces in Exporter error message
Dagfinn Ilmari Mannsåker [Wed, 26 Jun 2019 16:56:06 +0000 (17:56 +0100)]
Fix leading spaces in Exporter error message

The second and subsequent lines when trying to import non-existent
items had a leading space (or whatever $" happened to be).

4 years agoregcomp.h: Use actual commit number
Karl Williamson [Wed, 26 Jun 2019 15:06:21 +0000 (09:06 -0600)]
regcomp.h: Use actual commit number

This referred to the commit message, but now that the number has been
determined, use that.

4 years agoAdd ANYOFHr regnode
Karl Williamson [Wed, 5 Jun 2019 17:15:00 +0000 (11:15 -0600)]
Add ANYOFHr regnode

This commit adds a new regnode, ANYOFHr, like ANYOFH, but it also has a
loose upper bound for the first UTF-8 byte matchable by the node.  (The
'r' stands for 'range').  It would be nice to have a tight upper bound,
but to do so requires 4 more bits than are available without changing
the node arguments types, and hence increasing the node size.  Having a
loose bound is better than no bound, and comes essentially free, by
using two unused bits in the current ANYOFH node, and requiring only a
few extra, pipeline-able, mask, etc instructions at run time, no extra
conditionals.  Any ANYOFH nodes that would benefit from having an upper
bound will instead be compiled into this node type.

Its use is based on the following observations.

There are 64 possible start bytes, so the full range can be expressed in
6 bits.  This means that the flags field in ANYOFH nodes containing the
start byte has two extra bits that can be used for something else.

An ANYOFH node only happens when there is no matching code point in the
bit map, so the smallest code point that could be is 256.  The start
byte for that is C4, so there are actually only 60 possible start bytes.
(perl can be compiled with a larger bit map in which case the minimum
start byte would be even higher.)

A second observation is that knowing the highest start byte is above F0
is no better than knowing it's F0.  This is because the highest code
point whose start byte is F0 is U+3FFFF, and all code points above that
that are currently allocated are all very specialized and rarely
encountered.  And there's no likelihood of that changing anytime soon as
there's plenty of unallocated space below that.  So if an ANYOFH node's
highest start byte is F0 or above, there's no advantage to knowing what
the actual max possible start byte is, so leave it as ANYOFH,.

That means the highest start byte we care about in ANYOFHr is EF.  That
cuts the number of start bytes we care about down to 43, still 6 bits
required to represent them, but it allows for the following scheme:

Populate the flags field by subtracting C0 from the lowest start byte
and shift left 2 bits.  That leaves the the bottom two bits unused.
We use them as follows, where x is the start byte of the lowest code
point in the node:

bits
----
11  The upper limit of the range can be as much as (EF - x) / 8
10  The upper limit of the range can be as much as (EF - x) / 4
01  The upper limit of the range can be as much as (EF - x) / 2
00  The upper limit of the range can be as much as  EF

That partitions the loose upper bound into 4 possible ranges, with it
being tighter the closer it is to the strict lower bound.  This makes
the loose upper bound more meaningful when there is most to gain by
having one.

Some examples of what the various upper bounds would be for all the
possibilities of these two bits are:
           Upper bound given the 2 bits
Low bound  11 10 01 00
---------  -- -- -- --
C4         C9 CE D9 EF
D0         D3 D7 DF EF
E0         E1 E3 E7 EF

Start bytes of E0 and above represent many more code points each than
lower ones, as they are 3 byte sequences instead of two.  This scheme
provides tighter bounds for them, which is also a point in its favor.

Thus we have provided a loose upper bound using two otherwise unused
bits.  An alternate scheme could have had the intervals all the same,
but this provides a tighter bound when it makes the most sense to.

For EBCDIC the range is is from C8 to F4,

Tests will be added in a later commit

4 years agoregex: Add lower bound to ANYOFH nodes UTF-8 byte
Karl Williamson [Tue, 4 Jun 2019 18:16:10 +0000 (12:16 -0600)]
regex: Add lower bound to ANYOFH nodes UTF-8 byte

This commit adds a lower bound for the first UTF-8 byte matchable by an
ANYOFH node.  The flags field is otherwise unused, and using it for this
purpose allows code to rule out match possibilities without having to
convert from UTF-8 to code point.

It might be better to do the inverse instead, to have the field be an
upper bound.  The reason is that the conversion is cheap for smaller
numbers.  The commit following mostly addresses this.

4 years agoUse inRANGE for seeing if node is an ANYOFH type
Karl Williamson [Tue, 4 Jun 2019 17:43:17 +0000 (11:43 -0600)]
Use inRANGE for seeing if node is an ANYOFH type

This is easier to read, especially when a third type is added a few
commits ahead.

4 years ago(perl #122112) make sure SIGPIPE is delivered if we test it
Tony Cook [Tue, 25 Jun 2019 05:47:57 +0000 (15:47 +1000)]
(perl #122112) make sure SIGPIPE is delivered if we test it

4 years agoWhite space only in comment
Karl Williamson [Tue, 4 Jun 2019 18:31:03 +0000 (12:31 -0600)]
White space only in comment

4 years agoregcomp.sym: Change regnode description
Karl Williamson [Wed, 5 Jun 2019 17:15:51 +0000 (11:15 -0600)]
regcomp.sym: Change regnode description

Simplify the description for ANYOFb

4 years agoAdditional Net-Ping tests skip if d_getpbyname is undef
Richard Leach [Sun, 19 May 2019 03:34:38 +0000 (03:34 +0000)]
Additional Net-Ping tests skip if d_getpbyname is undef

4 years agoTests for Android stub functions updated for Oreo
Richard Leach [Sun, 19 May 2019 03:27:56 +0000 (03:27 +0000)]
Tests for Android stub functions updated for Oreo

4 years agoFix apidoc macro entries
Karl Williamson [Tue, 25 Jun 2019 14:40:05 +0000 (08:40 -0600)]
Fix apidoc macro entries

This makes various fixes to the text that is used to generate the
documentation.  The dominant change is to add the 'n' flag to indicate
that the macro takes no arguments.  A couple should have been marked
with a D (for deprecated) flag, and a couple were missing parameters,
and a couple were missing return values.

These were spotted by using Devel::PPPort on them.

4 years agohonour $PERL_DESTRUCT_LEVEL on non-debug builds
David Mitchell [Mon, 24 Jun 2019 12:00:25 +0000 (13:00 +0100)]
honour $PERL_DESTRUCT_LEVEL on non-debug builds

This environment variable was previously only checked for on DEBUGGING
builds.

4 years agoFix erroneous references to USE_CBACKTRACE
Steve Hay [Mon, 24 Jun 2019 19:47:26 +0000 (20:47 +0100)]
Fix erroneous references to USE_CBACKTRACE

The #define set in Configure and used in locale.c and util.c is actually
USE_C_BACKTRACE.

Pointed out by NormW in
https://www.nntp.perl.org/group/perl.perl5.porters/2018/04/msg250441.html

4 years ago[MERGE] make optree-walking mostly non-recursive
David Mitchell [Mon, 24 Jun 2019 10:40:30 +0000 (11:40 +0100)]
[MERGE] make optree-walking mostly non-recursive

This branch updates many of the functions in op.c which recursively
walk an op tree during compilation.  This avoids SEGVs from stack
overflow when the op tree is deeply nested, such as
    $n == 1 ? "one" : $n == 2 ? "two" : ....
(especially in code which is auto-generated)

This is particularly noticeable where the code is compiled within a
separate thread, as threads tend to have small stacks by default.

Some functions already avoided recursion by mallocing a buffer
containing a list of ops to visit, but this could be leaked if the code
died during compilation.

Making the functions non-recursive is a lot easier now that the last
node in each OpSIBLING chain holds a pointer back to the parent node.
Where the function needs to recursively visit *every* node, its just a
case of following each child link, then every OpSIBLING link then the
parent link. Where the recursion is more selective, it becomes more
tricky. In some cases I have followed the policy that a node has N kids
and kids I..N need visiting, then start at I and iterate as usual; but
if just kids I and J  needs visiting (but not J+1..N), then do old-style
recursion on nodes I and J. These cases are hopefully rare.

4 years agoPerl_op_lvalue_flags(): make mostly non-recursive
David Mitchell [Fri, 14 Jun 2019 10:26:37 +0000 (11:26 +0100)]
Perl_op_lvalue_flags(): make mostly non-recursive

Recursion is left in a few places where is necessary to call itself
with a different value for 'type'.

4 years agoPerl_op_lvalue_flags() add blank lines
David Mitchell [Wed, 12 Jun 2019 11:03:52 +0000 (12:03 +0100)]
Perl_op_lvalue_flags() add blank lines

... between switch cases for readability.

4 years agoPerl_op_lvalue_flags(): skip OPf_WANT_VOID ops.
David Mitchell [Wed, 12 Jun 2019 10:57:54 +0000 (11:57 +0100)]
Perl_op_lvalue_flags(): skip OPf_WANT_VOID ops.

Currently this function asserts that its 'o' argument is non-VOID;
later when recursing an OP_LIST, it skips any kids which are VOID.

This commit changes it so that the assert becomes a return, and
OP_LIST doesn't check whether its kids are VOID.

Doing it this way makes it easier to shortly make Perl_op_lvalue_flags()
non-recursive.

The only functional difference is that on debugging builds,
Perl_op_lvalue_flags() will no longer fail an assert if inadvertently
called with a VOID op.

4 years agoPerl_op_lvalue_flags(): fixup documentation
David Mitchell [Thu, 6 Jun 2019 12:32:25 +0000 (13:32 +0100)]
Perl_op_lvalue_flags(): fixup documentation

First, move the apidoc text for op_lvalue() to be directly above
Perl_op_lvalue_flags() (it had wandered).

Secondly, add a brief non-API note explaining what the extra 'flags'
parameter does

4 years agoreindent op.c:S_lvref()
David Mitchell [Thu, 6 Jun 2019 12:01:41 +0000 (13:01 +0100)]
reindent op.c:S_lvref()

...  after the previous commit wrapped most if it in a while loop.  Also
put a blank line after each switch case for readability.

4 years agomake op.c:S_lvref() non-recursive
David Mitchell [Thu, 6 Jun 2019 12:00:18 +0000 (13:00 +0100)]
make op.c:S_lvref() non-recursive

4 years agodocument what op.c:S_lvref() does
David Mitchell [Tue, 4 Jun 2019 12:41:21 +0000 (13:41 +0100)]
document what op.c:S_lvref() does

4 years agoop.c: S_lvref(): handle all kids on OP_NULL
David Mitchell [Tue, 4 Jun 2019 12:33:22 +0000 (13:33 +0100)]
op.c: S_lvref(): handle all kids on OP_NULL

For an OP_NULL, his function formerly recursed into *all* its kids
if was an ex-list, otherwise only the first one.

To simplify making this function non-recursive, make it so that it
unconditionally recurses into all the kids.

However for now, also add an assertion that a non ex-list OP_NULL
will only have one child at most. If we find some code which violates
this, then we can nmake a more informed decision as to whether
non ex-list OP_NULL's should have all, or only their first child
examined.

4 years agoClarify purpose of S_looks_like_bool()
David Mitchell [Fri, 31 May 2019 15:59:53 +0000 (16:59 +0100)]
Clarify purpose of S_looks_like_bool()

4 years agomake op.c:S_find_and_forget_pmops() non-recursive
David Mitchell [Fri, 31 May 2019 15:53:42 +0000 (16:53 +0100)]
make op.c:S_find_and_forget_pmops() non-recursive

For every CV that's freed which has a shared optree (e.g. a closure
or between threads), the whole optree is walked looking for PMOPs.
Make that walk non-recursive.

Contrived code that triggers a stack overflow:

{
    my $outer;
    my $e = 'sub { $outer && '
            . join('&&', ('$x') x 100_000)
            . " }";
    #print $e, "\n";
    eval $e;
}

Even after this commit, that code still SEGVs due to a separate stack
blow in Perl_rpeep().

4 years agoPerl_doref(): reindent
David Mitchell [Fri, 31 May 2019 15:02:19 +0000 (16:02 +0100)]
Perl_doref(): reindent

Previous commit added a while loop.

4 years agoPerl_doref(): make non-recursive
David Mitchell [Fri, 31 May 2019 10:58:11 +0000 (11:58 +0100)]
Perl_doref(): make non-recursive

This stops the following code from SEGVing for example:

    my $e = "\$r";
    $e = "+do{$e}" for 1..70_000;
    $e = "push \@{$e}, 1";
    eval $e;

Similarly with a long

    $a[0][0][0][0].....

This commit causes a slight change in behaviour, in that scalar(o)
is now only called once at the end of the top-level doref() call,
rather than at the end of processing each child. This should make no
functional difference, apart from speeding up compiling infinitesimally.

4 years agodocument what Perl_doref does
David Mitchell [Fri, 31 May 2019 09:27:25 +0000 (10:27 +0100)]
document what Perl_doref does

4 years agomake op.c:S_aassign_scan() non-recursive
David Mitchell [Thu, 30 May 2019 13:22:09 +0000 (14:22 +0100)]
make op.c:S_aassign_scan() non-recursive

With this commit and some previous ones, the following code no longer
blows the stack:

    my $e = "1";
    $e = "do { \$x; $e}" for 1..100_000;
    $e = "\@x = $e";
    eval $e;

4 years agomake Perl_op_linklist() non-recursive
David Mitchell [Wed, 29 May 2019 14:57:06 +0000 (15:57 +0100)]
make Perl_op_linklist() non-recursive

4 years agoPerl_op_linklist(): use OPf_KIDS flags
David Mitchell [Wed, 29 May 2019 14:03:42 +0000 (15:03 +0100)]
Perl_op_linklist(): use OPf_KIDS flags

This function just blindly assumes that cUNOPo->op_first is a valid
indication that the op has at least one child. This is successful *most*
of the time. Putting in an assertion caused t/op/lvref.t to fail.

Instead, check the OPf_KIDS flag.

4 years agoPerl_scalarvoid(): add comment saying what it does
David Mitchell [Wed, 29 May 2019 08:49:19 +0000 (09:49 +0100)]
Perl_scalarvoid(): add comment saying what it does

It applies void context, which isn't all that obvious just from the
name.

4 years agoop.c: S_search_const: remove recursion
David Mitchell [Tue, 28 May 2019 16:37:43 +0000 (17:37 +0100)]
op.c: S_search_const: remove recursion

There are a couple of places where this function recurses, but they
are both effectively tail recursion and can be easily eliminated.

4 years agoop.c: add code comments to S_search_const()
David Mitchell [Tue, 28 May 2019 16:25:33 +0000 (17:25 +0100)]
op.c: add code comments to S_search_const()

plus a few blank lines for readability.