This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
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.

7 years agoUse cBOOL() instead of ? TRUE : FALSE
Dagfinn Ilmari Mannsåker [Wed, 18 Jan 2017 12:37:26 +0000 (12:37 +0000)]
Use cBOOL() instead of ? TRUE : FALSE

Except under cpan/ and dist/

7 years agoRT#130623: assertions when tying into non-packages
Aaron Crane [Tue, 24 Jan 2017 19:50:32 +0000 (19:50 +0000)]
RT#130623: assertions when tying into non-packages

7 years agoPerl_sv_dump(): allow a null-pointer argument
Aaron Crane [Tue, 24 Jan 2017 18:25:37 +0000 (18:25 +0000)]
Perl_sv_dump(): allow a null-pointer argument

Since the recursive case already handles null pointers, and this function is
specifically aimed at debugging, it seems sensible to handle a null pointer
at the top level too.

7 years agoS_do_pmop_dump_bar() reduce scope of ch variable
David Mitchell [Tue, 24 Jan 2017 15:23:24 +0000 (15:23 +0000)]
S_do_pmop_dump_bar() reduce scope of ch variable

trivial bit of tidy-up

7 years agohandle op_pv better in op_clear() and op_dump()
David Mitchell [Tue, 24 Jan 2017 14:43:05 +0000 (14:43 +0000)]
handle op_pv better in op_clear() and op_dump()

In op_clear(), the ops with labels stored in the op_pv field (OP_NEXT etc)
fall-through to the OP_TRANS/OP_TRANSR code, which determines whether to
free op_pv based on the OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF flags, which are
only valid for OP_TRANS/OP_TRANSR. At the moment the fall-through fields
don't use either of those private bits, but in case this changes in
future, only check those flag bits for trans ops.

At the same time, enhance op_dump() to display the OP_PV field of such
ops.

Also, fix a leak I introduced in the recently-added S_gv_display()
function.

7 years agoperlapi.pod: remove AvARRAY() example from sortsv()
David Mitchell [Tue, 24 Jan 2017 13:55:45 +0000 (13:55 +0000)]
perlapi.pod: remove AvARRAY() example from sortsv()

The docs for the Perl_sort() API function include a 1-line example
of sorting an AV in-place using  AvARRAY(av). Since AvARRAY() isn't
part of the API and the example would fail on tied or magic arrays,
just delete it.

At the same time, clarify the docs a bit for Perl_sort() and
Perl_sort_flags()

7 years agobetter handle freeing of code blocks in /(?{...})/
David Mitchell [Sun, 30 Oct 2016 12:15:03 +0000 (12:15 +0000)]
better handle freeing of code blocks in /(?{...})/

[perl #129140] attempting double-free

Thus fixes some leaks and double frees in regexes which contain code
blocks.

During compilation, an array of struct reg_code_block's is malloced.
Initially this is just attached to the RExC_state_t struct local var in
Perl_re_op_compile(). Later it may be attached to a pattern. The difficulty
is ensuring that the array is free()d (and the ref counts contained within
decremented) should compilation croak early, while avoiding double frees
once the array has been attached to a regex.

The current mechanism of making the array the PVX of an SV is a bit flaky,
as the array can be realloced(), and code can be re-entered when utf8 is
detected mid-compilation.

This commit changes the array into separately malloced head and body.
The body contains the actual array, and can be realloced. The head
contains a pointer to the array, plus size and an 'attached' boolean.
This indicates whether the struct has been attached to a regex, and is
effectively a 1-bit ref count.

Whenever a head is allocated, SAVEDESTRUCTOR_X() is used to call
S_free_codeblocks() to free the head and body on scope exit. This function
skips the freeing if 'attached' is true, and this flag is set only at the
point where the head gets attached to the regex.

In one way this complicates the code, since the num_code_blocks field is now
not always available (it's only there is a head has been allocated), but
mainly its simplifies, since all the book-keeping is now done in the two
new static functions S_alloc_code_blocks() and S_free_codeblocks()

7 years agoperldelta entries for op_class() and op_dump()
David Mitchell [Tue, 24 Jan 2017 11:48:00 +0000 (11:48 +0000)]
perldelta entries for op_class() and op_dump()

Entries for cd6e487 and 1e85b65

7 years agoOP_CLASS() docs - mention op_class() too
David Mitchell [Tue, 24 Jan 2017 11:38:30 +0000 (11:38 +0000)]
OP_CLASS() docs - mention op_class() too

7 years agoperldelta for 743e3e72117a
Tony Cook [Tue, 24 Jan 2017 04:37:38 +0000 (15:37 +1100)]
perldelta for 743e3e72117a

7 years ago(perl #129190) intuit_method() can move the line buffer
Tony Cook [Thu, 8 Sep 2016 03:21:02 +0000 (13:21 +1000)]
(perl #129190) intuit_method() can move the line buffer

and broke PL_bufptr when it did.

7 years agoperldelta for 71776ae4fad9
Tony Cook [Tue, 24 Jan 2017 00:46:38 +0000 (11:46 +1100)]
perldelta for 71776ae4fad9

7 years ago(perl #129274) avoid treating the # in $# as a comment intro
Tony Cook [Tue, 24 Jan 2017 00:14:28 +0000 (11:14 +1100)]
(perl #129274) avoid treating the # in $# as a comment intro

7 years agopermit goto at top level of multicalled sub
Zefram [Mon, 23 Jan 2017 02:25:50 +0000 (02:25 +0000)]
permit goto at top level of multicalled sub

A multicalled sub is reckoned to be a pseudo block, out of which it is
not permissible to goto.  However, the test for a pseudo block was being
applied too early, preventing not just escape from a multicalled sub but
also a goto at the top level within the sub.  This is a bug similar, but
not identical, to [perl #113938].  Now the test is deferred, permitting
goto at the sub's top level but still forbidding goto out of it.

7 years agoBe consistent in deprecation messages.
Abigail [Mon, 23 Jan 2017 21:29:19 +0000 (22:29 +0100)]
Be consistent in deprecation messages.

Changed one deprecation message to not use a leading v in the Perl
version number, as the other deprecation messages don't have them
either.

7 years agodump.c: handle GV being really a ref to a CV
David Mitchell [Mon, 23 Jan 2017 16:12:38 +0000 (16:12 +0000)]
dump.c: handle GV being really a ref to a CV

RT #129285

These days a 'GV' can actually just be a ref to a CV when the only thing
that would be stored in the glob is a CV. Update S_do_op_dump_bar() to
handle this. Formerly it would trigger an assert on a non-threaded build.

In fact, incorporate the fixed logic into a static function,
S_gv_display(), that is shared by both S_do_op_dump_bar() and
Perl_debop(); so both

    perl -Dx

and

    perl -Dt

get the benefit.

Also for the -Dx case, make it display the raw address of the GV too.

7 years agoreindent OP_AELEMFAST block in S_do_op_dump_bar()
David Mitchell [Mon, 23 Jan 2017 15:14:43 +0000 (15:14 +0000)]
reindent OP_AELEMFAST block in S_do_op_dump_bar()

after previous commit removed an enclosing 'if' block.
Whitespace-only change

7 years agoop_dump(): no OPf_SPECIAL on AELEMFAST,GVSV,GV
David Mitchell [Mon, 23 Jan 2017 15:10:12 +0000 (15:10 +0000)]
op_dump(): no OPf_SPECIAL on AELEMFAST,GVSV,GV

between 5.14 and 5.16 pp_aelemfast changed from using OPf_SPECIAL to
using op type to distinguish between a lexical or glob arg, but op_dump()
hadn't been updated to reflect this. Also, GVSV and GV never used the
OPf_SPECIAL flag, so testing for it with those ops was wrong (but
currently harmless).

7 years agofix some more bizarre indention in dump.c
David Mitchell [Mon, 23 Jan 2017 14:58:29 +0000 (14:58 +0000)]
fix some more bizarre indention in dump.c

(whitespace-only change)

Not mentioning any names to protect the guilty, but about 3 years ago some
code was committed to dump.c that had just bizarre indentation; for
example, this

    if (foo)
        bar

being more like

        if (foo)
     bar

(and this is nothing to do with tab expansion).

This commit fixes up the most glaring issues.

7 years agomess_sv(): access only if PL_curcop is non-null
David Mitchell [Mon, 23 Jan 2017 13:37:21 +0000 (13:37 +0000)]
mess_sv(): access only if PL_curcop is non-null

RT #130621

In Perl_mess_sv(), don't try to add an "at foo line NN" to the error
message if PL_curcop is null.

In the ticket above, the reason that PL_curcop is null is the less
than optimal way that evals free their optree: ideally the optree should
be attached to the eval CV and freed when the CV is; instead a separate
SAVEFREEOP() is done. But that fix is for another time; regardless,
mess_sv() should have a PL_curcop != NULL guard anyway.

7 years agockDEAD: PL_curcop->cop_warnings only if PL_curcop
David Mitchell [Mon, 23 Jan 2017 13:27:07 +0000 (13:27 +0000)]
ckDEAD: PL_curcop->cop_warnings only if PL_curcop

RT #130621

In ckDEAD(), don't check the value of PL_curcop->cop_warnings unless
PL_curcop is non-null.

In the ticket above, the reason that PL_curcop is null is the less
than optimal way that evals free their optree: ideally the optree should
be attached to the eval CV and freed when the CV is; instead a separate
SAVEFREEOP() is done. But that fix is for another time; regardless,
ckDEAD() should have a PL_curcop != NULL guard anyway like isLEXWARN_on()
etc already do.

7 years agoavoid sort assert failure after compile fail
David Mitchell [Mon, 23 Jan 2017 12:27:20 +0000 (12:27 +0000)]
avoid sort assert failure after compile fail

RT #130617

in rpeep(), there's an assert that the optree is sane for the sort's
codeblock. After compile errors, it isn;t necessary sane, so skip the
assert in that case.

I've also changed a kLISTOP->op_next into the equivalent but less
obfuscated kid->op_next.

7 years agoFix memory leak in B::RHE->HASH method.
Sergey Aleynikov [Wed, 4 Jan 2017 22:33:32 +0000 (01:33 +0300)]
Fix memory leak in B::RHE->HASH method.

7 years agolib/utf8.t: Generalize for EBCDIC
Karl Williamson [Sun, 22 Jan 2017 17:55:43 +0000 (10:55 -0700)]
lib/utf8.t: Generalize for EBCDIC

This had an ASCII-specific test which has been failing on EBCDIC
platforms.

7 years agoMove I8 test helpers to common file
Karl Williamson [Sun, 22 Jan 2017 17:53:41 +0000 (10:53 -0700)]
Move I8 test helpers to common file

This moves the code that helps in testing I8 (which is the same as UTF-8
on non-EBCDIC platforms) to t/charset_tools.pl, away from the .t where
they previously were.  This means these can now be used in other .t's.

7 years agofix special-case recreation of *::
Zefram [Sun, 22 Jan 2017 07:26:34 +0000 (07:26 +0000)]
fix special-case recreation of *::

If *:: is called for then as a special case it is looked up as
$::{"main::"}.  If $::{"main::"} has been deleted, then that hash entry
is recreated.  But formerly it was only recreated as an undef scalar,
which broke things relying on glob lookup returning a glob.  Now in
that special case the recreated hash entry is initialised as a glob,
and populated with the customary recursive reference to the main stash.
Fixes [perl #129869].

7 years agohandle errors in gen_constant_list
Zefram [Sun, 22 Jan 2017 03:20:08 +0000 (03:20 +0000)]
handle errors in gen_constant_list

When the attempt to constant-fold a list generates an error, that
error should not be signalled at compile time, but merely abort the
attempt at constant folding, so that the error will occur naturally
at runtime.  This is achieved by wrapping the compile-time execution in
gen_constant_list() in a fake eval block.  This brings it in line with
the scalar fold_constants().  Fixes [perl #129320].

7 years agoavoid disabling utf8 pos cache on tainted strings
David Mitchell [Sat, 21 Jan 2017 15:47:43 +0000 (15:47 +0000)]
avoid disabling utf8 pos cache on tainted strings

RT #130584

When pos() or similar is used on a utf8 string, perl attaches magic
to it that caches a couple of byte<->char offset conversions. This can
avoid quadratic behaviour when continually scanning a big chunk of a long
string to convert a byte offset to a char offset when pos() is called.

v5.17.3-203-g7d1328b added code to invalidate this cache when get magic is
called on an SV, since the get magic may change the value of the SV.

However, under -T, taint magic gets added to a tainted string, which
includes a get method which doesn't actually change the SV's value.
So make a special exception to get-magic-cache-invalidation if the only
get magic on the string is taint.

This stops code like the following going quadratic under -T:

    $_ = "... long tainted utf8 string ...";
    while ( /..../g) {
        my $p = pos(); # calculating pos() goes quadratic
    }

7 years agoS_do_op_dump_bar(): fix some weird indentation
David Mitchell [Fri, 20 Jan 2017 12:40:31 +0000 (12:40 +0000)]
S_do_op_dump_bar(): fix some weird indentation

whitespace-only change

7 years agorevamp the op_dump() output format
David Mitchell [Tue, 17 Jan 2017 17:40:32 +0000 (17:40 +0000)]
revamp the op_dump() output format

This is mainly used for low-level debugging these days (higher level stuff
like Concise having since been created), e.g. calling op_dump() from
within a debugger or running with -Dx. Make it display more info, and use
an ACSII-art tree to show the structure.

The main changes are:

* added 'ASCII-art' tree structure;
* it now displays each op's class and address;
* for op_next etc links, it now displays the type and address of the
  linked-to op in addition to its sequence number;
* the following ops now have their op_other field displayed, like op_and
  etc already do:
    andassign argdefelem dor dorassign entergiven entertry enterwhen
    once orassign regcomp substcont
* enteriter now has its op_redo etc fields displayed, like enterloop
  already does;

Here is a sample before and after of perl -Dx -e'($x+$y) * $z'

Before:

    {
    1   TYPE = leave  ===> NULL
        TARG = 1
        FLAGS = (VOID,KIDS,PARENS,SLABBED)
        PRIVATE = (REFC)
        REFCNT = 1
        {
    2       TYPE = enter  ===> 3
            FLAGS = (UNKNOWN,SLABBED,MORESIB)
        }
        {
    3       TYPE = nextstate  ===> 4
            FLAGS = (VOID,SLABBED,MORESIB)
            LINE = 1
            PACKAGE = "main"
            SEQ = 4294967246
        }
        {
    5       TYPE = multiply  ===> 1
            TARG = 5
            FLAGS = (VOID,KIDS,SLABBED)
            PRIVATE = (0x2)
            {
    6           TYPE = add  ===> 7
                TARG = 3
                FLAGS = (SCALAR,KIDS,PARENS,SLABBED,MORESIB)
                PRIVATE = (0x2)
                {
    8               TYPE = null  ===> (9)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS,SLABBED,MORESIB)
                    PRIVATE = (0x1)
                    {
    4                   TYPE = gvsv  ===> 9
                        FLAGS = (SCALAR,SLABBED)
                        PADIX = 1
                    }
                }
                {
    10              TYPE = null  ===> (6)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS,SLABBED)
                    PRIVATE = (0x1)
                    {
    9                   TYPE = gvsv  ===> 6
                        FLAGS = (SCALAR,SLABBED)
                        PADIX = 2
                    }
                }
            }
            {
    11          TYPE = null  ===> (5)
                  (was rv2sv)
                FLAGS = (SCALAR,KIDS,SLABBED)
                PRIVATE = (0x1)
                {
    7               TYPE = gvsv  ===> 5
                    FLAGS = (SCALAR,SLABBED)
                    PADIX = 4
                }
            }
        }
    }

After:

    1    leave LISTOP(0xdecb38) ===> [0x0]
         TARG = 1
         FLAGS = (VOID,KIDS,PARENS,SLABBED)
         PRIVATE = (REFC)
         REFCNT = 1
         |
    2    +--enter OP(0xdecb00) ===> 3 [nextstate 0xdecb80]
         |   FLAGS = (UNKNOWN,SLABBED,MORESIB)
         |
    3    +--nextstate COP(0xdecb80) ===> 4 [gvsv 0xdeb3b8]
         |   FLAGS = (VOID,SLABBED,MORESIB)
         |   LINE = 1
         |   PACKAGE = "main"
         |   SEQ = 4294967246
         |
    5    +--multiply BINOP(0xdecbe0) ===> 1 [leave 0xdecb38]
             TARG = 5
             FLAGS = (VOID,KIDS,SLABBED)
             PRIVATE = (0x2)
             |
    6        +--add BINOP(0xdeb2b0) ===> 7 [gvsv 0xdeb270]
             |   TARG = 3
             |   FLAGS = (SCALAR,KIDS,PARENS,SLABBED,MORESIB)
             |   PRIVATE = (0x2)
             |   |
    8        |   +--null (ex-rv2sv) UNOP(0xdeb378) ===> 9 [gvsv 0xdeb338]
             |   |   FLAGS = (SCALAR,KIDS,SLABBED,MORESIB)
             |   |   PRIVATE = (0x1)
             |   |   |
    4        |   |   +--gvsv PADOP(0xdeb3b8) ===> 9 [gvsv 0xdeb338]
             |   |       FLAGS = (SCALAR,SLABBED)
             |   |       PADIX = 1
             |   |
    10       |   +--null (ex-rv2sv) UNOP(0xdeb2f8) ===> 6 [add 0xdeb2b0]
             |       FLAGS = (SCALAR,KIDS,SLABBED)
             |       PRIVATE = (0x1)
             |       |
    9        |       +--gvsv PADOP(0xdeb338) ===> 6 [add 0xdeb2b0]
             |           FLAGS = (SCALAR,SLABBED)
             |           PADIX = 2
             |
    11       +--null (ex-rv2sv) UNOP(0xdeb220) ===> 5 [multiply 0xdecbe0]
                 FLAGS = (SCALAR,KIDS,SLABBED)
                 PRIVATE = (0x1)
                 |
    7            +--gvsv PADOP(0xdeb270) ===> 5 [multiply 0xdecbe0]
                     FLAGS = (SCALAR,SLABBED)
                     PADIX = 4

7 years agoadd Perl_op_class(o) API function
David Mitchell [Wed, 18 Jan 2017 12:35:50 +0000 (12:35 +0000)]
add Perl_op_class(o) API function

Given an op, this function determines what type of struct it has been
allocated as. Returns one of the OPclass enums, such as OPclass_LISTOP.

Originally this was a static function in B.xs, but it has wider
applicability; indeed several XS modules on CPAN have cut and pasted it.

It adds the OPclass enum to op.h. In B.xs there was a similar enum, but
with names like OPc_LISTOP. I've renamed them to OPclass_LISTOP etc. so as
not to clash with the cut+paste code already on CPAN.

7 years agoUpdate Module::CoreList for 5.25.10
Abigail [Fri, 20 Jan 2017 16:37:58 +0000 (17:37 +0100)]
Update Module::CoreList for 5.25.10

7 years agoBump the perl version in various places for 5.25.10
Abigail [Fri, 20 Jan 2017 16:31:32 +0000 (17:31 +0100)]
Bump the perl version in various places for 5.25.10

7 years agoNew perldelta for 5.25.10
Abigail [Fri, 20 Jan 2017 16:19:00 +0000 (17:19 +0100)]
New perldelta for 5.25.10

7 years agoTick!
Abigail [Fri, 20 Jan 2017 16:07:55 +0000 (17:07 +0100)]
Tick!

7 years agoEpigraph for 5.25.9
Abigail [Fri, 20 Jan 2017 16:06:54 +0000 (17:06 +0100)]
Epigraph for 5.25.9

7 years agoLet's be consistent v5.25.9
Abigail [Fri, 20 Jan 2017 03:07:32 +0000 (04:07 +0100)]
Let's be consistent

7 years agoAdd perlhist entry for the 5.25.9 release
Abigail [Fri, 20 Jan 2017 03:06:13 +0000 (04:06 +0100)]
Add perlhist entry for the 5.25.9 release

7 years agoAcknowledgements for perldelta
Abigail [Fri, 20 Jan 2017 03:04:09 +0000 (04:04 +0100)]
Acknowledgements for perldelta

7 years agoMore work on perldelta:
Abigail [Fri, 20 Jan 2017 02:48:55 +0000 (03:48 +0100)]
More work on perldelta:

* Finished the update modules.
* Made podchecker -warning -warnings happy.
* Fixed some typos.

7 years agoFix typo in the name the .pm file is generated from.
Abigail [Fri, 20 Jan 2017 02:32:26 +0000 (03:32 +0100)]
Fix typo in the name the .pm file is generated from.

7 years agoUpdate Module::CoreList for 5.25.9
Abigail [Fri, 20 Jan 2017 01:46:55 +0000 (02:46 +0100)]
Update Module::CoreList for 5.25.9

7 years agoMore perldelta entries
Abigail [Fri, 20 Jan 2017 01:15:00 +0000 (02:15 +0100)]
More perldelta entries

7 years agoWork on perldelta
Abigail [Fri, 20 Jan 2017 00:50:32 +0000 (01:50 +0100)]
Work on perldelta

7 years agoMake an entry for the deprecation of certain string delimiters.
Abigail [Thu, 19 Jan 2017 18:40:51 +0000 (19:40 +0100)]
Make an entry for the deprecation of certain string delimiters.

This mostly copies the entry in perldiag to perldeprecation. When 5.30
arrives, the entry in perldiag can dissappear, and the wording in
perldeprecation needs to change -- as the deprecation will no longer
be in the future.

7 years agoTypo fix: one of the =head2's should have been a =head3
Abigail [Thu, 19 Jan 2017 18:37:10 +0000 (19:37 +0100)]
Typo fix: one of the =head2's should have been a =head3

7 years agoutil.c: Allow C backtrace to compile under threads
Karl Williamson [Thu, 19 Jan 2017 20:54:48 +0000 (13:54 -0700)]
util.c: Allow C backtrace to compile under threads

This would not compile due to passing a thread context parameter to
Safefree, which isn't expecting it.

No claim is made by this commit that it works well under threads.  No
claim is made in the documentation to that effect either.

7 years agotoke.c: Refactor part of tr// handling, mostly for EBCDIC
Karl Williamson [Thu, 19 Jan 2017 04:48:51 +0000 (21:48 -0700)]
toke.c: Refactor part of tr// handling, mostly for EBCDIC

Commit af9be36c89322d2469f27b3c98c20c32044697fe changed toke.c to count
the number of UTF-8 variant characters seen in a string so far.  If the
count is 0 when the string has to be upgraded to UTF-8, then only a flag
has to be flipped, saving reparse time.  Incrementing this count wasn't
getting done during the expansion of ranges like A-Z under tr///.  This
currently doesn't matter for ASCII platforms, as the count is currently
treated as a boolen, and it was getting set if a range endpoint is
variant.  On EBCDIC platforms a range may contain variants even if both
endpoints are not.  For example \x00-\xFF.  (\xFF is a control that is
an invariant).  This led to a lot of noise on an EBCDIC smoke, but no
actual tests failing.

I want to keep it as a count so that in the future, things could be
changed so that count can be used to know how big to grow a string when
it is converted to UTF-8, without having to re-parse it as we do now.
It turns out that we need to have this count anyway in the tr/// code as
that grows the string to account for the expansion, and needs to know
how many variants there are in order to do so if the string already is
in UTF-8.  So refactoring that code slightly allows the count to served
double-duty, for the grow if it is already UTF-8, and how much to grow
if it isn't UTF-8.  And it fixes the noise problem on EBCDIC

7 years agotoke.c: Avoid work if tr/a-b/foo/
Karl Williamson [Wed, 18 Jan 2017 22:36:49 +0000 (15:36 -0700)]
toke.c: Avoid work if tr/a-b/foo/

A two-element range here is already fully set up, and no need to do
anything.

7 years agotoke.c: Avoid work for tr/a-a/.../
Karl Williamson [Wed, 18 Jan 2017 21:21:02 +0000 (14:21 -0700)]
toke.c: Avoid work for tr/a-a/.../

A single element range can skip a bunch of work.

7 years agotoke.c: Save a branch
Karl Williamson [Thu, 19 Jan 2017 20:52:57 +0000 (13:52 -0700)]
toke.c: Save a branch

By ordering these sequential tests properly, a branch in the mainline
can be saved.

7 years agotoke.c: Add, clarify some comments, white-space
Karl Williamson [Wed, 18 Jan 2017 21:19:37 +0000 (14:19 -0700)]
toke.c: Add, clarify some comments, white-space

7 years agoperlebcdic: Rmv obsolete text about 'use encoding'
Karl Williamson [Tue, 17 Jan 2017 00:52:55 +0000 (17:52 -0700)]
perlebcdic: Rmv obsolete text about 'use encoding'

7 years agoperlop: Remove obsolete text
Karl Williamson [Tue, 17 Jan 2017 00:51:20 +0000 (17:51 -0700)]
perlop: Remove obsolete text

'use encoding' no longer works.  Don't say it does.

7 years agoFix bug with a digit range under re 'strict'
Karl Williamson [Fri, 13 Jan 2017 20:53:17 +0000 (13:53 -0700)]
Fix bug with a digit range under re 'strict'

"use re 'strict" is supposed to warn if a range whose start and end
points are digits aren't from the same group of 10.  For example, if you
mix Bengali and Thai digits.  It wasn't working properly for 5 groups of
mathematical digits starting at U+1D7E.  This commit fixes that, and
refactors the code to bail out as soon as it discovers that no warning
is warranted, instead of doing unnecessary work.