This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
6 years agoremove unreferenced copies of char * swash_property_names[]
Daniel Dragan [Mon, 26 Feb 2018 02:31:26 +0000 (21:31 -0500)]
remove unreferenced copies of char * swash_property_names[]

Due to some MSVC bug or perl's not using MS specific CC options that I've
never figured out, MSVC does not remove unreferenced by a single .obj or
combine identical, static const data vars. MSVC funcs get removed &
combined correctly. Since for var swash_property_names removing it from
.objs that dont need it is very easy, do it. It saves some memory space.
Perhaps some other platforms/OSes/CCs have similar problems removing
unreferenced symbols from final binaries so this patch would help on those
CCs too.

regexec.c stopped using swash_property_names in commit 2a16ac9277 in 5.19.8
"regexec.c: Use compiled-in POSIX definitions"

regcomp.c stopped using swash_property_names in commit bcb875216f in 5.19.8
"regcomp.c: Rmv code for delayed 'til runtime POSIX defns"

with MSVC 2008 64, before

miniperl.exe disk file size 1761KB .rdata virtual size 0xBC354 bytes
perl527.dll disk file size 2040KB .rdata virtual size 0xC9421 bytes

after this commit

miniperl.exe disk file size 1761KB .rdata virtual size 0xBC2C4 bytes
perl527.dll disk file size 2040KB .rdata virtual size 0xC9381 bytes

~144 bytes saved by removing unused copies of swash_property_names array.

There are other cases of large duplicate static const data vars still in
the perl527.dll binary but this patch covers a very simple case.

6 years agowarnings.pm: _at_level functions and chunky handles
Father Chrysostomos [Mon, 26 Feb 2018 17:23:28 +0000 (09:23 -0800)]
warnings.pm: _at_level functions and chunky handles

The _at_level functions, which have to bypass Carp, were not
reporting non-line-based filehandles correctly.  The perl core
does:

    ..., <fh> chunk 7.

if $/ is not "\n".  warnings.pm should do the same.  It was using
‘line’.

6 years agoCarp: Avoid run-time mods; StrVal workarounds
Father Chrysostomos [Mon, 26 Feb 2018 09:23:53 +0000 (01:23 -0800)]
Carp: Avoid run-time mods; StrVal workarounds

Carp needs to avoid loading modules while reporting errors, because
it may be invoked via $SIG{__DIE__} after a syntax error, when BEGIN
blocks are forbidden.

Before this commit (as of v5.27.8-360-gc99363a) it was doing just that
for reference arguments within stack traces.

That means we either need to load overload.pm at start-up so that
overload::StrVal is already available, or avoid overload::StrVal
altogether.

It turns out that various versions of overload::StrVal have
their own problems that prevent Carp from using them (out-
lined in the comments added to Carp.pm and also described at
<https://rt.perl.org/Ticket/Display.html?id=132902#txn-1535564>).

So we now follow two approaches:  If overloading.pm is available, use
that; otherwise, use a hideous workaround inspired by ancient imple-
entations of overload::StrVal and Scalar::Util::blessed, while avoid-
ing the bugs in those old versions.

6 years agoop.h: remove spurious # define indent
David Mitchell [Tue, 27 Feb 2018 15:32:25 +0000 (15:32 +0000)]
op.h: remove spurious #  define indent

whitespace-only change

6 years agoext/File-Glob/t/rt131211.t: fix timing issues
David Mitchell [Tue, 27 Feb 2018 14:58:18 +0000 (14:58 +0000)]
ext/File-Glob/t/rt131211.t: fix timing issues

This test file occasionally fails test numbers 1 and/or 2 on smokes.
These two tests measure how long it takes to do a matching and
non-matching glob() with a lot of "a*a*a*...." and fail if the
match and non-matching times differ too much (the original bug was that
non-match went exponential on number of "a*"'s).

However, on good systems, the timings returned are typically
sub-millisecond, so I'm guessing the occasional failures are due to

(small measured noise) * 100  > (another small measured noise).

So this commit avoids tests 1&2 failing unless the values measured
are large enough not to be merely noise.

This is just speculation on my part though - I couldn't reproduce a
failure myself.

6 years ago(perl #127743) don't probe Storable limits so much (Win32 makefiles)
Tony Cook [Mon, 26 Feb 2018 23:50:35 +0000 (10:50 +1100)]
(perl #127743) don't probe Storable limits so much (Win32 makefiles)

Win32 port of the changes in 8175eebc32

6 years agoAPItest/t/locale.t: Add detail to test names
Karl Williamson [Mon, 26 Feb 2018 04:40:35 +0000 (21:40 -0700)]
APItest/t/locale.t: Add detail to test names

This detail can help in interpreting the results.

6 years agoFix Perl_langinfo currency symbol for non-nl_langinfo systems
Karl Williamson [Mon, 26 Feb 2018 04:28:42 +0000 (21:28 -0700)]
Fix Perl_langinfo currency symbol for non-nl_langinfo systems

Commit 628ff75a4a7ac013dad43df7a53fcb55bf758ed7 broke this.

6 years agosuppress error messages from the shell when probing Storable limits
Tony Cook [Mon, 19 Feb 2018 23:10:34 +0000 (10:10 +1100)]
suppress error messages from the shell when probing Storable limits

6 years agomake the Storable stacksize messages less scary
Tony Cook [Mon, 19 Feb 2018 23:09:44 +0000 (10:09 +1100)]
make the Storable stacksize messages less scary

6 years ago(perl #127743) don't probe Storable limits so much
Tony Cook [Mon, 26 Feb 2018 04:04:20 +0000 (15:04 +1100)]
(perl #127743) don't probe Storable limits so much

Previously any rebuild on the perl executable or the shared library
would re-run the Storable recursion limit probing.  Only do so
if the Storable binary or Storable.pm is rebuilt.

This needs to be ported to the Win32 makefiles too.

6 years ago[perl #132910] Carp: Avoid ->can
Father Chrysostomos [Mon, 26 Feb 2018 02:19:54 +0000 (18:19 -0800)]
[perl #132910] Carp: Avoid ->can

If a module has its own ‘can’ (or even UNIVERSAL::can) implementation,
it may impede Carp’s use of ->can to detect overloading.  Instead,
use UNIVERSAL::can directly, or, in the presence of an override,
use overload::mycan.  Don’t use overload::Overloaded, since old
versions of overload call ->can.

6 years agomove init_i18nl10n(1) to after the ENTER in perl_construct
Yves Orton [Mon, 26 Feb 2018 00:42:22 +0000 (01:42 +0100)]
move init_i18nl10n(1) to after the ENTER in perl_construct

init_i18nl10n(1) uses SAVEFREEPV, before any ENTER is performed. Move it afterwards

6 years agoRevert "Storable: when building in core do not run stacksize every time"
Yves Orton [Mon, 26 Feb 2018 00:40:19 +0000 (01:40 +0100)]
Revert "Storable: when building in core do not run stacksize every time"

This reverts commit 345db0f66ed0ac7b609bb6bcceaf3a48b5f8e25b.

6 years agoUpgrade ExtUtils::MakeMaker to 7.33_03
Father Chrysostomos [Sun, 25 Feb 2018 21:31:34 +0000 (13:31 -0800)]
Upgrade ExtUtils::MakeMaker to 7.33_03

6 years agosync-with-cpan: Allow relative dir for tarball
Father Chrysostomos [Sun, 25 Feb 2018 21:29:36 +0000 (13:29 -0800)]
sync-with-cpan: Allow relative dir for tarball

6 years agoFix Perl_langinfo() for non-nl_langinfo() systems
Karl Williamson [Sun, 25 Feb 2018 19:51:59 +0000 (12:51 -0700)]
Fix Perl_langinfo() for non-nl_langinfo() systems

Commit 628ff75a4a7ac013dad43df7a53fcb55bf758ed7 caused the return value
to not be set for some paths through the function on platforms, like
Windows, that don't have nl_langinfo()

6 years agolocale.c: Silence compiler warning
Karl Williamson [Sun, 25 Feb 2018 18:56:44 +0000 (11:56 -0700)]
locale.c: Silence compiler warning

The Windows compiler no longer raises a warning if we change this UV to
a plain unsigned.

6 years agolocale.c: Save needed value before destroying it
Karl Williamson [Sat, 24 Feb 2018 23:32:44 +0000 (16:32 -0700)]
locale.c: Save needed value before destroying it

This moves up the copying of a needed value to before the place where it
could get destroyed.  This only happened on some configurations under
some circumstances, which is why it got missed.

6 years agolocale.c: Let static fcn take a NULL argument
Karl Williamson [Sat, 24 Feb 2018 23:22:22 +0000 (16:22 -0700)]
locale.c: Let static fcn take a NULL argument

It turns out that it will be convenient in a future commit to have this
function handle NULL input.  That also means that every call should use
the return value of this function.

6 years agoStorable: when building in core do not run stacksize every time
Yves Orton [Sun, 25 Feb 2018 14:03:57 +0000 (15:03 +0100)]
Storable: when building in core do not run stacksize every time

6 years agoif an SV IsCOW_shared_hash then we can assume it has a null at the end
Yves Orton [Sun, 25 Feb 2018 13:29:03 +0000 (14:29 +0100)]
if an SV IsCOW_shared_hash then we can assume it has a null at the end

6 years agoCorrect (re)wording on defective HP-UX locales
H.Merijn Brand [Sun, 25 Feb 2018 15:57:33 +0000 (16:57 +0100)]
Correct (re)wording on defective HP-UX locales

6 years agoadd a svleak.t test for RT #132892
Yves Orton [Sun, 25 Feb 2018 09:46:48 +0000 (10:46 +0100)]
add a svleak.t test for RT #132892

This tests the change applied in
910a6a8be166fb3780dcd2520e3526e537383ef2

I tested that when that commit is reverted this test fails,
and when it is in place it does not.

6 years agoAllow goto into glob’s arg
Father Chrysostomos [Sun, 25 Feb 2018 01:47:25 +0000 (17:47 -0800)]
Allow goto into glob’s arg

$ ./perl -Ilib  -Xe 'goto foo; glob do { foo:  $1}'
Can't "goto" into a binary or list expression at -e line 1.

What binary or list expression?  True, glob has the *precedence* of a list operator, but so does not:

$ ./perl -Ilib  -Xe 'goto foo; not do { foo:  $1}; prt "ok\n"'
ok

Glob seems to be the only exception, due to its ‘special’ op tree.

6 years agoperlfunc:goto: Correct and clarify
Father Chrysostomos [Sun, 25 Feb 2018 01:43:26 +0000 (17:43 -0800)]
perlfunc:goto: Correct and clarify

6 years agolocale.c: Properly return LC_ALL locale names
Karl Williamson [Fri, 23 Feb 2018 18:13:09 +0000 (11:13 -0700)]
locale.c: Properly return LC_ALL locale names

On systems using POSIX 2008 functions that don't have querylocale(),
perl has to keep track of the locale names currently in effect.  There
was code to invalidate LC_ALL as a single name if one or more of its
components aren't all the same.  But omitted was code to re-validate it
when they later do become the same.  This commit adds that omitted code.

6 years agolocale.c: Fix dangling set of LC_NUMERIC to C
Karl Williamson [Fri, 23 Feb 2018 18:06:45 +0000 (11:06 -0700)]
locale.c: Fix dangling set of LC_NUMERIC to C

In the past, we've kept LC_NUMERIC in the C locale, because so much code
relies on the radix character being a dot.  5.27.9 added an enhancement
that checks if the current locale already has it be a dot.  If so, it's
fine to keep the locale in that one.

The spot fixed by this commit didn't get updated to account for this
change.

(I realize that the docs also need to be updated; that will be in a
future commit)

6 years agot/loc_tools.pl: 8859-16 is legit; 8859-0 isn't
Karl Williamson [Fri, 23 Feb 2018 18:02:40 +0000 (11:02 -0700)]
t/loc_tools.pl: 8859-16 is legit; 8859-0 isn't

This adjusts the loop boundaries looking for come common locale names.
It was failing to look for 8859-16; instead looking for latin0, 8859-0,
which don't exist

6 years agoperlapi: Clarify Perl_langinfo()
Karl Williamson [Fri, 23 Feb 2018 17:59:33 +0000 (10:59 -0700)]
perlapi: Clarify Perl_langinfo()

6 years agot/loc_tools.pl: Consider recently added warning
Karl Williamson [Fri, 23 Feb 2018 17:46:53 +0000 (10:46 -0700)]
t/loc_tools.pl: Consider recently added warning

This file has functions that look for and return the valid locales on
the current system.  A new incompatibility was discovered and a warning
generated for in 8b7358b96caf71db3213a7d72fc401e42ee0b2d.

This file should have been updated at that time to look for that message
to mean it the locale is not compatible.  This commit updates it.

6 years agoPerl_langinfo(): Need to save return under more circumstances
Karl Williamson [Fri, 23 Feb 2018 00:43:16 +0000 (17:43 -0700)]
Perl_langinfo(): Need to save return under more circumstances

I forgot that the internal static buffers returned from nl_langinfo()
and localconv() can be destroyed if the locale changes, and not just
from a subsequent call to the function.  Therefore save the results
always.

6 years agoCarp: add test for overloads without overload.pm
Yves Orton [Sun, 25 Feb 2018 03:15:23 +0000 (04:15 +0100)]
Carp: add test for overloads without overload.pm

6 years agoCarp: overloads can be enabled with via ::() as well as ::((
Yves Orton [Sun, 25 Feb 2018 03:07:15 +0000 (04:07 +0100)]
Carp: overloads can be enabled with via ::() as well as ::((

6 years agoexplain compile time effects of require
Yves Orton [Sun, 25 Feb 2018 03:04:02 +0000 (04:04 +0100)]
explain compile time effects of require

there is a difference between

   require Foo::Bar;

and

   require "Foo/Bar.pm";

in that the former will autovivify the Foo::Bar namespace at compile
time, but the latter will not. Populating the namespace is left to run
time in both cases.

This doc adds some details about this to the require entry in perlfunc

6 years agoSpelling correction.
James E Keenan [Sat, 24 Feb 2018 19:01:23 +0000 (14:01 -0500)]
Spelling correction.

Addresses https://github.com/mhx/Devel-PPPort/pull/50/files.

6 years agoPathTools/Changes: Retroactively mention CPAN RT #114236
Father Chrysostomos [Sat, 24 Feb 2018 18:14:45 +0000 (10:14 -0800)]
PathTools/Changes: Retroactively mention CPAN RT #114236

So that new releases will have a more complete and helpful
change log.

6 years agosilence warnings when using zaphod32 on 64 bit builds
Yves Orton [Sat, 24 Feb 2018 16:42:00 +0000 (17:42 +0100)]
silence warnings when using zaphod32 on 64 bit builds

if STRLEN is 64 bit, then there is truncation when using key_len to initialize the state.
This causes problems with windows compilers especially. See comments from bulk88 in
perl #132860 (which is not directly related to this patch, but is where it was discussed)

6 years agoCarp: add comment explaining the fix for perl #131046
Yves Orton [Sat, 24 Feb 2018 11:48:46 +0000 (12:48 +0100)]
Carp: add comment explaining the fix for perl #131046

In 4764858cb80e76fdba33cc1b3be8fcdef26df754 I added code that
eval's the argument extraction from DB::args() (code written by
both Pali and myself independently).

Unfortunately the commit message for that commit was somewhat
misleading, making it sound like the patch was a complete fix for
the underlying problem of stack-not-refcounted bugs, when in fact
it is actually a workaround, and a not-universally popular one
either due to its incompleteness. For more details of why it is
not popular see Zeframs commentary in
https://rt.perl.org/Public/Bug/Display.html?id=131046

Despite the concerns expressed by Zefram when considered from the
POV of a large enterprise using Carp to trap exceptions from
application code, having Carp throw its own exceptions about
stack-not-refcounted bugs and thus hiding the applications error
data is a significant issue.

So in 4764858cb80e76fdba33cc1b3be8fcdef26df754 we use eval to
handle those cases where Perl /can/ detect a stack-not-refcounted
error, and thus preserve as much of the applications error data
as possible.

This commit adds a comment to Carp which spells all of this out.

6 years agoFix perl #132902 - Carp: avoid infinite loops when checking for overloads
Yves Orton [Sat, 24 Feb 2018 11:37:29 +0000 (12:37 +0100)]
Fix perl #132902 - Carp: avoid infinite loops when checking for overloads

We use $obj->can("((") to see if a package has enabled overloads,
however in some cases can() is overridden with a custom implementation,
which may be unaware of these methods and then call Carp itself. This
then results in an infinite loop. An example is Class::Std v0.013.
While technically this is a bug in whatever overrides UNIVERSAL::can(),
Carp is so prolific in its use that we might as well treat it as a Carp
bug also and avoid the problem outright.

See also: https://github.com/chorny/Class-Std/pull/2

6 years agoRevert "Revert "Carp: Avoid string eval""
Yves Orton [Sat, 24 Feb 2018 04:42:51 +0000 (05:42 +0100)]
Revert "Revert "Carp: Avoid string eval""

This reverts commit f61fbe7bb36915d6a598df82ede2511d261e41d3.

After further research it appears that this does NOT break .pmc's

The docs on .pmc's leave much to be desired.

6 years agoRevert "Carp: Avoid string eval"
Yves Orton [Sat, 24 Feb 2018 03:59:50 +0000 (04:59 +0100)]
Revert "Carp: Avoid string eval"

This reverts commit 7bb6e12450c58b7094ccdfa7025fa495d3996bcf.

This patch breaks the behavior of .pmc's. :-(

Until we decide if breaking this rarely used feature is ok I am reverting.

6 years agoCarp: Avoid string eval
Father Chrysostomos [Sat, 24 Feb 2018 03:32:51 +0000 (19:32 -0800)]
Carp: Avoid string eval

Carp’s particular use of string eval is unnecessary in this case, and
slower than the alternative.  Carp’s reason for using string eval is
to avoid the effect of bareword require vivifying a package.  But that
only applies to bareword require, and not other forms of require:

$ perl -le 'print $::{"overload::"}||"nothing"; require overload'
*main::overload::
$ perl -le 'print $::{"overload::"}||"nothing"; require "overload.pm"'
nothing

Since string eval has to set up a parser and a new scope, it is much
slower that require, and quite unnecessary here.

6 years ago[perl #132854] Allow goto into first arg of bin op
Father Chrysostomos [Sat, 24 Feb 2018 01:59:09 +0000 (17:59 -0800)]
[perl #132854] Allow goto into first arg of bin op

This particular case does not risk any stack corruption, and there is
a CPAN module depending on it working (PerlX::AsyncAwait).

6 years agobetter comments about Carp overload logic
Zefram [Sat, 24 Feb 2018 00:40:13 +0000 (00:40 +0000)]
better comments about Carp overload logic

The comments originally added by commit
c99363aa273278adcad39f32026629b700f9bbc3 for [perl #132828] were unclear
and a bit over-excited.

6 years agoremove spurious _ part of Carp version number
Zefram [Sat, 24 Feb 2018 00:25:15 +0000 (00:25 +0000)]
remove spurious _ part of Carp version number

Commit 4764858cb80e76fdba33cc1b3be8fcdef26df754 unwisely
changed Carp's version number to an underscored one.  Commit
c99363aa273278adcad39f32026629b700f9bbc3 incremented the underscored
part and copied it to Carp::Heavy.  With blead being upstream for Carp,
there is no reason for it to have an underscored version number.

6 years agoperlretut: Clarify metacharacters
Karl Williamson [Wed, 27 Dec 2017 00:20:38 +0000 (17:20 -0700)]
perlretut: Clarify metacharacters

6 years agoEnsure that we don't pick up any "system perl" libraries in @INC.
James E Keenan [Thu, 1 Feb 2018 02:59:21 +0000 (21:59 -0500)]
Ensure that we don't pick up any "system perl" libraries in @INC.

We need a tightly defined @INC which, for this test file, only needs './lib'
so that we can locate the two pragmata and Config.

For: RT # 132795

6 years agoperl #132892: avoid leak by mortalizing temporary copy of pattern
Yves Orton [Fri, 23 Feb 2018 03:13:49 +0000 (04:13 +0100)]
perl #132892: avoid leak by mortalizing temporary copy of pattern

6 years agofix Perl #132828 - dont use overload to bypass overloads
Yves Orton [Sun, 18 Feb 2018 06:29:03 +0000 (07:29 +0100)]
fix Perl #132828 - dont use overload to bypass overloads

the internals don't need overload.pm to be loaded to enable overloads
which means that Carp needs to defend against overload without checking
if overload.pm is loaded either.

One odd thing about this change is that if I remove the "eval" that
wraps the "require" then we fail tests in dist/Carp/t/vivify_stash.t
which defies expectation as the require is never actually executed
from that code.

This patch doesn't have tests yet as it can segfault perl.

6 years agoFix RT #52610: Carp: Do not crash when reading @DB::args
Pali [Wed, 31 Jan 2018 21:43:46 +0000 (22:43 +0100)]
Fix RT #52610: Carp: Do not crash when reading @DB::args

Trying to read values from array @DB::args can lead to perl fatal error
"Bizarre copy of ARRAY in scalar assignment". But missing, incomplete or
possible incorrect value in @DB::args is not a fatal error for Carp.

Carp is primary used for reporting warnings and errors from other
modules, so it should not crash perl when trying to print error message.

This patch safely iterates all elements of @DB::args array via eval { }
block and replace already freed scalars for Carp usage by string
"** argument not available anymore **".

This prevent crashing perl and allows to use Carp module. It it not a
proper fix but rather workaround for Carp module. At least it allows to
safely use Carp.

Patch amended by Yves Orton

6 years agoPATCH: [perl #132900] Blead Breaks CPAN: FELIPE/Crypt-Perl
Karl Williamson [Fri, 23 Feb 2018 04:45:42 +0000 (21:45 -0700)]
PATCH: [perl #132900] Blead Breaks CPAN: FELIPE/Crypt-Perl

The root cause of this was using a 'char' where it should have been
'U8'.  I changed the signatures so that all the related functions take
and return U8's, and the compiler detects what should be cast to/from
char.  The functions all deal with byte bit patterns, so unsigned is the
appropriate declaration.

6 years agoAPItest:locale.t Fix ALT_DIGITS test
Karl Williamson [Thu, 22 Feb 2018 21:21:23 +0000 (14:21 -0700)]
APItest:locale.t Fix ALT_DIGITS test

The value returned for ALT_DIGITS may vary by locale and platform.
Change the  test to only look for a result, as opposed to a particular
result.

This should fix https://rt.perl.org/Ticket/Display.html?id=132879
but I'll leave the ticket open until that is verified.

6 years agot/op/index.t: indent run_tests() sub
David Mitchell [Tue, 20 Feb 2018 17:04:10 +0000 (17:04 +0000)]
t/op/index.t: indent run_tests() sub

(whitespace-only change)

The body of run_tests() had no indentation, meaning people didn't see it
and started adding tests outside the sub (see previous commit)

6 years agot/op/index.t: include all tests within run_tests()
David Mitchell [Tue, 20 Feb 2018 17:01:28 +0000 (17:01 +0000)]
t/op/index.t: include all tests within run_tests()

Some tests were added at the end of the file, outside sub run_tests(),
so weren't being picked up by t/op/index_thr.t.

6 years agoAdd word apparently dropped in documentation.
James E Keenan [Mon, 19 Feb 2018 13:19:22 +0000 (08:19 -0500)]
Add word apparently dropped in documentation.

6 years agoMove note about defective locale on HP-UX to README.hpux
H.Merijn Brand [Tue, 20 Feb 2018 10:55:17 +0000 (11:55 +0100)]
Move note about defective locale on HP-UX to README.hpux

6 years agoS_do_trans_complex(): outdent a block of code
David Mitchell [Tue, 20 Feb 2018 09:54:07 +0000 (09:54 +0000)]
S_do_trans_complex(): outdent a block of code

whitespace-only change left over from my recent tr///c fix work

6 years agofix nit in perl5278delta.pod
David Mitchell [Tue, 20 Feb 2018 09:35:21 +0000 (09:35 +0000)]
fix nit in perl5278delta.pod

RT #132776

The :lvalue sub examples didn't have a valid body for an lvalue sub;
I've replaced the '1' with '...'

6 years agoMerge branch '\N{} handler refactoring ' into blead
Karl Williamson [Tue, 20 Feb 2018 08:38:27 +0000 (01:38 -0700)]
Merge branch '\N{} handler refactoring ' into blead

This series of commits refactors a portion of the \N{} handling in
regcomp.c.  This was done in preparation for allowing m'\N{...}', that
is single quoted patterns containing named characters.  Currently this
is illegal.

The final step to do this is not quite ready to be committed.  It
basically works, but the edge cases need to be looked at and tests
created, and the code freeze is upon us.

Some of the commits in this series are more than a year old, and I was
plagued with problems with rebasing, some of which I only resolved just
now, and decided to get this refactoring in before any more things come
along.  I intend to fix
https://rt.perl.org/Ticket/Display.html?id=132163
during the code freeze, and I've started it out on the refactored code
used here, so it would be extra work to have to use the unrefactored
version.

6 years agoregcomp.c: Refactor some if-elses
Karl Williamson [Sun, 15 Jan 2017 00:55:24 +0000 (17:55 -0700)]
regcomp.c: Refactor some if-elses

if (foo) {
    ...
    return
} else {
    stuff
}

is equivalent to

if (foo) {
    ...
    return
}

stuff

This commit changes the former to the latter, which also means moving
some declarations earlier, and some intialization later, and removing
some no longer valid code.  This will be useful in the next commit.

6 years agoregcomp.c: White space only
Karl Williamson [Thu, 2 Mar 2017 19:15:20 +0000 (12:15 -0700)]
regcomp.c: White space only

This changes the indentation of some code to reflect where it should be
with the addition and subtraction of blocks in the next commits.  And it
reflows to fit in 79 columns, and converts some tabs to spaces.

6 years agoregcomp.c: Simplify expression
Karl Williamson [Thu, 2 Mar 2017 19:14:38 +0000 (12:14 -0700)]
regcomp.c: Simplify expression

The previous commit has made part of this 'if' redundant, so the whole
thing can be simplified.

6 years agoregcomp.c: Re-order branches
Karl Williamson [Thu, 12 Jan 2017 21:59:45 +0000 (14:59 -0700)]
regcomp.c: Re-order branches

This will be useful in a future commit

6 years agoperldelta for performance enhancements
Karl Williamson [Tue, 20 Feb 2018 05:12:49 +0000 (22:12 -0700)]
perldelta for performance enhancements

6 years agoutf8.h: Add in #define for backcompat
Karl Williamson [Mon, 12 Feb 2018 12:53:47 +0000 (05:53 -0700)]
utf8.h: Add in #define for backcompat

This symbol somehow got deleted, and it really shouldn't have been.

This should not go in perldelta, as we don't want people to be using
this ancient symbol who aren't already are.

6 years agolocale.c: Add STATIC_ASSERT
Karl Williamson [Tue, 20 Feb 2018 04:15:21 +0000 (21:15 -0700)]
locale.c: Add STATIC_ASSERT

I tried this in a smoke earlier, and got one failure, and to keep on
going, removed it temporarily.  But many other changes later, I tried
again in a smoke, and it isn't failing.  A legitimate failure of this
assertion would mean reading/writing past a buffer end.

6 years agoperlre: Add note that nested (?>...) are not no-ops
Karl Williamson [Tue, 20 Feb 2018 03:52:29 +0000 (20:52 -0700)]
perlre: Add note that nested (?>...) are not no-ops

6 years agoAdd atomic script runs
Karl Williamson [Tue, 20 Feb 2018 03:40:20 +0000 (20:40 -0700)]
Add atomic script runs

This is an extension to the new script_run feature that is syntactic
sugar for the idiom espected to be most commonly used:

(*sr:(?>...)) can be written as (*asr:...)

6 years agoFix skipping char in (*sr:...) defn
Karl Williamson [Tue, 20 Feb 2018 03:28:19 +0000 (20:28 -0700)]
Fix skipping char in (*sr:...) defn

This was wrongly calling nextchar(), which skipped the next character
wrongly

6 years agot/re/script_run.t: White space only
Karl Williamson [Tue, 20 Feb 2018 03:15:21 +0000 (20:15 -0700)]
t/re/script_run.t: White space only

The previous commit created an outer block around these

6 years agot/re/script_run.t: Tests for 'sr' form of (*script_run:...)
Karl Williamson [Tue, 20 Feb 2018 03:12:28 +0000 (20:12 -0700)]
t/re/script_run.t: Tests for 'sr' form of (*script_run:...)

6 years agoregcomp.c: Silence uninit compiler warning
Karl Williamson [Mon, 19 Feb 2018 19:14:06 +0000 (12:14 -0700)]
regcomp.c: Silence uninit compiler warning

This warning (only known on one compiler at the moment) is probably
wrong, but by setting this to NULL, we avoid the warning, and should
segfault if the warning were correct, instead of using uninitialized
data.

6 years agoregcomp.c: Make sure no future ambiguity on new alpha assertions
Karl Williamson [Mon, 19 Feb 2018 19:01:51 +0000 (12:01 -0700)]
regcomp.c: Make sure no future ambiguity on new alpha assertions

This change adds a colon when checking if a string is an alpha
assertion.  This is defensive coding against an unlikely future change
wherein some new (*... construct is added that has the same initial
sequence as one of these assertions.  The colon acts as a terminator and
would automatically prevent any ambiguity.  One of these had the colon,
and hence was inconsistent with the rest.

Spotted by ilmari.

6 years agoregcomp.c: White space only
Karl Williamson [Mon, 19 Feb 2018 18:57:37 +0000 (11:57 -0700)]
regcomp.c: White space only

Fit in 80 columns, outdent because of removed enclosing block in a
previous commit, consistent spacing around '+'.

ilmari spotted the '+' spacing issues

6 years agohints/hpux.sh: Note locale univ.utf8 may be defective
Karl Williamson [Mon, 19 Feb 2018 19:08:15 +0000 (12:08 -0700)]
hints/hpux.sh: Note locale univ.utf8 may be defective

A new check in 8b7358b96caf71db3213a7d72fc401e42ee0b2d0 is finding that
this locale is defective.  It is fixed by 11.31

6 years agoStorable: recurse.t: use note() rather than diag()
David Mitchell [Mon, 19 Feb 2018 22:50:59 +0000 (22:50 +0000)]
Storable: recurse.t: use note() rather than diag()

diag() goes to STDERR and should only be used when a test fails and extra
diagnostic info should be output.

6 years ago[MERGE] fixups for OP_MULTICONCAT
David Mitchell [Mon, 19 Feb 2018 22:20:40 +0000 (22:20 +0000)]
[MERGE] fixups for OP_MULTICONCAT

This branch fixes three main issues caused by the OP_MULTICONCAT
optimisation:

* When dealing with magic/tie/overloading, there were many edge cases;
the way these are handled has been completely rewritten, fixing
bugs related to exactly when and how args are sringified and/or tested
for undefinedness;

* relatedly,  on a stringified concat such as $x .= "$y", or
$a = "$b$c$d", the stringification is honoured under exactly the same
(buggy) set of conditions that pertained before multiconcat was
introduced; this is noticable in overloading whether the result calls the
stringify method and thus returns a plain string, or whether it skips that
and returns an overloaded object, e.g. for $a = "$b$c$d", does $a end up
as a ref or a string. Before the branch it was always a ref, now its
sometimes a string.

* concats within a runtime pattern code block could crash, e.g.

    /$a(?{  $b . "c" })/

6 years agomulticoncat: /$a(?{ $b . "c" })/ could crash
David Mitchell [Mon, 19 Feb 2018 21:32:36 +0000 (21:32 +0000)]
multiconcat: /$a(?{  $b . "c" })/ could crash

RT #132772

Due to the weird order in which codeblocks within patterns are optimised,
it was possible for the OP_CONCAT -> OP_MULTICONCAT optimisation to leave
freed ops in the op execution chain, leading to assertion failures or
crashes.

In particular, optimize_optree() needs to always be called before
CALL_PEEP(), otherwise the individual subtrees which make up the two
children of a concat op may not have the head of subtree as the last op in
the subtree's op_next chain: in the subtree

    RV2SV
      |
     GV

this subtree gets peephole-optimised to

    ex-RV2SV
      |
     GVSV

and GVSV->op_next no longer points to the ex-RV2SV but rather directly
to RV2SV->op_next. But S_maybe_multiconcat() assumes that the head of each
subtree is the last op to be executed: It updates RV2SV->op_next when
reorganising the optree, but leaves GVSV->op_next possibly pointing at a
freed op.

This commit provides a minimal fix by unconditionally calling
optimize_optree() on each code block in Perl_pmruntime(). This may
mean that optimize_optree() may be run against the same code block again
later, but apart from the slight inefficiency, this should be harmless.

A more general fix will be applied post 5.28.0 release.

6 years agoS_maybe_multiconcat(): fix some code comments
David Mitchell [Mon, 19 Feb 2018 17:04:52 +0000 (17:04 +0000)]
S_maybe_multiconcat(): fix some code comments

various typos and thinkos

6 years agopp_multiconcat: correctly honour stringify
David Mitchell [Mon, 19 Feb 2018 11:59:03 +0000 (11:59 +0000)]
pp_multiconcat: correctly honour stringify

RT #132793, RT #132801

In something like $x .= "$overloaded", the $overloaded stringify method
wasn't being called.

However, it turns that the existing (pre-multiconcat) behaviour is also
buggy and inconsistent. That behaviour has been restored as-is.
At some future time, these bugs might be addressed.

Here are some comments from the new tests added to overload.t:

Since 5.000, any OP_STRINGIFY immediately following an OP_CONCAT
is optimised away, on the assumption that since concat will always
return a valid string anyway, it doesn't need stringifying.
So in "$x", the stringify is needed, but on "$x$y" it isn't.
This assumption is flawed once overloading has been introduced, since
concat might return an overloaded object which still needs stringifying.
However, this flawed behaviour is apparently needed by at least one
module, and is tested for in opbasic/concat.t: see RT #124160.

There is also a wart with the OPpTARGET_MY optimisation: specifically,
in $lex = "...", if $lex is a lexical var, then a chain of 2 or more
concats *doesn't* optimise away OP_STRINGIFY:

$lex = "$x";        # stringifies
$lex = "$x$y";      # doesn't stringify
$lex = "$x$y$z..."; # stringifies

6 years agopp_multiconcat: eliminate/rename dsv/dsv_pv vars
David Mitchell [Sat, 17 Feb 2018 12:22:09 +0000 (12:22 +0000)]
pp_multiconcat: eliminate/rename dsv/dsv_pv vars

After the previous commit, dsv is always the same as targ,
so relace all uses of 'dsv' with 'targ', and rename the 'dsv_pv' var
to 'targ_pv'.

Also rename a limited scope var from 'targ_pv' to targ_buf' as that
name is now being used for dsv_pv.

Should be no functional changes.

6 years agoredo magic/overload handing in pp_multiconcat
David Mitchell [Sat, 10 Feb 2018 15:27:59 +0000 (15:27 +0000)]
redo magic/overload handing in pp_multiconcat

The way pp_multiconcat handles things like tieing and overloading
doesn't work very well at the moment. There's a lot of code to handle
edge cases, and there are still open bugs.

The basic algorithm in pp_multiconcat is to first stringify (i.e. call
SvPV() on) *all* args, then use the obtained values to calculate the total
length and utf8ness required, then do a single SvGROW and copy all the
bytes from all the args.

This ordering is wrong when variables with visible side effects, such as
tie/overload, are encountered. The current approach is to stringify args
up until such an arg is encountered, concat all args up until that one
together via the normal fast route, then jump to a special block of code
which concats any remaining args one by one the "hard" way, handling
overload etc.

This is problematic because we sometimes need to go back in time. For
example in ($undef . $overloaded), we're supposed to call
    $overloaded->concat($undef, reverse=1)
so to speak, but by the time of the method call, we've already tried to
stringify $undef and emitted a spurious 'uninit var' warning.

The new approach taken in this commit is to:

1) Bail out of the stringify loop under a greater range of problematical
variable classes - namely we stop when encountering *anything* which
might cause external effects, so in addition to tied and overloaded vars,
we now stop for any sort of get magic, or any undefined value where
warnings are in scope.

2) If we bail out, we throw away any stringification results so far,
and concatenate *all* args the slow way, even ones we're already
stringified. This solves the "going back in time" problem mentioned above.
It's safe because the only vars that get processed twice are ones for which
the first stringification could have no side effects.

The slow concat loop now uses S_do_concat(), which is a new static inline
function which implements the main body of pp_concat() - so they share
identical code.

An intentional side-effect of this commit is to fix three tickets:

    RT #132783
    RT #132827
    RT #132595

so tests for them are included in this commit.

One effect of this commit is that string concatenation of magic or
undefined vars will now be slower than before, e.g.

    "pid=$$"
    "value=$undef"

but they will probably still be faster than before pp_multiconcat was
introduced.

6 years agomove body of pp_concat() to S_do_concat()
David Mitchell [Fri, 16 Feb 2018 14:10:40 +0000 (14:10 +0000)]
move body of pp_concat() to S_do_concat()

Create an inline static function which implements the body of pp_concat(),
then replace pp_concat()'s body with a call to it.

Shortly, we'll use this function in pp_multiconcat() too.

6 years agoUpdate META files and MANIFEST for if.pm
Sawyer X [Mon, 19 Feb 2018 18:22:33 +0000 (20:22 +0200)]
Update META files and MANIFEST for if.pm

6 years agoregcomp.c: Use macro to avoid code duplication
Yves Orton [Mon, 12 Feb 2018 05:22:54 +0000 (22:22 -0700)]
regcomp.c: Use macro to avoid code duplication

Wrap RESTART_PASS1 logic in a macro layer for clarity and reduction of
duplicate code

The committer in consultation with Tony Cook changed things to avoid a
compiler warning, and added comments, white space.

6 years agoFix manifest
Sawyer X [Mon, 19 Feb 2018 09:18:20 +0000 (11:18 +0200)]
Fix manifest

6 years agoCorrect PathTools dist files and bump to 3.74:
Sawyer X [Mon, 19 Feb 2018 08:38:22 +0000 (10:38 +0200)]
Correct PathTools dist files and bump to 3.74:

There were permission errors when uploading 3.73 so we are bumping
it to 3.74.

I've included the META.json and META.yml files in the dist and
corrected their entry in MANIFEST.

6 years agoAdd alphabetic synonyms for regex assertions
Karl Williamson [Mon, 19 Feb 2018 04:30:17 +0000 (21:30 -0700)]
Add alphabetic synonyms for regex assertions

This commit came out of the committee formed with PCRE members as a
result of http://nntp.perl.org/group/perl.perl5.porters/246762

6 years agoChange syntax of script runs
Karl Williamson [Mon, 19 Feb 2018 03:28:34 +0000 (20:28 -0700)]
Change syntax of script runs

The new syntax is (*script_run:...)
and a shortcut (*sr:...)

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

6 years agoAdd 'alpha_assertions' warnings category
Karl Williamson [Sun, 18 Feb 2018 04:20:59 +0000 (21:20 -0700)]
Add 'alpha_assertions' warnings category

This will be used in future commits.

6 years agoSort an entry in perldiag
Karl Williamson [Mon, 19 Feb 2018 03:37:34 +0000 (20:37 -0700)]
Sort an entry in perldiag

6 years ago[Merge] ‘Nonelem’ scalars
Father Chrysostomos [Mon, 19 Feb 2018 00:41:09 +0000 (16:41 -0800)]
[Merge] ‘Nonelem’ scalars

6 years agoperldelta for non-elems
Father Chrysostomos [Mon, 19 Feb 2018 00:41:02 +0000 (16:41 -0800)]
perldelta for non-elems

I don’t think the bug involving defelems, which this branch partially
fixes is significant enough to be mentioned in the bugs section.

Likewise, the memory leaks fixed (some of them introduced in the
same dev cycle) are so rare that it would add unnecessary verbiage
to perldelta.

6 years agoFix ary shifting when sparse ary is passed to sub
Father Chrysostomos [Mon, 19 Feb 2018 00:12:11 +0000 (16:12 -0800)]
Fix ary shifting when sparse ary is passed to sub

This commit fixes #132729 in the specific case where a nonexistent
element within a sparse array is passed to a subroutine.

Prior to this commit,

    some_sub($sparse_array[$n])

where $n <= $#sparse_array and the element does not exist, would exhi-
bit erroneous behaviour if some_sub shifted or unshifted the original
@sparse_array.  Any ‘holes’ (nonexistent elements) in the array would
show up in @_ as deferred element (defelem) scalars, magic scalars
that remember their index in the array.  This index is not updated and
gets out of synch when the array is shifted.

This commit fixes the bug for elements within the array by using the
new ‘nonelem’ magic introduced a few commits ago.  It stores within
the array a magic scalar that is marked as being nonexistent.

It also reduced the number of scalars that need to be created if such
a sub call happens repeatedly.

6 years agoFix two bugs when calling &xsub when @_ has holes
Father Chrysostomos [Tue, 13 Feb 2018 21:36:22 +0000 (13:36 -0800)]
Fix two bugs when calling &xsub when @_ has holes

This fixes #132729 in the particular instance where an XSUB is
called via ampersand syntax when @_ has ‘holes’, or nonexistent ele-
ments, as in:

    @_ = ();
    $_[1] = 1;
    &xsub;

This means that if the XSUB or something it calls unshifts @_, the
first argument passed to the XSUB will now refer to $_[1], not $_[0];
i.e., as of this commit it is correctly shifted over.  Previously, a
‘defelem’ was used, which is a magical scalar that remembers its index
in the array, independent of whether the array was shifted.

In addition, the old code failed to mortalize the defelem, so this
commit fixes a memory leak with the new ‘non-elem’ mechanism (a spe-
cially-marked element stored in the array itself).

6 years agoTest #132729 with array flattening
Father Chrysostomos [Mon, 12 Feb 2018 01:14:20 +0000 (17:14 -0800)]
Test #132729 with array flattening

Other instances of this bug have not yet been fixed.  This commit’s
grandparent fixed the case where an array with holes in it is flat-
tened in lvalue context, and then gets shifted/unshifted before
an element is vivified.

6 years agosvleak.t: Test for leak fixed by prev. commit
Father Chrysostomos [Mon, 12 Feb 2018 01:01:26 +0000 (17:01 -0800)]
svleak.t: Test for leak fixed by prev. commit

6 years ago‘Nonelems’ for pushing sparse array on the stack
Father Chrysostomos [Mon, 22 Jan 2018 05:55:00 +0000 (21:55 -0800)]
‘Nonelems’ for pushing sparse array on the stack

To avoid having to create deferred elements every time a sparse array
is pushed on to the stack, store a magic scalar in the array itself,
which av_exists and refto recognise as not existing.

This means there is only a one-time cost for putting such arrays on
the stack.

It also means that deferred elements that live long enough don’t
start pointing to the wrong array entry if the array gets shifted (or
unshifted/spliced) in the mean time.  Instead, the scalar is already
in the array, so it cannot lose its place.  This fix only applies
when the array as a whole is pushed on to the stack, but it could be
extended in future commits to apply to other places where we currently
use deferred elements.

6 years agoMerge branch 'add thread-safe locales' into blead
Karl Williamson [Sun, 18 Feb 2018 22:45:08 +0000 (15:45 -0700)]
Merge branch 'add thread-safe locales' into blead