This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
6 years agolocale.c: Refactor static fcn to save work
Karl Williamson [Thu, 20 Jul 2017 22:20:01 +0000 (16:20 -0600)]
locale.c: Refactor static fcn to save work

This adds a parameter to the function that sets the radix character for
floating point numbers.  We know that the radix by default is a dot, so
no need to calculate it in that case.

This code was previously using localeconv() to find the locale's decimal
point.  The just added my_nl_langinfo() fcn does the same with an easier
API, and is more thread safe, and automatically switches to use
localeconv() when n nl_langinfo() isn't available, so revise the
conditional compilation directives that previously were necessary, and
collapse directives that were unnecessarily nested.

And adjust indentation

6 years agolocale.c: Create extended internal Perl_langinfo()
Karl Williamson [Tue, 12 Sep 2017 01:12:56 +0000 (19:12 -0600)]
locale.c: Create extended internal Perl_langinfo()

This extended version allows it to be called so that it uses the current
locale for the LC_NUMERIC, instead of toggling to the underlying one.
(This can be useful when in the middle of things.)

This ability won't be used until the next commit

6 years agolocale.c: Rmv redundant fcn call
Karl Williamson [Thu, 20 Jul 2017 22:24:42 +0000 (16:24 -0600)]
locale.c: Rmv redundant fcn call

This function is called as part of the call made in the line before.  No
need to do it twice.

6 years agolocale.c: White-space, comment, rearrange some #else
Karl Williamson [Sun, 16 Jul 2017 00:19:48 +0000 (18:19 -0600)]
locale.c: White-space, comment, rearrange some #else

This file is full of conditional compilation, due to the fact that
locale support has been highly variable in the OSes Perl has operated
on.  This commit properly indents nested compiler directives, and makes
sure there is a blank line between the directives and real code.  I find
that much easier to read.  It also re-orders some

    #ifdef some_feature
        Many lines of code handling feature
    #else
        1 to 3 lines of trivial code to avoid compilation warnings
    #endif

to

    #ifndef some_feature
        1 to 3 lines of trivial code to avoid compilation warnings
    #else
        Many lines of code handling feature
    #endif

Otherwise the trivial code may be hundreds of lines from the original
'#if', which makes it hard to grok.

This commit also clarifies and fixes typos in comments, and removes some
obsolete comments.

6 years agoMerge branch 'BO' into blead
Todd Rinaldo [Wed, 8 Nov 2017 22:39:12 +0000 (16:39 -0600)]
Merge branch 'BO' into blead

Make it simpler to divine if modules are there because of loading B/O or
because the actual program used them.

NPD

6 years agoext/B/t/strict.t: Assure B.pm and O.pm pass strict and warnings checks.
Todd Rinaldo [Wed, 13 Sep 2017 19:35:39 +0000 (14:35 -0500)]
ext/B/t/strict.t: Assure B.pm and O.pm pass strict and warnings checks.

We need to test these in unit tests since they do not load these modules to
prevent pollution of the stash in compilers.

6 years agoFix warnings (used once) for O.pm
Todd Rinaldo [Wed, 13 Sep 2017 19:35:35 +0000 (14:35 -0500)]
Fix warnings (used once) for O.pm

6 years agoFix warnings (used once) for B.pm
Todd Rinaldo [Wed, 13 Sep 2017 19:35:30 +0000 (14:35 -0500)]
Fix warnings (used once) for B.pm

6 years agoRemove unnecessary module loads from B and O
Todd Rinaldo [Wed, 13 Sep 2017 19:35:21 +0000 (14:35 -0500)]
Remove unnecessary module loads from B and O

This commit removes multiple unnecessary modules so that
perl -MO= can hand back to compile as cleanly as possible.

This change caused significant jitter in tests for B::Concise. While updating
the test to the new reality, OptreeCheck.pm was corrected to stop stripping
regexes off $got when it started failing so it would be easier to see where
the failure happened.

6 years agoSimplify travis.yml config for Continuous Integration
Nicolas R [Wed, 8 Nov 2017 22:30:37 +0000 (15:30 -0700)]
Simplify travis.yml config for Continuous Integration

The goal is to have a quick smoke on travis smokers
to plug in short future CI for any new commits/PR.

NPD

6 years agorestore error message for unterminated strings
Lukas Mai [Wed, 8 Nov 2017 22:05:35 +0000 (23:05 +0100)]
restore error message for unterminated strings

The previous strchr/memchr changes inadvertently broke the error message
for perl -e '"'. Instead of

    Can't find string terminator '"' anywhere before EOF

it became

    Can't find string terminator """ anywhere before EOF

6 years agodisable t/porting/authors.t for distro packaging
Nicolas R [Mon, 6 Nov 2017 23:44:17 +0000 (16:44 -0700)]
disable t/porting/authors.t for distro packaging

NPD

6 years agodisable t/porting/podcheck.t for distro packaging
Nicolas R [Mon, 6 Nov 2017 23:42:08 +0000 (16:42 -0700)]
disable t/porting/podcheck.t for distro packaging

NPD

6 years agoAllow custom PL_strtab hash in perl_construct.
Nicolas R [Wed, 8 Nov 2017 15:56:20 +0000 (08:56 -0700)]
Allow custom PL_strtab hash in perl_construct.

Such a patch allow PL_strtab optimizations at compile time
to statically malloc PL_strtab to an optimized size at startup.

Custom entries can then be added (after PL_hash_seed initialization)
without risking the hash to be reset by perl_construct.

6 years agoPERL_STRLEN_ROUNDUP: parenthesize macro parameter
Lukas Mai [Wed, 8 Nov 2017 10:45:05 +0000 (11:45 +0100)]
PERL_STRLEN_ROUNDUP: parenthesize macro parameter

Also:
- factor out common expression
- remove redundant double parens
- add spaces to expression

6 years agotoke.c: Fix wrong use of memrchr
Karl Williamson [Tue, 7 Nov 2017 22:56:32 +0000 (15:56 -0700)]
toke.c: Fix wrong use of memrchr

This was a replacement of strchr(), so should not have used the
find-right-most memrchr.

This was spotted by Christian Hansen.  I don't know what the
implications are, but thought I should get a fix in immediately.

6 years agoBlead breaks DBD::SQLite
Karl Williamson [Tue, 7 Nov 2017 19:52:09 +0000 (12:52 -0700)]
Blead breaks DBD::SQLite

This partially reverts 0f12654f40.

The particular spot being reverted is in gv.c, and the change did not
take into account all the nuances involved, so simply revert it.  I
believe what is happening is that a negative number is being generated
and treated as a very large number.  Instead the code should retain the
original test that it was ok to do the subtraction, before actually
doing it.

6 years agoTwo fix-ups following b59bf0b288.
Craig A. Berry [Tue, 7 Nov 2017 03:13:24 +0000 (21:13 -0600)]
Two fix-ups following b59bf0b288.

In one case, memEQs was missing a length parameter, and in the
other, two opening braces had been removed but only one closing
brace.

6 years agotoke.c: use my_memrchr helper for portability [round 2]
Nicolas R [Mon, 6 Nov 2017 23:10:21 +0000 (16:10 -0700)]
toke.c: use my_memrchr helper for portability [round 2]

compilation broken on darwin using clang

6 years agoUse my_memrchr helper for portability
Nicolas R [Mon, 6 Nov 2017 23:03:03 +0000 (16:03 -0700)]
Use my_memrchr helper for portability

Recent commit '8725053bce' breaks darwin compilation.

We should use my_memrchr helper to avoid
portability issues, instead of calling
directly memrchr.

6 years agoMerge branch 'convert strchr to memchr' into blead
Karl Williamson [Mon, 6 Nov 2017 21:32:14 +0000 (14:32 -0700)]
Merge branch 'convert strchr to memchr' into blead

Using C string functions on Perl strings doesn't work properly if they
contain embedded NULs.  This can happen with Perl program text, for
example, and even if the NUL is illegal, the generated diagnostics are
likely to be misleading as the parsing would have terminated
prematurely.

I have done an audit on core for cases where C string functions are used
in contexts where a Perl string is being processed.  This came down to
uses of strchr() and strrchr().  This branch changes many of them to
memchr() and memrchr() respectively.  Not all uses of these functions
need change, as there are places where C strings are what is being
processed, such as dealing with OS strings that are NUL terminated.
File paths and environ are two examples.

Also, memchr and memrchr tend to be faster than their str equivalents,
as they only need to look for one termination condition, and there may
be hardware assistance on some platforms.  Further, memrchr knows
exactly where to start looking, instead of having to find the NUL ending
the string (strrchr is likely to be implemented as iterating over the
string using strchr from the left, over and over until it fails).

I may have converted some str functions to mem ones unnecessarily, as I
didn't check in full detail if some were operating only on C strings, but
given that the mem ones are faster, this is OK

6 years agotoke.c: Convert some strchr to memchr
Karl Williamson [Sat, 25 Mar 2017 21:06:58 +0000 (15:06 -0600)]
toke.c: Convert some strchr to memchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agotoke.c use memBEGINs with prev commit
Karl Williamson [Thu, 2 Nov 2017 20:01:54 +0000 (14:01 -0600)]
toke.c use memBEGINs with prev commit

6 years agotoke.c: Add limit parameter to 3 static functions
Karl Williamson [Mon, 6 Nov 2017 21:12:41 +0000 (14:12 -0700)]
toke.c: Add limit parameter to 3 static functions

This will make it possible to fix to handle embedded NULs in the next
commits.

6 years agoregcomp.c: Convert some strchr to memchr
Karl Williamson [Sat, 25 Mar 2017 21:00:22 +0000 (15:00 -0600)]
regcomp.c: Convert some strchr to memchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agoperl.c: Use memchr instead of strchr
Karl Williamson [Sat, 25 Mar 2017 20:55:08 +0000 (14:55 -0600)]
perl.c: Use memchr instead of strchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agoop.c: Use memchr,memrchr instead of strchr,strrchr
Karl Williamson [Sat, 25 Mar 2017 20:54:13 +0000 (14:54 -0600)]
op.c: Use memchr,memrchr instead of strchr,strrchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agomg.c: Use memchr instead of strchr
Karl Williamson [Sat, 25 Mar 2017 20:53:07 +0000 (14:53 -0600)]
mg.c: Use memchr instead of strchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agodoio.c: Change strchr to memchr
Karl Williamson [Sat, 25 Mar 2017 20:51:19 +0000 (14:51 -0600)]
doio.c: Change strchr to memchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agopp_sys.c; Use memchr instead of strchr
Karl Williamson [Sat, 25 Mar 2017 20:50:48 +0000 (14:50 -0600)]
pp_sys.c; Use memchr instead of strchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agoutf8.c: Use memchr instead of strchr
Karl Williamson [Sat, 25 Mar 2017 20:46:50 +0000 (14:46 -0600)]
utf8.c: Use memchr instead of strchr

This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

6 years agodquote.c: Use memchr() instead of strchr()
Karl Williamson [Sat, 25 Mar 2017 17:39:05 +0000 (11:39 -0600)]
dquote.c: Use memchr() instead of strchr()

This allows \x and \o to work properly in the face of embedded NULs.
A limit parameter is added to each function, and that is passed to
memchr (which replaces strchr).  See the branch merge message for more
information.

6 years agolocale.c: Tighten what is considered a LC variable
Karl Williamson [Sat, 25 Mar 2017 01:01:39 +0000 (19:01 -0600)]
locale.c: Tighten what is considered a LC variable

Things like LC_CTYPE are locale variables, but not LC_ctype nor
LC__CTYPE.  Prior to this commit all were treated as locale variables.
Many platforms have more locale variables than Perl knows about, e.g.,
LC_PAPER, and the code tries to catch all possibilities.

6 years agolocale.c: White space, extra braces only
Karl Williamson [Thu, 9 Mar 2017 18:53:48 +0000 (11:53 -0700)]
locale.c: White space, extra braces only

Align vertically, and indent blocks to standard.  It adds braces for
clarity.

6 years agoMerge branch for new string comparison macros into blead
Karl Williamson [Mon, 6 Nov 2017 19:50:52 +0000 (12:50 -0700)]
Merge branch for new string comparison macros into blead

See thread beginning with
     http://nntp.perl.org/group/perl.perl5.porters/244335

This branch creates various new macros that are easier to read and use
than the underlying code, and uses them in blead

6 years agohandy.h: Add comments
Karl Williamson [Fri, 3 Nov 2017 04:16:11 +0000 (22:16 -0600)]
handy.h: Add comments

This adds a description of the naming conventions to be used for any new
string comparison macros.

6 years agoMake new macros private
Karl Williamson [Fri, 3 Nov 2017 03:12:08 +0000 (21:12 -0600)]
Make new macros private

Until we decide these weren't a bad idea

6 years agoext/attributes/attributes.xs is PERL_EXT
Karl Williamson [Fri, 3 Nov 2017 14:16:41 +0000 (08:16 -0600)]
ext/attributes/attributes.xs is PERL_EXT

6 years agohandy.h: Make uniform the defns of strFOO, memFOO
Karl Williamson [Fri, 24 Mar 2017 01:38:04 +0000 (19:38 -0600)]
handy.h: Make uniform the defns of strFOO, memFOO

For consistency

6 years agoRemove _memEQs, _memNEs
Karl Williamson [Fri, 3 Nov 2017 03:02:25 +0000 (21:02 -0600)]
Remove _memEQs, _memNEs

All uses of these private macros have been replaced by other calls.

6 years agoAdd memENDPs and use it in core
Karl Williamson [Tue, 25 Apr 2017 02:39:02 +0000 (20:39 -0600)]
Add memENDPs and use it in core

This corresponds to memBEGINPs

6 years agoAdd memBEGINPs() to core and use it
Karl Williamson [Tue, 25 Apr 2017 02:27:24 +0000 (20:27 -0600)]
Add memBEGINPs() to core and use it

This macro is like memBEGINs(), but the 'P' signifies we want a proper
substring, meaning that the 2nd string parameter must not be the entire
first parameter.

6 years agoUse memENDs() in core
Karl Williamson [Tue, 25 Apr 2017 02:11:40 +0000 (20:11 -0600)]
Use memENDs() in core

6 years agoUse memBEGINs() in core
Karl Williamson [Tue, 25 Apr 2017 02:02:57 +0000 (20:02 -0600)]
Use memBEGINs() in core

6 years agoChange some strBEGINs() to memBEGINs()
Karl Williamson [Thu, 2 Nov 2017 20:03:40 +0000 (14:03 -0600)]
Change some strBEGINs() to memBEGINs()

The latter is generally faster when the length is already known.

This commit also changes a few hard-coded numbers to use sizeof().

6 years agoAdd memBEGINs(), memENDs() and use them in APItest
Karl Williamson [Tue, 31 Oct 2017 18:11:12 +0000 (12:11 -0600)]
Add memBEGINs(), memENDs() and use them in APItest

memBEGINs() is like strBEGINs(), but can be used for buffers without
trailing NULs.  It can also be used when there is a trailing NUL, and
the length is known, as it should be somewhat faster, only having to
check for one ending condition.

Same for memENDs vs strENDs

6 years agoChange some strncmp(), etc. to strBEGINs()
Karl Williamson [Thu, 9 Mar 2017 17:55:38 +0000 (10:55 -0700)]
Change some strncmp(), etc. to strBEGINs()

The latter is much clearer as to what's going on, and the programmer and
program reader don't have to count characters.

6 years agoUse memEQs, memNEs in core files
Karl Williamson [Tue, 31 Oct 2017 14:30:38 +0000 (08:30 -0600)]
Use memEQs, memNEs in core files

Where the length is known, we can use these functions which relieve
the programmer and the program reader from having to count characters.
The memFOO functions should also be slightly faster than the strFOO
equivalents.

In some instances in this commit, hard coded numbers are used.  These
come from the 'case' statement values that apply to them.

6 years agoRename strEQs to strBEGINs; remove strNEs
Karl Williamson [Thu, 9 Mar 2017 03:31:25 +0000 (20:31 -0700)]
Rename strEQs to strBEGINs; remove strNEs

The original names are confusing.

See thread beginning with
http://nntp.perl.org/group/perl.perl5.porters/244335

The two macros are mapped into just that one, complementing the result
for the few cases where strNEs was used.

6 years agog++ 4.0 supports __attribute__((unused))
Lukas Mai [Mon, 6 Nov 2017 18:57:08 +0000 (19:57 +0100)]
g++ 4.0 supports __attribute__((unused))

6 years agoFix deparsing of transliterations with unprintable characters.
John Lightsey [Tue, 31 Oct 2017 23:12:26 +0000 (18:12 -0500)]
Fix deparsing of transliterations with unprintable characters.

RT #132405

Signed-off-by: Nicolas R <atoomic@cpan.org>
6 years agosupport -nre in t/harness, exclude files by regex
Yves Orton [Mon, 6 Nov 2017 13:43:32 +0000 (14:43 +0100)]
support -nre in t/harness, exclude files by regex

6 years agoadd assertions about format lexing
Zefram [Sun, 5 Nov 2017 04:45:04 +0000 (04:45 +0000)]
add assertions about format lexing

[perl #132158] describes a situation in which a weird kind of unterminated
format caused the parser to crash.  Add some assertions that catch the
messed up parser state before it actually crashes.

6 years agodeparse implicit ~~ as explicit with -x2
Zefram [Sun, 5 Nov 2017 00:09:32 +0000 (00:09 +0000)]
deparse implicit ~~ as explicit with -x2

Fixes [perl #91362].

6 years agoRevert "Speed up Carp.pm when backtrace arguments are references"
Zefram [Sat, 4 Nov 2017 22:04:20 +0000 (22:04 +0000)]
Revert "Speed up Carp.pm when backtrace arguments are references"

This reverts commit 7a831b721c469aeccfe1110a2d177dd115d5998d.  It was
buggy and mostly pointless, and following criticism on p5p it should
never have been committed.

6 years agoinitialisation of simple aggregate state variables
Zefram [Sat, 4 Nov 2017 21:43:59 +0000 (21:43 +0000)]
initialisation of simple aggregate state variables

We now recognise the basic cases of aggregate state variables, to
permit initialisations of the form "state @a =" or "state @a :shared =".
Initialisation of state variable lists remains forbidden, because the
op flags don't let us distinguish "state(...)" from "(state(...))" in
most cases.

6 years agoAdd comment to explain why we want to probe for statfs() et al
Aaron Crane [Wed, 1 Nov 2017 17:52:24 +0000 (17:52 +0000)]
Add comment to explain why we want to probe for statfs() et al

6 years agopp_multiconcat: don't stringify LHS overload arg
David Mitchell [Sat, 4 Nov 2017 10:30:00 +0000 (10:30 +0000)]
pp_multiconcat: don't stringify LHS overload arg

RT #132385

In something like

    $a1 . $a2

where $a2 is overloaded, the concat overload method was being called
like

    concat($a2, "$a1", 1);

(The 1 indicated that the args are reversed).

This commit changes it so that it's called as

    concat($a2, $a1, 1);

i.e. that the original arg is passed in rather than a stringified copy
of it. This is important if for example $a1 is a ref.

6 years agoperldelta for b3937e202aaf1 (Carp & ISA constant)
Father Chrysostomos [Sat, 4 Nov 2017 04:36:20 +0000 (21:36 -0700)]
perldelta for b3937e202aaf1 (Carp & ISA constant)

6 years agoAvoid unique REGCOMP in dynaloader
J. Nick Koston [Wed, 6 Sep 2017 17:18:51 +0000 (12:18 -0500)]
Avoid unique REGCOMP in dynaloader

Dynaloader has 4 unique regex's that cannot be de-duplicated
by perlcc.  Switch them to index/substr

References: CPANEL-15683

Signed-off-by: Nicolas R <atoomic@cpan.org>
6 years agoSpeed up Carp.pm when backtrace arguments are references
Nicolas R [Tue, 22 Aug 2017 18:26:15 +0000 (13:26 -0500)]
Speed up Carp.pm when backtrace arguments are references

Avoid downgrading the string when not required.

Author: J. Nick Koston <nick@cpanel.net>
References: CPANEL-15140

6 years agoAvoid a segfault when untying an object
Nicolas R [Mon, 31 Oct 2016 17:53:17 +0000 (11:53 -0600)]
Avoid a segfault when untying an object

Check if the tied object has a stash set
before calling UNTIE method.

6 years ago(perl #131895) fail stat on names with \0 embedded
Tony Cook [Thu, 2 Nov 2017 20:18:56 +0000 (20:18 +0000)]
(perl #131895) fail stat on names with \0 embedded

Also lstat() and the file test ops.

6 years agoyada-yada is a term, not an operator
Lukas Mai [Thu, 2 Nov 2017 19:48:38 +0000 (19:48 +0000)]
yada-yada is a term, not an operator

6 years agodocument qw's whitespace rules
Zefram [Thu, 2 Nov 2017 19:29:33 +0000 (19:29 +0000)]
document qw's whitespace rules

qw only splits on ASCII whitespace, like primary tokenisation, but
nowadays unlike the split() formulation with which it's documented.
Document this additional difference from split().  Fixes [perl #132272].

6 years agotoke.c: Rmv useless code
Karl Williamson [Sat, 25 Mar 2017 23:38:40 +0000 (17:38 -0600)]
toke.c: Rmv useless code

This code is unreachable because the code above makes sure that the
variable can't be larger than PL_bufend, and the code is only executed
if it is larger.

6 years agotoke.c: White space only
Karl Williamson [Sat, 25 Mar 2017 21:18:27 +0000 (15:18 -0600)]
toke.c: White space only

Fix up some white space, including outdenting a block that was doubly
indented

6 years agomulticoncat: use append_utf8_from_native_byte()
David Mitchell [Wed, 1 Nov 2017 18:45:36 +0000 (18:45 +0000)]
multiconcat: use append_utf8_from_native_byte()

This small inline function does what my code was doing manually in a
couple of places. Should be no functional difference, just makes the code
tidier.

Suggested by Karl.

6 years agosprintf-as-multiconcat: fix \x80 issue
David Mitchell [Wed, 1 Nov 2017 17:14:58 +0000 (17:14 +0000)]
sprintf-as-multiconcat: fix \x80 issue

My recent OP_MULTICONCAT merge which (amongst other things) converts
sprintfs with a constant format that only containing %s's into a
multiconcat op, miscounted variant chars (i.e. chars like \x80, which if
upgraded to utf8, expand the number of bytes they require).
This could cause buffer overruns.

Spotted by Karl Williamson++

NPD

6 years agoIncrease $Carp::Heavy::VERSION to 1.44
Father Chrysostomos [Wed, 1 Nov 2017 20:59:05 +0000 (13:59 -0700)]
Increase $Carp::Heavy::VERSION to 1.44

6 years agoIncrease $Carp::VERSION to 1.44
Father Chrysostomos [Wed, 1 Nov 2017 20:13:00 +0000 (13:13 -0700)]
Increase $Carp::VERSION to 1.44

6 years agoCarp: Don’t choke on ISA constant
Father Chrysostomos [Wed, 1 Nov 2017 20:11:27 +0000 (13:11 -0700)]
Carp: Don’t choke on ISA constant

This broke some time between 1.29 (perl 5.18) and 1.3301 (perl 5.20):

$ perl5.20.1 -e 'package Foo { use constant ISA => 42; Bar::f() } package Bar { use Carp; sub f { carp "tun syn" } }'
Not a GLOB reference at /usr/local/lib/perl5/5.20.1/Carp.pm line 560.

and still persisted in bleadperl (Carp 1.43) until this commit.

The code that goes poking through the symbol table needs to take into
account that not all stash elements are globs.

6 years agocustomized.dat: Add generator note
Father Chrysostomos [Wed, 1 Nov 2017 05:18:10 +0000 (22:18 -0700)]
customized.dat: Add generator note

So that people like me who do not do this very often can see just
by looking at the file how it got generated.

6 years agoPorting/Maintainers.pl: vutil.c is no longer CUSTOMIZED
Father Chrysostomos [Wed, 1 Nov 2017 05:12:42 +0000 (22:12 -0700)]
Porting/Maintainers.pl: vutil.c is no longer CUSTOMIZED

6 years agoRevert "vutil.c: use new SvPVCLEAR and constant string friendly macros"
Father Chrysostomos [Wed, 1 Nov 2017 05:02:49 +0000 (22:02 -0700)]
Revert "vutil.c: use new SvPVCLEAR and constant string friendly macros"

This reverts commit 7394beb1401a6ac5e5e19cff7f08486e5141126c.

This change to vutil.c is unnecessary and makes it differ needlessly
from the CPAN release (CPAN *is* upstream for this file), making syn-
chronisation harder.

6 years agometaconfig.h: Rmv HAS_MEMRCHR
Karl Williamson [Wed, 1 Nov 2017 16:56:24 +0000 (10:56 -0600)]
metaconfig.h: Rmv HAS_MEMRCHR

This is now used in code, and hence no longer needed in this file

6 years agometaconfig.h: Rmv HAS_THREAD_SAFE_NL_LANGINFO_L
Karl Williamson [Wed, 1 Nov 2017 16:55:07 +0000 (10:55 -0600)]
metaconfig.h: Rmv HAS_THREAD_SAFE_NL_LANGINFO_L

This is now used in code, and hence no longer needed in this file

6 years agoAdd my_memrchr() implementation of memrchr()
Karl Williamson [Sat, 25 Mar 2017 18:45:34 +0000 (12:45 -0600)]
Add my_memrchr() implementation of memrchr()

On platforms that have memrchr(), my_mrchr() maps to use that instead.

This is useful functionality, lacking on many platforms.  This commit
also uses the new function in two places in the core where the comments
previously indicated it would be advantageous to use it if we had it.

It is left usable only in core, so that if this turns out to have been a
bad idea, it can be easily removed.

6 years agoAPItest.xs: Omit unused variable
Karl Williamson [Tue, 31 Oct 2017 00:52:14 +0000 (18:52 -0600)]
APItest.xs: Omit unused variable

6 years agoutf8.c: Rmv obsolete comment
Karl Williamson [Mon, 30 Oct 2017 15:32:36 +0000 (09:32 -0600)]
utf8.c: Rmv obsolete comment

This was no longer true

6 years agofix Perl_get_cvn_flags() return value
David Mitchell [Wed, 1 Nov 2017 10:51:13 +0000 (10:51 +0000)]
fix Perl_get_cvn_flags() return value

One branch returned an SV* when it should return CV*.
This upset g++.

6 years agofix ext/B/t/optree_samples.t
David Mitchell [Tue, 31 Oct 2017 23:36:40 +0000 (23:36 +0000)]
fix ext/B/t/optree_samples.t

The recent OP_MULTICONCAT merge broke it under PERL_UNICODE=""

6 years agoMake get_cv cope with subrefs
Father Chrysostomos [Tue, 31 Oct 2017 17:16:59 +0000 (10:16 -0700)]
Make get_cv cope with subrefs

When called with GV_NOADD_NOINIT, get_cv will fail an assertion if the
thingy in the stash is not a GV.

While calling with GV_NOADD_NOINIT is a strange thing to do, neverthe-
less Cpanel::JSON::XS does it with "Encode::decode", which is not an
unreasonable thing to do if it is known that the sub already exists.

This commit makes get_cv take sub refs into account, so that, when we
reënable the optimisation reverted by 9bceb75b8d9, Cpanel::JSON::XS
will continue to work with bleadperl.

(Currently, the optimisation only applies to the main package, which
is why I am able to test this now.)

6 years agoBasic tests for get_cvn_flags
Father Chrysostomos [Tue, 31 Oct 2017 04:49:04 +0000 (21:49 -0700)]
Basic tests for get_cvn_flags

6 years ago[MERGE] add OP_MULTICONCAT and optimize_optree()
David Mitchell [Tue, 31 Oct 2017 16:08:06 +0000 (16:08 +0000)]
[MERGE] add OP_MULTICONCAT and optimize_optree()

This branch contains one main commit which adds the new OP_MULTICONCAT op,
plus a few prior commits to provide support; in particular, adding an extra
top-down optree scan phase to allow extra optimisation opportunities, just
before the peephole optimiser is run.

See the OP_MULTICONCAT for more details, but in summary it:
allows multiple OP_CONCAT, OP_CONST ops, plus optionally an OP_SASSIGN
or OP_STRINGIFY, to be combined into a single OP_MULTICONCAT op, which can
make things a *lot* faster: 4x or more.

6 years agoperldelta entry for OP_MULTICONCAT
David Mitchell [Wed, 25 Oct 2017 10:58:47 +0000 (11:58 +0100)]
perldelta entry for OP_MULTICONCAT

6 years agoAdd OP_MULTICONCAT op
David Mitchell [Tue, 8 Aug 2017 17:42:14 +0000 (18:42 +0100)]
Add OP_MULTICONCAT op

Allow multiple OP_CONCAT, OP_CONST ops, plus optionally an OP_SASSIGN
or OP_STRINGIFY, to be combined into a single OP_MULTICONCAT op, which can
make things a *lot* faster: 4x or more.

In more detail: it will optimise into a single OP_MULTICONCAT, most
expressions of the form

    LHS RHS

where LHS is one of

    (empty)
    my $lexical =
    $lexical    =
    $lexical   .=
    expression  =
    expression .=

and RHS is one of

    (A . B . C . ...)            where A,B,C etc are expressions and/or
                                 string constants

    "aAbBc..."                   where a,A,b,B etc are expressions and/or
                                 string constants

    sprintf "..%s..%s..", A,B,.. where the format is a constant string
                                 containing only '%s' and '%%' elements,
                                 and A,B, etc are scalar expressions (so
                                 only a fixed, compile-time-known number of
                                 args: no arrays or list context function
                                 calls etc)

It doesn't optimise other forms, such as

    ($a . $b) . ($c. $d)

    ((($a .= $b) .= $c) .= $d);

(although sub-parts of those expressions might be converted to an
OP_MULTICONCAT). This is partly because it would be hard to maintain the
correct ordering of tie or overload calls.

The compiler uses heuristics to determine when to convert: in general,
expressions involving a single OP_CONCAT aren't converted, unless some
other saving can be made, for example if an OP_CONST can be eliminated, or
in the presence of 'my $x = .. ' which OP_MULTICONCAT can apply
OPpTARGET_MY to, but OP_CONST can't.

The multiconcat op is of type UNOP_AUX, with the op_aux structure directly
holding a pointer to a single constant char* string plus a list of segment
lengths. So for

    "a=$a b=$b\n";

the constant string is "a= b=\n", and the segment lengths are (2,3,1).
If the constant string has different non-utf8 and utf8 representations
(such as "\x80") then both variants are pre-computed and stored in the aux
struct, along with two sets of segment lengths.

For all the above LHS types, any SASSIGN op is optimised away. For a LHS
of '$lex=', '$lex.=' or 'my $lex=', the PADSV is optimised away too.

For example where $a and $b are lexical vars, this statement:

    my $c = "a=$a, b=$b\n";

formerly compiled to

    const[PV "a="] s
    padsv[$a:1,3] s
    concat[t4] sK/2
    const[PV ", b="] s
    concat[t5] sKS/2
    padsv[$b:1,3] s
    concat[t6] sKS/2
    const[PV "\n"] s
    concat[t7] sKS/2
    padsv[$c:2,3] sRM*/LVINTRO
    sassign vKS/2

and now compiles to:

    padsv[$a:1,3] s
    padsv[$b:1,3] s
    multiconcat("a=, b=\n",2,4,1)[$c:2,3] vK/LVINTRO,TARGMY,STRINGIFY

In terms of how much faster it is, this code:

    my $a = "the quick brown fox jumps over the lazy dog";
    my $b = "to be, or not to be; sorry, what was the question again?";

    for my $i (1..10_000_000) {
        my $c = "a=$a, b=$b\n";
    }

runs 2.7 times faster, and if you throw utf8 mixtures in it gets even
better. This loop runs 4 times faster:

    my $s;
    my $a = "ab\x{100}cde";
    my $b = "fghij";
    my $c = "\x{101}klmn";

    for my $i (1..10_000_000) {
        $s = "\x{100}wxyz";
        $s .= "foo=$a bar=$b baz=$c";
    }

The main ways in which OP_MULTICONCAT gains its speed are:

* any OP_CONSTs are eliminated, and the constant bits (already in the
  right encoding) are copied directly from the constant string attached to
  the op's aux structure.

* It optimises away any SASSIGN op, and possibly a PADSV op on the LHS, in
  all cases; OP_CONCAT only did this in very limited circumstances.

* Because it has a holistic view of the entire concatenation expression,
  it can do the whole thing in one efficient go, rather than creating and
  copying intermediate results. pp_multiconcat() goes to considerable
  efforts to avoid inefficiencies. For example it will only SvGROW() the
  target once, and to the exact size needed, no matter what mix of utf8
  and non-utf8 appear on the LHS and RHS.  It never allocates any
  temporary SVs except possibly in the case of tie or overloading.

* It does all its own appending and utf8 handling rather than calling
  out to functions like sv_catsv().

* It's very good at handling the LHS appearing on the RHS; for example in

    $x = "abcd";
    $x = "-$x-$x-";

  It will do roughly the equivalent of the following (where targ is $x);

    SvPV_force(targ);
    SvGROW(targ, 11);
    p = SvPVX(targ);
    Move(p,   p+1,  4, char);
    Copy("-", p,    1, char);
    Copy("-", p+5,  1, char);
    Copy(p+1, p+6,  4, char);
    Copy("-", p+10, 1, char);
    SvCUR(targ) = 11;
    p[11] = '\0';

  Formerly, pp_concat would have used multiple PADTMPs or temporary SVs to
  handle situations like that.

The code is quite big; both S_maybe_multiconcat() and pp_multiconcat()
(the main compile-time and runtime parts of the implementation) are over
700 lines each. It turns out that when you combine multiple ops, the
number of edge cases grows exponentially ;-)

6 years agooverload.t: add more concat tests
David Mitchell [Fri, 18 Aug 2017 13:51:45 +0000 (14:51 +0100)]
overload.t: add more concat tests

The '.' and '.=' string concatenation overload methods don't seem to be
heavily tested. Add some more tests, especially with an eye to things that
might break when multiple concat ops are optimised into a single op
(as I intend to do shortly).

6 years agofix a benchmarks sprintf entry
David Mitchell [Mon, 14 Aug 2017 15:46:01 +0000 (16:46 +0100)]
fix a benchmarks sprintf entry

an sprintf entry in t/perf/benchmarks was missing two %s's due to an
earlier cut+paste error. Also, it was being constant folded, so
use vars rather literals for the arguments.

6 years agoadd extra optimization phase
David Mitchell [Wed, 20 Sep 2017 15:02:55 +0000 (16:02 +0100)]
add extra optimization phase

Add the function optimize_optree(). Optree optimization/finalization is
now done in three main phases:

    1) optimize_optree(optree);
    2) CALL_PEEP(*startp);
    3) finalize_optree(optree);

(1) and (3) are done in top-down order, while (2) is done in execution
order.

Note that this function doesn't actually optimize anything yet; this
commit is just adding the necessary infrastructure.

Adding this extra top-down phase allows certain combinations of ops
to be recognised in ways that the peephole optimizer would find hard.

For example in

    $a = expression1 . expression2 . expression3 . expression4

the top-down tree looks like

    sassign
        concat
            concat
                concat
                    expression1
                        ...
                    expression2
                        ...
                expression3
                    ...
            expression4
                ...
        padsv[$a]

so its easy to see the nested concats, while execution order looks like

    ... lots of ops for expression1 ...
    ... lots of ops for expression2 ...
    concat
    ... lots of ops for expression3 ...
    concat
    ... lots of ops for expression4 ...
    concat
    padsv[$a]
    sassign

where its not at all obvious that there is a chain of nested concats.

Similarly, trying to do this in finalize_optree() is hard because the
peephole optimizer will have messed things up. Also it will be too
late to remove nulled-out ops from the execution path.

6 years agopanic if a freed op is called
David Mitchell [Wed, 4 Oct 2017 10:29:40 +0000 (11:29 +0100)]
panic if a freed op is called

On debugging builds, when freeing an op, set its op_ppaddr to point to
a function which dies. That way if a freed op accidentally remains in the
execution path, you'll know immediately, rather than crashing sometime
later with a stack underflow or whatever.

6 years agoregen/opcode.pl: display duplicate bit name
David Mitchell [Sun, 20 Aug 2017 11:21:09 +0000 (12:21 +0100)]
regen/opcode.pl: display duplicate bit name

change this error message:

    addbits(): bit 4 of multiconcat already specified  at ...

to

    addbits(): bit 4 of multiconcat already specified (OPpTARGET_MY) at ...

6 years agoUse nl_langinfo_l() if available
Karl Williamson [Thu, 26 Oct 2017 14:29:50 +0000 (08:29 -0600)]
Use nl_langinfo_l() if available

This function allows us to avoid using a mutex and changing the locale.

6 years agomake_ext.pl: Use version.pm for version cmp
Father Chrysostomos [Mon, 30 Oct 2017 20:37:21 +0000 (13:37 -0700)]
make_ext.pl: Use version.pm for version cmp

We do a version comparison to determine whether Makefile.PL needs to
be run (in case a module version changed).  The simple string compar-
ison we have done up till now fails if the two version numbers differ
simply by a trailing zero (as currently happens with DB_File, which
is at version 1.840, with XS_VERSION set to 1.84.  Since version.pm’s
routines are compiled into miniperl, there is no reason not to do this
‘properly’, and it stops multiple ‘make’ invocations from rebuilding
DB_File again, and again....

6 years agoperldeprecation: Change some uses of "in Perl $version" to "as of Perl $version"
Dagfinn Ilmari Mannsåker [Mon, 30 Oct 2017 18:24:50 +0000 (18:24 +0000)]
perldeprecation: Change some uses of "in Perl $version" to "as of Perl $version"

In present and present perfect tense sentences, this makes it clearer
that it doesn't just apply to that version, but subsequent versions
too.  Sentences in simple past tense have been left as is.

6 years agoThe AIX doubledouble longdouble has been left broken for three years.
Jarkko Hietaniemi [Mon, 30 Oct 2017 05:19:18 +0000 (07:19 +0200)]
The AIX doubledouble longdouble has been left broken for three years.

I must have left the test in the wrong position while
working on getting it to work, and never tested it since.
My apologies.

With this simple trick the following failing tests start to work.

        ../cpan/Math-Complex/t/Complex.t
        ../cpan/Math-Complex/t/Trig.t
        ../cpan/Math-Complex/t/underbar.t
        ../cpan/Scalar-List-Utils/t/uniq.t
        ../ext/POSIX/t/math.t
        ../lib/warnings.t
        op/sprintf2.t
        op/time.t

Or rather, the broken part of the functionality, Infinity,
starts being avoided, as it should be.  See the comment above
about the known brokenness of long doubles and infinity in AIX.

Note that even after this fix the following are still broken in
this AIX (the perl5 aix machine), but these are unrelated to infnan:

        ../cpan/ExtUtils-MakeMaker/t/03-xsstatic.t
        ../dist/Storable/t/store.t
        ../ext/XS-APItest/t/handy00.t
        re/uniprops01.t
        re/uniprops02.t
        re/uniprops03.t
        re/uniprops04.t
        re/uniprops05.t
        re/uniprops06.t
        re/uniprops07.t
        re/uniprops08.t
        re/uniprops09.t
        re/uniprops10.t

(as of blead 4faa3060)

6 years agoperldelta for e8d55f27af46, ebcc725e3f7e
Tony Cook [Mon, 30 Oct 2017 00:14:36 +0000 (11:14 +1100)]
perldelta for e8d55f27af46ebcc725e3f7e

6 years ago(perl #132245) don't leak on \N{}
Tony Cook [Wed, 18 Oct 2017 23:47:22 +0000 (10:47 +1100)]
(perl #132245) don't leak on \N{}

get_and_check_backslash_N_name() failed to free its working SV if
the name was empty.

6 years ago(perl #132245) don't try to process a char range with no preceding char
Tony Cook [Wed, 18 Oct 2017 23:46:04 +0000 (10:46 +1100)]
(perl #132245) don't try to process a char range with no preceding char

A range like \N{}-0 eventually results in compilation failing, but
before that, get_and_check_backslash_N_name() attempts to treat
the memory before the empty output of \N{} as a character.

6 years agoShow that '/o' modifier no longer has adverse effects on 'split'.
Harald Jörg [Sun, 29 Oct 2017 13:41:59 +0000 (09:41 -0400)]
Show that '/o' modifier no longer has adverse effects on 'split'.

    The underlying problem was already fixed in
    3cb4cde3dd4d2af2f5065053905708bffa5168f9 (Jul 4 2017).  For clarity, adding
    test adapted from original poster in RT 132334.

    Add Harald Jörg to Perl AUTHORS.