This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
7 years agotoke.c: Quit now if error at end of input
Karl Williamson [Tue, 14 Feb 2017 02:18:38 +0000 (19:18 -0700)]
toke.c: Quit now if error at end of input

In these two cases, we know we are at the end of the input, and that we
have an error.  There is no need to try to patch things up so we can
continue to parse looking for other errors; there's nothing left to
parse.  So skip having to deal with patching up.

7 years agotoke.c: Un-special case something
Karl Williamson [Tue, 14 Feb 2017 02:12:31 +0000 (19:12 -0700)]
toke.c: Un-special case something

By refactoring slightly, we make this code in a switch statement
have the same entrance and exit invariants as the other cases, so they
all can be handled uniformly at the end of the switch.

7 years agoDon't try to compile a pattern known to be in error
Karl Williamson [Tue, 14 Feb 2017 02:01:46 +0000 (19:01 -0700)]
Don't try to compile a pattern known to be in error

Regular expression patterns are parsed by the lexer/toker, and then
compiled by the regex compiler.  It is foolish to try to compile one
that the parser has rejected as syntactically bad; assumptions may be
violated and segfaults ensue.  This commit abandons all parsing
immediately if a pattern had errors in it.  A better solution would be
to flag this pattern as not to be compiled, and continue parsing other
things so as to find the most errors in a single attempt, but I don't
think it's worth the extra effort.

Making this change caused some misleading error messages in the test
suite to be replaced by better ones.

7 years agotoke.c: Add internal function to abort parsing
Karl Williamson [Tue, 14 Feb 2017 01:49:52 +0000 (18:49 -0700)]
toke.c: Add internal function to abort parsing

This is to be called to abort the parsing early, before the required
number of errors have been found.  It is used when continuing the parse
would be either fruitless or we could be looking at garbage.

7 years agotoke.c: White-space only
Karl Williamson [Tue, 14 Feb 2017 01:46:30 +0000 (18:46 -0700)]
toke.c: White-space only

Indent after the previous commit enclosed this code in a new block.

7 years agoRelax internal function API
Karl Williamson [Tue, 14 Feb 2017 01:27:02 +0000 (18:27 -0700)]
Relax internal function API

This changes  yyerror_pvn so that its first parameter can be NULL.  This
indicates no message is to be output, but that parsing is to be
abandoned immediately, without waiting for more errors to build up.

7 years agoExtract code into a function
Karl Williamson [Mon, 13 Feb 2017 20:18:38 +0000 (13:18 -0700)]
Extract code into a function

This creates a function in toke.c to output the compilation aborted
message, changing perl.c to call that function.  This is in preparation
for this to be called from a 2nd place

7 years agotoke.c: Rmv no longer necessary UTF-8 checks
Karl Williamson [Mon, 13 Feb 2017 20:03:32 +0000 (13:03 -0700)]
toke.c: Rmv no longer necessary UTF-8 checks

The previous commit tightened up the checking for well-formed UTF8ness,
so that the ones removed here were redundant.

The test during a string eval may also no longer be necessary, but since
there are many ways to create that string, I'm not confidant enough to
remove it.

7 years agoAdd test for [perl #130675]
Karl Williamson [Tue, 14 Feb 2017 03:40:57 +0000 (20:40 -0700)]
Add test for [perl #130675]

7 years agot/lib/croak/toke_l1: Cut down test
Karl Williamson [Tue, 14 Feb 2017 03:37:47 +0000 (20:37 -0700)]
t/lib/croak/toke_l1: Cut down test

The previous commits hardening toke.c against malformed UTF-8 input have
allowed this test case to be cut down substantially

7 years agotoke.c: Fix bugs where UTF-8 is turned on in mid chunk
Karl Williamson [Mon, 13 Feb 2017 19:35:18 +0000 (12:35 -0700)]
toke.c: Fix bugs where UTF-8 is turned on in mid chunk

Previous commits have tightened up the checking of UTF-8 for
well-formedness in the input program or string eval.  This is done in
lex_next_chunk and lex_start.  But it doesn't handle the case of

    use utf8; foo

because 'foo' is checked while UTF-8 is still off.  This solves that
problem by noticing when utf8 is turned on, and then rechecking at the
next opportunity.

See thread beginning at
http://nntp.perl.org/group/perl.perl5.porters/242916

This fixes [perl #130675].  A test will be added in a future commit

This catches some errors earlier than they used to be and aborts. so
some tests in the suite had to be split into multiple parts.

7 years agomg.c: PL_hints is unsigned
Karl Williamson [Mon, 13 Feb 2017 19:16:45 +0000 (12:16 -0700)]
mg.c: PL_hints is unsigned

Therefore it's dangerous to presume things fit into an IV.

7 years agotoke.c: Add branch prediction
Karl Williamson [Mon, 13 Feb 2017 19:02:54 +0000 (12:02 -0700)]
toke.c: Add branch prediction

The input is far more likely to be well-formed than not.

7 years agotoke.c: Fix comments describing S_tokeq
Karl Williamson [Mon, 13 Feb 2017 18:54:06 +0000 (11:54 -0700)]
toke.c: Fix comments describing S_tokeq

The comments about what this function does were incorrect.

7 years agotoke.c: Slight refactor.
Karl Williamson [Mon, 13 Feb 2017 18:51:59 +0000 (11:51 -0700)]
toke.c: Slight refactor.

This moves an automatic variable to closer to the only place it is used;
it also adds branch prediction.  It is likely that the input will be
well-formed.

7 years agotoke.c: White space, comments, braces
Karl Williamson [Mon, 13 Feb 2017 18:29:35 +0000 (11:29 -0700)]
toke.c: White space, comments, braces

I am adding the braces because in one of the areas, the lack of braces
had led to a blead failure.

7 years agotoke.c: Don't compare same bytes twice
Karl Williamson [Mon, 13 Feb 2017 18:31:53 +0000 (11:31 -0700)]
toke.c: Don't compare same bytes twice

Before starting this memEQ, we know that the first bytes are the same,
so might as well start the compare with the 2nd bytes.

7 years agotoke.c: Move declaration
Karl Williamson [Mon, 13 Feb 2017 18:15:07 +0000 (11:15 -0700)]
toke.c: Move declaration

This automatic variable doesn't need such a large scope.

7 years agoperly.c: Clarify comment
Karl Williamson [Thu, 9 Feb 2017 05:18:27 +0000 (22:18 -0700)]
perly.c: Clarify comment

7 years agosv.h: Add comment
Karl Williamson [Sat, 11 Feb 2017 04:26:55 +0000 (21:26 -0700)]
sv.h: Add comment

7 years agoMerge branch 'sawyerx/undeprecate-backslash-c' into blead
Sawyer X [Sun, 12 Feb 2017 10:52:12 +0000 (12:52 +0200)]
Merge branch 'sawyerx/undeprecate-backslash-c' into blead

7 years agoRevert "Deprecating the use of C<< \cI<X> >> to specify a printable character."
Sawyer X [Wed, 8 Feb 2017 13:00:37 +0000 (14:00 +0100)]
Revert "Deprecating the use of C<< \cI<X> >> to specify a printable character."

This reverts commit bfdc8cd3d5a81ab176f7d530d2e692897463c97d.

7 years agoRevert "Avoid triggering a deprecation warnings."
Sawyer X [Wed, 8 Feb 2017 12:34:31 +0000 (13:34 +0100)]
Revert "Avoid triggering a deprecation warnings."

This reverts commit 5ad2a0b67cdf1d90b67b991ae8708d3b9d57bad9.

We have decided to undeprecate \c. Please see:
http://www.nntp.perl.org/group/perl.perl5.porters/2017/01/msg242693.html

7 years agopp_pack.c: Remove no longer relevant comment
Karl Williamson [Sat, 11 Feb 2017 20:07:33 +0000 (13:07 -0700)]
pp_pack.c: Remove no longer relevant comment

7 years agopp_pack.c: Remove needless branch
Karl Williamson [Sat, 11 Feb 2017 20:02:46 +0000 (13:02 -0700)]
pp_pack.c: Remove needless branch

This function only sets *retlen to 0 if the input length is 0.  In all
but one case, the function was not called with with that input.  In that
one case, I changed to avoid calling the function with that input.
Hence we can remove checking *retlen for 0.

7 years agopp_pack.c: Remove obsolete code
Karl Williamson [Sat, 11 Feb 2017 20:00:27 +0000 (13:00 -0700)]
pp_pack.c: Remove obsolete code

This code effectively reduced to

 if (foo) 0 else 0

because a #define was changed to 0 some releases ago.  Just replace by

 0

7 years agoutf8.c: Move comment a few lines up in the file
Karl Williamson [Sat, 11 Feb 2017 19:58:16 +0000 (12:58 -0700)]
utf8.c: Move comment a few lines up in the file

Move it to where it makes more sense.

7 years agoutf8.h: Clarify comment
Karl Williamson [Sat, 11 Feb 2017 19:57:33 +0000 (12:57 -0700)]
utf8.h: Clarify comment

7 years agoutf8.h: White-space, parens only
Karl Williamson [Sun, 12 Feb 2017 03:59:49 +0000 (20:59 -0700)]
utf8.h: White-space, parens only

Add parens to clarify grouping, white-space for legibility

7 years agoutf8.h: Add branch prediction
Karl Williamson [Sun, 12 Feb 2017 03:57:36 +0000 (20:57 -0700)]
utf8.h: Add branch prediction

use bytes;

is unlikely to be the case.

7 years ago(perl #126203) build issues
Tony Cook [Sat, 11 Feb 2017 21:53:58 +0000 (08:53 +1100)]
(perl #126203) build issues

helps to test builds with the right options...

7 years agoChange av_foo_nomg() name
Karl Williamson [Fri, 13 Jan 2017 19:35:26 +0000 (12:35 -0700)]
Change av_foo_nomg() name

These names sparked some controversy when created:

http://www.nntp.perl.org/group/perl.perl5.porters/2016/03/msg235216.html

I looked through existing code for paradigms to follow, and found some
occurrences of 'skip_foo_mg'.  So this commit changes the names to be

    av_top_index_skip_len_mg()
    av_tindex_skip_len_mg()

This is explicit about the type of magic that is ignored, and will still
be valid if another type of magic ever gets added.

7 years agoCoverity #28930: unchecked return value
Jarkko Hietaniemi [Sat, 11 Feb 2017 00:03:29 +0000 (19:03 -0500)]
Coverity #28930: unchecked return value

Strangely, this was apparently found already in 2014, but it now
(rightfully) showed up.  Coverity database tweak?

7 years agoNet::Ping: Todo a test on EBCDIC
Karl Williamson [Fri, 10 Feb 2017 17:04:16 +0000 (10:04 -0700)]
Net::Ping: Todo a test on EBCDIC

This is just to get it to pass.  It appears to be a permissions problem
on our one smoker.

7 years agoCoverity #155950: pRExC->code_blocks is blindly derefed
Jarkko Hietaniemi [Sun, 5 Feb 2017 23:50:11 +0000 (18:50 -0500)]
Coverity #155950: pRExC->code_blocks is blindly derefed

Even though code calling S_pat_upgrade_to_utf8 from the
Perl_re_op_compile is testing the code_blocks for NULLness.

7 years agoregcomp.c: Fix so will compile on C++11
Karl Williamson [Wed, 8 Feb 2017 22:48:56 +0000 (15:48 -0700)]
regcomp.c: Fix so will compile on C++11

See 147e38468b8279e26a0ca11e4efd8492016f2702 for complete explanation

7 years ago(perl #126203) avoid potential leaks on quadmath_snprintf() failure
Tony Cook [Thu, 9 Feb 2017 00:19:45 +0000 (11:19 +1100)]
(perl #126203) avoid potential leaks on quadmath_snprintf() failure

In the unlikely case quadmath_snprintf() fails both sv_vcatpvfn_flags()
and my_snprintf() could leak the temp format string returned by
quadmath_format_single() if quadmath_format_single() had to rebuild
the format.

Getting quadmath_snprintf() to fail in this context seems impractical,
but future changes may make it happen, so clean up after ourselves.

7 years agoGetopt::Std: Changed pod NAME to follow convention
Neil Bowers [Sun, 5 Feb 2017 21:18:37 +0000 (21:18 +0000)]
Getopt::Std: Changed pod NAME to follow convention

See thread at http://nntp.perl.org/group/perl.perl5.porters/242374

7 years agolocale.c: Use only C89 legal C
Karl Williamson [Tue, 7 Feb 2017 17:00:19 +0000 (10:00 -0700)]
locale.c: Use only C89 legal C

An array was being declared and initialized from a non-constant.

Spotted by James Keenan

7 years agoAdd TODO test for [perl #125493]
Karl Williamson [Wed, 8 Feb 2017 04:42:40 +0000 (21:42 -0700)]
Add TODO test for [perl #125493]

7 years agoperldelta for d6851fe9ee8e
Tony Cook [Wed, 8 Feb 2017 03:56:10 +0000 (14:56 +1100)]
perldelta for d6851fe9ee8e

7 years ago(perl #130705) don't convert match with argument to qr
Tony Cook [Wed, 8 Feb 2017 03:38:45 +0000 (14:38 +1100)]
(perl #130705) don't convert match with argument to qr

Code like:

  0 =~ qr/1/ ~~ 0

would have the match operator replaced with qr, leaving an op tree
like:

e  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
d     <@> print vK ->e
3        <0> pushmark s ->4
c        <2> aelem sK/2 ->d
5           <1> rv2av[t1] sKR/1 ->6
4              <$> gv(*0) s ->5
b           <2> smartmatch sK/2 ->c
9              </> qr() sKS ->a  <=== umm
6                 <$> const(IV 0) s ->7
8                 <|> regcomp(other->9) sK ->9
7                    </> qr(/"1"/) s ->8
a              <$> const(IV 0) s ->b

when executed, this would leave an extra value on the stack:

$ ./perl -Dst -e 'print(0->[0 =~ qr/1/ ~~ 0])'
Smartmatch is experimental at -e line 1.

EXECUTING...

    =>
(-e:0)  enter
    =>
(-e:0)  nextstate
    =>
(-e:1)  pushmark
    =>  *
(-e:1)  gv(main::0)
    =>  *  GV()
(-e:1)  rv2av
    =>  *  AV()
(-e:1)  const(IV(0))
    =>  *  AV()  IV(0)
(-e:1)  qr
    =>  *  AV()  IV(0)  \REGEXP()
(-e:1)  regcomp
    =>  *  AV()  IV(0)
(-e:1)  qr
    =>  *  AV()  IV(0)  \REGEXP()
(-e:1)  const(IV(0))
    =>  *  AV()  IV(0)  \REGEXP()  IV(0)
(-e:1)  smartmatch
    =>  *  AV()  IV(0)  SV_NO
(-e:1)  aelem
    =>  *  AV()  SV_UNDEF  <=== trying to print an AV
(-e:1)  print
perl: sv.c:2941: Perl_sv_2pv_flags: Assertion `((svtype)((sv)->sv_flags & 0xff)) != SVt_PVAV && ((svtype)((sv)->sv_flags & 0xff)) != SVt_PVHV && ((svtype)((sv)->sv_flags & 0xff)) != SVt_PVFM' failed.
Aborted

7 years agopod: Do not suggest to use insecure :utf8 PerlIO layer when reading files
Pali [Sun, 18 Sep 2016 15:16:33 +0000 (17:16 +0200)]
pod: Do not suggest to use insecure :utf8 PerlIO layer when reading files

Instead use strict :encoding(UTF-8) PerlIO layer for input files.

7 years agoAdd test for [perl #129157]
Karl Williamson [Tue, 7 Feb 2017 23:21:25 +0000 (16:21 -0700)]
Add test for [perl #129157]

7 years agoperldelta for dd314e1ca8c3
Tony Cook [Tue, 7 Feb 2017 23:16:33 +0000 (10:16 +1100)]
perldelta for dd314e1ca8c3

7 years ago(perl #130722) don't call SvPVX() on a glob
Tony Cook [Tue, 7 Feb 2017 05:14:53 +0000 (16:14 +1100)]
(perl #130722) don't call SvPVX() on a glob

S_doparseform() called SvPVX() on the format argument, which
produced an assertion failure when the format was supplied as a
glob.

Since S_doparseform() calls SvPV() initially and stores the result,
just use that result.

7 years agoAdd .t for malformed-UTF-8 toke.c testing
Karl Williamson [Tue, 7 Feb 2017 20:12:36 +0000 (13:12 -0700)]
Add .t for malformed-UTF-8 toke.c testing

This adds a non-UTF-8 encoded file to make it easier to test malformed
UTF-8 strings.  The file is automatically skipped on EBCDIC platforms.

The file is initialized with a test for [perl #129037], which had
already been unknowingly fixed by commit
75219bacf5aacd315b96083de24e82cd8238e99a

7 years agomultideref: handle both OPpLVAL_INTRO,OPpDEREF
David Mitchell [Tue, 7 Feb 2017 15:45:14 +0000 (15:45 +0000)]
multideref: handle both OPpLVAL_INTRO,OPpDEREF

RT #130727

In a nested dereference like $a[0]{b}[1], all but the last aelem/helem
will normally have a OPpDEREF_AV/HV flag, while the last won't have a deref
but may well have OPpLVAL_INTRO, e.g.

    local $a[0]{b}[1] = 1;

The code in S_maybe_multideref() which converts a chain of aelem/helem's
into a single mltideref op assumes this - in particular that an op can't
have both OPpLVAL_INTRO and OPpDEREF* at the same time.  However, the
following code violates that assumption:

    @{ local $a[0]{b}[1] } = 1;

In @{expr} = 1, the array is in lvalue context, which makes expr be done
in ref (autovivify) context. So the final aelem in the above expression
gets both OPpLVAL_INTRO and OPpDEREF_AV flags.

In the old days, pp_aelem (probably more by luck than design) would action
OPpLVAL_INTRO and ignore OPpDEREF_AV. This commit makes pp_multideref
behave in the same way. In particular, there's no point in autovivifying
$a[0]{b}[1] as an array ref since the local() will be undone before it
gets a change to be used.

The easiest way to achieve this is to tun off the OPpDEREF flag on the
aelem/helem op if the OPpLVAL_INTRO flag is set.

7 years agoperluniintro: Use uppercase UTF-8 encoding name
Pali [Sun, 18 Sep 2016 15:52:36 +0000 (17:52 +0200)]
perluniintro: Use uppercase UTF-8 encoding name

Reason is consistency with other documentation files.

7 years agoperluniintro: Fix comment, Encode::decode does not have to return string with UTF8...
Pali [Sun, 18 Sep 2016 15:45:57 +0000 (17:45 +0200)]
perluniintro: Fix comment, Encode::decode does not have to return string with UTF8 flag set

7 years agoperluniintro: Suggest to use utf8::decode() instead heavy Encode when sequence of...
Pali [Sun, 18 Sep 2016 15:44:22 +0000 (17:44 +0200)]
perluniintro: Suggest to use utf8::decode() instead heavy Encode when sequence of bytes is valid UTF-8

7 years agopod: Suggest to use strict :encoding(UTF-8) PerlIO layer over not strict :encoding...
Pali [Sun, 18 Sep 2016 15:19:59 +0000 (17:19 +0200)]
pod: Suggest to use strict :encoding(UTF-8) PerlIO layer over not strict :encoding(utf8)

For data exchange it is better to use strict UTF-8 encoding and not perl's utf8.

7 years ago[perl #129061] CURLYX nodes can be studied more than once
Hugo van der Sanden [Wed, 5 Oct 2016 01:20:26 +0000 (02:20 +0100)]
[perl #129061] CURLYX nodes can be studied more than once

study_chunk() for CURLYX is used to set flags on the linked WHILEM
node to say it is the whilem_c'th of whilem_seen. However it assumes
each CURLYX can be studied only once, which is not the case - there
are various cases such as GOSUB which call study_chunk() recursively
on already-visited parts of the program.

Storing the wrong index can cause the super-linear cache handling in
regmatch() to read/write the byte after the end of poscache.

Also reported in [perl #129281].

7 years ago(perl #129281) test for buffer overflow issue
Tony Cook [Sun, 9 Oct 2016 23:46:46 +0000 (10:46 +1100)]
(perl #129281) test for buffer overflow issue

7 years agovi hints for pat.t
Hugo van der Sanden [Mon, 6 Feb 2017 11:11:11 +0000 (11:11 +0000)]
vi hints for pat.t

7 years agoRemove extra terminating semicolon
James E Keenan [Sun, 5 Feb 2017 23:04:36 +0000 (18:04 -0500)]
Remove extra terminating semicolon

Detected by compiling with clang under -Weverything, which includes -Wextra-semi.

Reviewed by jhedden++.

Increment $VERSION in threads.pm.

7 years agoPerl_fbm_instr(): remove dead code.
David Mitchell [Mon, 6 Feb 2017 09:20:04 +0000 (09:20 +0000)]
Perl_fbm_instr(): remove dead code.

For the case where littlestr hasn't been FBM compiled (!SvVALID()), it
can't be SvTAIL(), so there's no need for optional \n handling.

Spotted by Coverity.

7 years agoprevent leak of class name from retrieve_hook() on an exception
Tony Cook [Mon, 6 Feb 2017 00:38:10 +0000 (11:38 +1100)]
prevent leak of class name from retrieve_hook() on an exception

If supplied with a large class name, retrieve_hook() allocates
buffer for the class name and Safefree()s it on exit path.

Unfortunately this memory leaks if load_module() (or a couple of other
code paths) throw an exception.

So use SAVEFREEPV() to release the memory instead.

==20183== 193 bytes in 1 blocks are definitely lost in loss record 4 of 6
==20183==    at 0x4C28C20: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20183==    by 0x55F85D: Perl_safesysmalloc (util.c:153)
==20183==    by 0x6ACA046: retrieve_hook (Storable.xs:4265)
==20183==    by 0x6AD6D19: retrieve (Storable.xs:6217)
==20183==    by 0x6AD8144: do_retrieve (Storable.xs:6401)
==20183==    by 0x6AD85B7: pretrieve (Storable.xs:6506)
==20183==    by 0x6AD8E14: XS_Storable_pretrieve (Storable.xs:6718)
==20183==    by 0x5C176D: Perl_pp_entersub (pp_hot.c:4227)
==20183==    by 0x55E1C6: Perl_runops_debug (dump.c:2450)
==20183==    by 0x461B79: S_run_body (perl.c:2528)
==20183==    by 0x46115C: perl_run (perl.c:2451)
==20183==    by 0x41F1CD: main (perlmain.c:123)

7 years agoFix stack buffer overflow in deserialization of hooks.
John Lightsey [Tue, 24 Jan 2017 16:30:18 +0000 (10:30 -0600)]
Fix stack buffer overflow in deserialization of hooks.

The use of signed lengths resulted in a stack overflow in retrieve_hook()
when a negative length was provided in the storable data.

The retrieve_blessed() codepath had a similar problem with the placement
of the trailing null byte when negative lengths were provided.

7 years agopp_formline: simplify growing of PL_formtarget
David Mitchell [Sat, 4 Feb 2017 15:54:09 +0000 (15:54 +0000)]
pp_formline: simplify growing of PL_formtarget

There's some reasonably complex logic to try and second guess how much
space to allocate or reallocate for the output buffer (some of which is
my doing from 2011, 26e935cfa6e7).

This commit removes most of this and now just does:

initially, grow the buffer by the size of the format. If any further
growing is needed later on (e.g. after a utf8 upgrade or due to @*) then
just grow as needed. This may give less optimal growing in edge cases
( i.e. repeated smaller grows rather than one big grow), but the old code
was often guessing wrong anyway.

This commit also makes it *always* check whether PL_formtarget needs growing
when about to append data to it, which is safer.

7 years agobuffer overrun with format and 'use bytes'
David Mitchell [Sat, 4 Feb 2017 15:10:49 +0000 (15:10 +0000)]
buffer overrun with format and 'use bytes'

RT #130703

In the scope of 'use bytes', appending a string to a format where the
format is utf8 and the string is non-utf8 but contains lots of chars
with ords >= 128, the buffer could be overrun. This is due to all the
\x80-type chars going from being stored as 1 bytes to 2 bytes, without
growing PL_formtarget accordingly.

This commit contains a minimal fix; the next commit will more generally
tidy up the grow code in pp_formline.

7 years agoFix memory leak in generating an exception message
Aaron Crane [Sat, 4 Feb 2017 15:28:19 +0000 (15:28 +0000)]
Fix memory leak in generating an exception message

This was my fault; oops.

7 years agoFix outdated note in perldiag
Aaron Crane [Sat, 4 Feb 2017 14:56:06 +0000 (14:56 +0000)]
Fix outdated note in perldiag

As of 4fa06845e75d453a3101cff32e24c5b743f9819e, the "Odd name/value argument
for subroutine" error has been reported from the callers' perspective.

7 years agoHvTOTALKEYS() takes a HV* as argument
Steffen Mueller [Fri, 3 Feb 2017 08:06:41 +0000 (09:06 +0100)]
HvTOTALKEYS() takes a HV* as argument

Incidentally, it currently works on SV *'s as well because there's an
explicit cast after an SvANY. Let's not rely on that. This commit also
removes a pointless const in a cast. Again. It takes an HV * as argument.
Let's only change that if we have a strong reason to.

7 years agotoke.c: Remove unused param from static function
Karl Williamson [Wed, 1 Feb 2017 20:15:00 +0000 (13:15 -0700)]
toke.c: Remove unused param from static function

Commit d2067945159644d284f8064efbd41024f9e8448a reverted commit
b5248d1e210c2a723adae8e9b7f5d17076647431.  b5248 removed a parameter
from S_scan_ident, and changed its interior to use PL_bufend instead of
that parameter.  The parameter had been used to limit how far into the
string being parsed scan_ident could look.  In all calls to scan_ident
but one, the parameter was already PL_bufend.  In the one call where it
wasn't, b5248 compensated by temporarily changing PL_bufend around the
call, running afoul, eventually, of the expectation that PL_bufend
points to a NUL.

I would have expected the reversion to add back both the parameter and
the uses of it, but apparently the function interior has changed enough
since the original commit, that it didn't even think there were
conflicts.  As a result the parameter got added back, but not the uses
of it.

I tried both approaches to fix this:
    1) to change the function to use the parameter;
    2) to simply delete the parameter.
Only the latter passed the test suite without error.

I then tried to understand why the parameter in the first place, and why
the kludge introduced by b5248 to work around removing it.  It appears
to me that this is for the benefit of the intuit_more function to enable
it to discern $] from a $ ending a bracketed character class, by ending
the scan before the ']' when in a pattern.

The trouble is that modern scan_ident versions do not view themselves as
constrained by PL_bufend.  If that is reached at a point where white
space is allowed, it will try appending the next input line and
continuing, thus changing PL_bufend.  Thus the kludge in b5248 wouldn't
necessarily do the expected limiting anyway.  The reason the approach
"1)" I tried didn't work was that the function continued to use the
original value, even after it had read in new things, instead of
accounting for those.

Hence approach "2)" is used.  I'm a little nervous about this, as it may
lead to intuit_more() (which uses heuristics) having more cases where it
makes the wrong choice about $] vs [...$].  But I don't see a way around
this, and the pre-existing code could fail anyway.

Spotted by Dave Mitchell.

7 years agot/lib/warnings/toke: Fix comment typos
Karl Williamson [Tue, 31 Jan 2017 22:17:56 +0000 (15:17 -0700)]
t/lib/warnings/toke: Fix comment typos

7 years agoavoid double-freeing regex code blocks
David Mitchell [Wed, 1 Feb 2017 15:50:14 +0000 (15:50 +0000)]
avoid double-freeing regex code blocks

RT #130650 heap-use-after-free in S_free_codeblocks

When compiling qr/(?{...})/, a reg_code_blocks structure is allocated
and various SVs are attached to it. Initially this is set to be freed
via a destructor on the savestack, in case of early dying. Later the
structure is attached to the compiling regex, and a boolean flag in the
structure, 'attached', is set to true to show that the destructor no
longer needs to free the struct.

However, it is possible to get three orders of destruction:

1) allocate, push destructor, die early
2) allocate, push destructor, attach to regex, die
2) allocate, push destructor, attach to regex, succeed

In 2, the regex is freed (via the savestack) before the destructor is
called. In 3, the destructor is called, then later the regex is freed.

It turns out perl can't currently handle case 2:

    qr'(?{})\6'

Fix this by turning the 'attached' boolean field into an integer refcount,
then keep a count of whether the struct is referenced from the savestack
and/or the regex. Since it normally has a value of 1 or 2, it's similar
to a boolean flag, but crucially it no longer just indicates that the
regex has a pointer to it ('attached'), but that at least one of the
savestack and regex have a pointer to it. So order of freeing no longer
matters.

I also updated S_free_codeblocks() so that it nulls out SV pointers in
the reg_code_blocks struct before freeing them. This is is generally good
practice to avoid double frees, although is probably not needed at the
moment.

7 years ago(perl #130684) allocate enough space for the extra 'x'
Tony Cook [Wed, 1 Feb 2017 03:34:16 +0000 (14:34 +1100)]
(perl #130684) allocate enough space for the extra 'x'

77c8f26370dcc0e added support for a doubled x regexp flags, and ensured
the doubled flag was passed to the qr// created by
S_compile_runtime_code().

Unfortunately it didn't ensure enough space was allocated for that
extra 'x'.

7 years agoPATCH: [perl #130655] Unrecognized UTF-8 char
Karl Williamson [Tue, 31 Jan 2017 21:17:14 +0000 (14:17 -0700)]
PATCH: [perl #130655] Unrecognized UTF-8 char

The root cause of this was code like this

    if (a)
        b

which got changed into

    if (a)
        c
        b

thus causing 'b' to being changed to be executed unconditionally.  The
solution is just to add braces

    if (a) {
        c
        b
    }

This is why I always use braces even if not required at the moment.  It
was the coding standard at $work.

It turns out that #130567 doesn't even come up with this fix in place.

7 years agoPATCH: [perl #130656] tr// failue with UTF-8 across lines
Karl Williamson [Tue, 31 Jan 2017 18:15:08 +0000 (11:15 -0700)]
PATCH: [perl #130656] tr// failue with UTF-8 across lines

This bug happend under things like

tr/\x{101}-\x{200}/
   \x{201}-\x{301}/

The newline in the middle was crucial.  As a result the second line got
parsed already knowing that the result was UTF-8, and as a result
setting a variable got skipped which happens only when we discover we
need to flip into UTF-8.

The solution adopted here is to set the variable under other conditions,
which leads to it getting set multiple times.  But this extra branch and
setting is confined to somehwat rare circumstances, leaving the mainline
code untouched.

7 years agosignature sub (\x80 triggered an assertion
David Mitchell [Mon, 30 Jan 2017 12:25:55 +0000 (12:25 +0000)]
signature sub (\x80 triggered an assertion

RT #130661

In the presence of 'use feature "signatures"', a char >= 0x80 where a sigil
was expected triggered an assert failure, because the (signed) character
was being was being promoted to int and ended up getting returned from
yylex() as a negative value.

7 years agoAdd test for [perl #129036]
Karl Williamson [Mon, 30 Jan 2017 03:59:44 +0000 (20:59 -0700)]
Add test for [perl #129036]

This was fixed by 6cdc5cd8f36f88172b0fcefdcadec75f5b6600b2
(but I didn't check that this was the actual commit).

7 years agoPATCH: [perl #130666]: Revert "toke.c, S_scan_ident(): Don't take a "end of buffer...
Karl Williamson [Sun, 29 Jan 2017 22:56:20 +0000 (15:56 -0700)]
PATCH: [perl #130666]: Revert "toke.c, S_scan_ident(): Don't take a "end of buffer" argument, use PL_bufend"

This reverts commit b5248d1e210c2a723adae8e9b7f5d17076647431.

This commit, dating from 2013, was made unnecessary by later removal of
the MAD code.  It temporarily changed the PL_bufend variable; doing that
ran afoul of an assertion, added in
fac0f7a38edc4e50a7250b738699165079b852d8, that expects PL_bufend to
point to a terminating NUL.

Beyond the reversion, a test is added here.

7 years agomention PASS2 in reginsert() example
Hugo van der Sanden [Sun, 29 Jan 2017 15:10:02 +0000 (15:10 +0000)]
mention PASS2 in reginsert() example

As per bb78386f13.

7 years agoassert that the RExC_recurse data structure points at a valid GOSUB
Yves Orton [Sat, 28 Jan 2017 15:20:35 +0000 (16:20 +0100)]
assert that the RExC_recurse data structure points at a valid GOSUB

This assert will fail if someone adds code that optimises away a GOSUB
call. At which point they will see the comment and know what to do.

7 years agosilence warnings from tests about impossible quantifiers
Yves Orton [Sat, 28 Jan 2017 14:13:17 +0000 (15:13 +0100)]
silence warnings from tests about impossible quantifiers

thanks to Dave M for noticing....

7 years agoin dump_sub() handle CV ref used as GV
Zefram [Sat, 28 Jan 2017 06:25:28 +0000 (06:25 +0000)]
in dump_sub() handle CV ref used as GV

dump_sub() can receive a CV ref where it's expecting a GV.  Make it
handle that cleanly.  Fixes [perl #129126].

7 years agocroak on sv_setpvn() on a glob
Zefram [Sat, 28 Jan 2017 05:51:00 +0000 (05:51 +0000)]
croak on sv_setpvn() on a glob

A real glob cannot be written to as a string scalar, and a sv_setpvn()
call attempting to do so used to hit an assertion.  (sv_force_normal()
coerces glob copies to strings, but leaves real globs unchanged.)
This isn't exposed through assignment ops, which have special semantics
for assignments to globs, but it can be reached through XS subs that
mutate arguments, and through "^" formats.  Change sv_setpvn() to check
for globs and croak cleanly.  Fixes [perl #129147].

7 years agoonly mess with NEXT_OFF() when we are in PASS2
Yves Orton [Fri, 27 Jan 2017 15:57:40 +0000 (16:57 +0100)]
only mess with NEXT_OFF() when we are in PASS2

In 31fc93954d1f379c7a49889d91436ce99818e1f6 I added code that would modify
NEXT_OFF() when we were not in PASS2, when we should not do so. Strangly this
did not segfault when I tested, but this fix is required.

7 years agoReuse previously-computed flag
Steffen Mueller [Fri, 27 Jan 2017 14:55:51 +0000 (15:55 +0100)]
Reuse previously-computed flag

7 years agoadd some details to the docs for S_reginsert()
Yves Orton [Fri, 27 Jan 2017 09:23:05 +0000 (10:23 +0100)]
add some details to the docs for S_reginsert()

Had these docs been here I would have saved some time debugging. So
save the next guy from the same trouble... (with my memory *I* might
even be the /next guy/. Sigh.)

7 years agofix RT #130561 - recursion and optimising away impossible quantifiers are not friends
Yves Orton [Fri, 27 Jan 2017 09:18:51 +0000 (10:18 +0100)]
fix RT #130561 - recursion and optimising away impossible quantifiers are not friends

Instead of optimising away impossible quantifiers like (foo){1,0} treat them
as unquantified, and guard them with an OPFAIL. Thus /(foo){1,0}/ is treated
the same as /(*FAIL)(foo)/ this is important in patterns like /(foo){1,0}|(?1)/
where the (?1) needs to be able to recurse into the (foo) even though the
(foo){1,0} can never match. It also resolves various issues (SEGVs) with patterns
like /((?1)){1,0}/.

This patch would have been easier if S_reginsert() documented that it is
the callers responsibility to properly set up the NEXT_OFF() of the inserted
node (if the node has a NEXT_OFF())

7 years agorename opnd to operand to save my sanity
Yves Orton [Fri, 27 Jan 2017 07:45:04 +0000 (08:45 +0100)]
rename opnd to operand to save my sanity

7 years agoFix wrong skippage when using -DPERL_DEBUGGING_MSTATS but not -DDEBUGGING
Steve Hay [Fri, 27 Jan 2017 09:21:53 +0000 (09:21 +0000)]
Fix wrong skippage when using -DPERL_DEBUGGING_MSTATS but not -DDEBUGGING

7 years agofix ord of upgraded empty string
Zefram [Fri, 27 Jan 2017 05:53:22 +0000 (05:53 +0000)]
fix ord of upgraded empty string

pp_ord fell foul of the new API stricture added by
d1f8d421df731c77beff3db92d27dc6ec28589f2.  Change it to avoid calling
utf8n_to_uvchr() on an empty string.  Fixes [perl #130545].

7 years agofix range op under aborted constant folding
Zefram [Fri, 27 Jan 2017 03:55:46 +0000 (03:55 +0000)]
fix range op under aborted constant folding

When constant-folding a range/flipflop construct, the op_next threading
of peephole optimisation caused multiple ops in the construct to have
a null op_next, because the final (and top-level) op in the construct
is a null op.  This meant that simple restoration of the top-level
op's op_next after execution wouldn't get it back into a fit state
to be composed with other ops.  In the event that the range construct
couldn't be constant-folded this made it compile to a broken optree.
If it couldn't be constant-folded but could actually be executed, for
example because it generated a warning, this meant the brokenness would
be encountered at runtime.  Execution would stop after the range op,
because of the null op_next.

To avoid this, temporarily mark the null op as a custom op during the
peephole optimisation that supports the execution for constant-folding.
This prevents it being op_next-threaded out, so simple op_next restoring
then works.  If the constant-folding is aborted, it compiles to an
operational optree.  However, the suppression of duplicate peephole
optimisation means that the null op is never ultimately threaded out
as it should be.  For the time being, this stands as a cost of failed
constant-folding of range constructs.

Fixes [perl #130639].

7 years agoCorrect file mode and line lengths to keep porting tests happy.
James E Keenan [Fri, 27 Jan 2017 03:44:03 +0000 (22:44 -0500)]
Correct file mode and line lengths to keep porting tests happy.

7 years agodocument nature and use of $a and $b in sort()
Christian Millour [Thu, 19 Jan 2017 10:49:03 +0000 (11:49 +0100)]
document nature and use of $a and $b in sort()

Signed-off-by: Abigail <abigail@abigail.be>
7 years agoTest for [perl #130567]
Karl Williamson [Thu, 26 Jan 2017 19:29:57 +0000 (12:29 -0700)]
Test for [perl #130567]

This was omitted from 90b58c702e376ab45f13a7f10e14d8c786d05d8a.

7 years agoperlapi: Fix grammar
Karl Williamson [Thu, 26 Jan 2017 05:33:22 +0000 (22:33 -0700)]
perlapi: Fix grammar

7 years agopod: Suggest to use strict UTF-8 encoding when dealing with external data
Pali [Sun, 18 Sep 2016 15:25:48 +0000 (17:25 +0200)]
pod: Suggest to use strict UTF-8 encoding when dealing with external data

For data exchange it is not good idea to use not strict perl's extended
dialect of utf8 encoding.

7 years agoperluniintro: Encode::encode_utf8() not always appropriate
Pali [Sun, 18 Sep 2016 15:21:54 +0000 (17:21 +0200)]
perluniintro: Encode::encode_utf8() not always appropriate

Do not suggest to use Encode::encode_utf8() when you need to know the
byte length of a string Encode module could do some additional
operations and bytes pragma is supposed to do that job.

7 years agoAdd Pali to AUTHORS
Karl Williamson [Thu, 26 Jan 2017 14:10:00 +0000 (07:10 -0700)]
Add Pali to AUTHORS

7 years agoUpdate McUpdate
Chris 'BinGOs' Williams [Thu, 26 Jan 2017 11:43:35 +0000 (11:43 +0000)]
Update McUpdate

7 years agoCherry-pick Scalar-List-Utils tainted.t fix from upstream
Dagfinn Ilmari Mannsåker [Thu, 26 Jan 2017 09:17:41 +0000 (09:17 +0000)]
Cherry-pick Scalar-List-Utils tainted.t fix from upstream

It's fixed properly upstream, by using $^X instead of %ENV, so use that
instead of the now-expired skip.

7 years agoRegenerate customized.dat
Dagfinn Ilmari Mannsåker [Thu, 26 Jan 2017 09:20:26 +0000 (09:20 +0000)]
Regenerate customized.dat

As of commit 254707bab3 cpan/CPAN is in sync with upstream.

7 years agoPATCH: [perl #130567] Assertion failure in scan_const
Karl Williamson [Thu, 26 Jan 2017 05:34:48 +0000 (22:34 -0700)]
PATCH: [perl #130567] Assertion failure in scan_const

It turns out that eval text isn't necessarily parsed by
lex_next_chunk(), but is by lex_start().  So, add a test to there to
look for malformed UTF-8.

7 years agoFix embed.fnc for utf8_to_uvchr_buf
Karl Williamson [Thu, 26 Jan 2017 05:19:55 +0000 (22:19 -0700)]
Fix embed.fnc for utf8_to_uvchr_buf

7 years agoDocumentation patch to recommend newSVpvn over newSVpv.
Colin Newell [Tue, 3 Jan 2017 19:56:13 +0000 (19:56 +0000)]
Documentation patch to recommend newSVpvn over newSVpv.

(Committer made a couple of grammatical corrections)

7 years agoregexec.c: Clarify comment
Karl Williamson [Thu, 26 Jan 2017 04:17:09 +0000 (21:17 -0700)]
regexec.c: Clarify comment

This now explains why we allow the input pointer to go off by 1 at the
end.