This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
David Mitchell [Thu, 27 Aug 2015 13:45:13 +0000 (14:45 +0100)]
pp_enteriter: tidy itervar-setting code
rename itervar to itervarp since it's more like an SV** than an SV*,
and set itersave earlier so that it can be used directly rather than
repeatedly dereffing itervarp.
Shouldn't be any functional change.
David Mitchell [Thu, 27 Aug 2015 12:43:49 +0000 (13:43 +0100)]
for loops: don't refcount bump orig var
In something like
for $pkg_var (...)
pp_enteriter() bumps the reference count or $pkg_var before making
itersave point to it. POPLOOP later decrements this ref count.
This bump is unnecessary; since we are effectively transferring ownership
(and thus ref count contribution) of the $pkg_var SV from the GvSV slot of
*pkg_var to the itersave slot of the context struct, the overall ref count
of the var should remain unchanged.
So skip the bump and later undo. This should make no functional difference;
it's just more efficient.
David Mitchell [Thu, 27 Aug 2015 12:40:20 +0000 (13:40 +0100)]
POPLOOP(): no need to mortalise current item
Now that pp_return() protects its return arg(s) against premature freeing
before calling dounwind(), there's no need for POPLOOP to mortalise the
current item.
David Mitchell [Wed, 19 Aug 2015 11:33:24 +0000 (12:33 +0100)]
Add itersave field to LOOP context struct
When entering a for loop, rather than saving the original loop variable on
the save stack, save it in the context struct. Quicker and simpler.
Note that as of this commit, entering a for loop no longer saves anything
on the save stack.
David Mitchell [Thu, 27 Aug 2015 11:13:58 +0000 (12:13 +0100)]
POPLOOP: call LEAVE_SCOPE()
in PUSHLOOP, save the current PL_savestack_ix, and in POPLOOP, do
LEAVE_SCOPE(cx->blk_loop.old_savestack_ix);
This is in preparation for shortly not wrapping loops in ENTER/LEAVE.
David Mitchell [Thu, 27 Aug 2015 11:02:27 +0000 (12:02 +0100)]
pp_return(): reindent following previous commit
whitespace-only change
David Mitchell [Tue, 25 Aug 2015 12:57:55 +0000 (13:57 +0100)]
pp_return(): handle dounwind() freeing args
Currently only POPSUB (and other sub-like contexts, such as POPEVAL) do a
LEAVE_SCOPE() as well as restoring things from the context struct. This
means that if pp_return() does a dounwind() to pop back to the next
SUB/EVAL/FORMAT context, LEAVE_SCOPE() won't get called, and any return
values aren't prematurely freed, e.g. in the following
sub f {
for (...) {
my $x = 1;
return $x;
}
}
POPLOOP() won't call LEAVE_SCOPE(), so $x doesn't get freed.
The next commit is about to change that: POPLOOP() will indeed call
LEAVE_SCOPE(), (and later commits may make other POPFOO() types do that
too). So in preparation, this commit makes pp_return() preserve any return
args before calling dounwind().
David Mitchell [Wed, 26 Aug 2015 10:34:59 +0000 (11:34 +0100)]
pp_leaveloop: use SVs_PADTMP|SVs_TEMP
When calling leave_common(), most callers specify the "safe" return SVs
that don't need copying as being those with SVs_PADTMP or SVs_TEMP
set (leaveeval is a correct exception to this this).
pp_leaveloop() specified no flags, meaning that it always copies. This
appears to be just be an oversight rather than being for any good reason.
David Mitchell [Wed, 26 Aug 2015 08:53:09 +0000 (09:53 +0100)]
S_leave_common(): simplify SVs_PADTMP handling
Now that SVs_PADTMP is a simple flag again (at one point its meaning was
inferred from the state of two flags) it no longer needs special handling
in S_leave_common().
David Mitchell [Sun, 19 Jul 2015 09:51:38 +0000 (10:51 +0100)]
for my $x (...): $x is always stale
Remove the code in pp_enteriter that turns $x's staleness off and schedules
on the save stack for it to be turned back on at scope exit.
Since 'for my $x' works by making $x's pad slot temporarily point to
each item in turn, the "real" $x which lives in the pad outside of loop
time can never be accessed by the usual closure tricks (BEGIN, eval,
nested named subs etc) during a loop, so doesn't need to be marked as not
stale.
Skipping this step is one less thing to be pushed onto the save stack
on each for loop entry.
David Mitchell [Fri, 17 Jul 2015 22:22:29 +0000 (23:22 +0100)]
pp_last: use debugging LEAVE variant
Make the two LEAVEs in pp_last() be instead
LEAVE_with_name("loop2");
LEAVE_with_name("loop1");
which is more self-documenting and will trap mistakes on DEBUGGING builds
David Mitchell [Fri, 17 Jul 2015 21:49:40 +0000 (22:49 +0100)]
only call leave_common in non-void context
A lot of the pp_leave* functions call S_leave_common() to process
any return args. Since many of these tend to be used in void context
(e.g. plain blocks {; ... }, for loops etc) tst gimme and only call
these function is non-void. For void context the function is mostly
a noop anyway; the only thing we're skipping is TAINT_NOT, which
doesn't matter in void context.
David Mitchell [Fri, 17 Jul 2015 21:23:51 +0000 (22:23 +0100)]
CXt_EVAL: save savestack_ix and tmps_floor in CX
In the various places that do PUSHEVAL (eval, require etc), eliminate
ENTER; SAVETMPS
and instead save the old values of PL_savestack_ix and PL_tmps_floor
directly in the eval context frame, similarly to how subs have been
recently changed.
This is faster and cleaner.
David Mitchell [Fri, 17 Jul 2015 20:51:25 +0000 (21:51 +0100)]
move SAVETMPS next to PUSHEVAL
In the various places where PUSHEVAL() is used, a SAVETMPS appears
shortly before it. Move each occurrence of SAVETMPS to just after the
SAVETMPS, in preparation shortly for making PUSHEVAL responsible for
saving PL_tmps_floor.
In theory this could make certain temporary items created during
eval/require startup to be freed slightly later. I don't know whether
this is is an issue or not. No tests fail ;-)
David Mitchell [Fri, 17 Jul 2015 13:44:32 +0000 (14:44 +0100)]
call_sv(), fold_const(): different CX pop test
Perl_call_sv() and S_fold_constants() both have similar code that:
pushes an EVAL context, does a JMPENV_PUSH() and CALLRUNOPS(), then
optionally pops the EVAL context.
The optionally part depends on whether what's doing the dying
has already popped the context before long-jumping. Currently the decision
on whether to pop is based on whether the scope stack has already been
popped.
This commit changes that to whether the context stack has already been
popped, since shortly we're going to change eval contexts so that the old
savestack_ix is stored in the CX struct rather than on the scope stack.
I ran this code with some asserts that the two conditions were identical,
and nothing failed.
David Mitchell [Thu, 16 Jul 2015 13:44:06 +0000 (14:44 +0100)]
CXt_FORMAT: save ss_ix and tmps_floor in CX struct
To match the recent work in this branch on CXt_SUB, make CXt_FORMAT save
PL_savestack_ix and PL_tmps_floor in the context structure rather than
doing ENTER/SAVETMPS. It's more efficient and more consistent.
David Mitchell [Mon, 13 Jul 2015 15:31:20 +0000 (16:31 +0100)]
pp_entersub(): reduce life of padlist var
only set it when it's needed
David Mitchell [Mon, 13 Jul 2015 15:25:36 +0000 (16:25 +0100)]
pp_entersub: unroll some CvFLAGS(cv) tests
Do a single bit comparison rather than two conditionals. Slightly faster.
David Mitchell [Mon, 13 Jul 2015 15:18:55 +0000 (16:18 +0100)]
pp_entersub(): reduce scope of gimme
Only calculate the gimme var where its needed.
David Mitchell [Mon, 13 Jul 2015 12:11:01 +0000 (13:11 +0100)]
pp_entersub(): don't prematurely calc hasargs
Currently at the top of pp_entersub() is:
const bool hasargs = (PL_op->op_flags & OPf_STACKED) != 0;
Defer testing this flag and/or saving it to a local var until
its actually needed. This is a micro-optimisation.
David Mitchell [Mon, 13 Jul 2015 11:48:17 +0000 (12:48 +0100)]
revamp pp_entersub()'s CV locating code
The big switch statement at the top of pp_entersub() is intended
to extract the CV from the passed argument, which might be a CV, a GV,
a ref to a CV, etc etc.
In 5.22.0, an optimisation was added to stashes such that if an entry
contained only a CV, then a ref to the CV was stored in the stash, rather
than a GV. This means that in the common case for a plain sub call, sv is
now a ref to a CV rather than a GV. So update the code to:
1) remove the special-casing of GVs;
2) add special casing for the sv being a non-magical, non-overloaded RV
pointing to a CV;
3) add special casing for the sv being a CV (true on method calls);
3) move the rare "sv == &PL_sv_yes" test further down the condition chain;
4) generally rearrange the switch cases so that common things fall though
and uncommon things do a goto;
5) sprinkle more LIKELY() pixie dust.
Part of the intention of special-casing is to avoid doing an indirect
branch by avoiding the switch statement completely.
David Mitchell [Mon, 13 Jul 2015 10:48:04 +0000 (11:48 +0100)]
tweak POPSUB()
re-order things slightly in POPSUB() so that values aren't being
read into local vars before they're needed (so the compiler doesn't
have to write the values back out to the local stack frame if it runs out
of spare registers).
Also, re-order the fields in struct block_sub so that they roughly
correspond with the order in which they are accessed by POPSUB. This is on
the voodoo theory that if the struct straddles a cache line, we may
trigger a prefetch of the second line, so the extra data will be ready for
us when we need it.
David Mitchell [Sat, 11 Jul 2015 21:13:51 +0000 (22:13 +0100)]
Eliminate ENTER/LEAVE from sub calls
Every sub call is wrapped in an ENTER/LEAVE pair, which uses the next
free slot on the scope stack to save and then restore the old value of
PL_savestack_ix. Instead, store the old value in a new field in the
context structure, old_savestack_ix. This is quicker and simpler.
Not that we keep the ENTER/LEAVE for XS sub calls, as they don't push a
context frame, and so have nowhere else to remember PL_savestack_ix.
As a side-effect, this commit fixes a TODO test in t/op/sub.t,
which was related to dying while popping a context, then re-popping that
context. For the second pop, the scopestack has since been overwritten
and so too much was getting popped from the savestack. Since we no longer
use the scopestack, it's no longer an issue.
David Mitchell [Sat, 11 Jul 2015 15:43:25 +0000 (16:43 +0100)]
pp_hot.c: skip unnecessary test
This condition:
!CvROOT(cv) && !CvXSUB(cv)
can be simplified because those two cv fields are actually
the same slot in a union.
David Mitchell [Sat, 11 Jul 2015 14:37:11 +0000 (15:37 +0100)]
pp_entersub(): simplify autoload logic
eliminate a label and goto by by just setting cv to null on failure,
and have a single "if (!cv) croak()" test at the end of the loop.
David Mitchell [Sat, 11 Jul 2015 14:30:38 +0000 (15:30 +0100)]
pp_entersub(): eliminate a label
replace:
retry:
if (A) die;
if (B) {
...;
goto retry;
}
with
while (B) {
...;
}
if (A) die;
it's functionally equivalent except that the A test is now only
tried after we have been successful at B. This is ok, because
A is testing for an uncloned closure prototype, while B is looking
for a CV stub which needs autoloading,and it doesn't rally matter
which we test for first.
David Mitchell [Sat, 11 Jul 2015 13:42:56 +0000 (14:42 +0100)]
add old_tmpsfloor field to CXt_SUB context frame
Rather than saving and restoring PL_tmps_floor on subroutine entry/exit
by using SAVETMPS and the save stack, store the old value directly
in the context struct and make PUSHSUB/POPSUB handle the saving and
restoring.
David Mitchell [Sat, 11 Jul 2015 13:16:29 +0000 (14:16 +0100)]
PUSH_MULTICALL: move SAVETMPS later
Move the SAVETMPS to just after the PUSHSUB. This should make no
functional difference, because nothing should have affected the TMPS stack
between the old and the new code positions.
David Mitchell [Sat, 11 Jul 2015 13:04:59 +0000 (14:04 +0100)]
pp_dbstate: do SAVETMPS etc in both branches
pp_dbstate() does an XS or non-XS subroutine call to &DB::DB;
move the SAVETMPS from before the (if CvISXSUB(cv)) test to the head of
both branches. This duplication of code is currently a noop, but will
shortly allow us to handle things differently in the two branches.
David Mitchell [Sat, 11 Jul 2015 12:58:47 +0000 (13:58 +0100)]
pp_sort: move SAVETMPS later
Move the SAVETMPS to just after the PUSHSUB. This should make no
functional difference, because nothing should have affected the TMPS stack
between the old and the new code positions.
For the OPf_SPECIAL/ CXt_NULL case, which doesn't do a PUSHSUB,
do another SAVETMPS there too.
David Mitchell [Sat, 11 Jul 2015 12:45:01 +0000 (13:45 +0100)]
pp_goto: do SAVETMPS etc in XS and non-XS branches
Move a SAVETMPS;SAVEFREESV(cv); from before the "if (CvISXSUB(cv))" test
to the head of both branches. This duplication of code is currently
a NOOP, but will shortly allow us to handle things differently in the two
branches.
David Mitchell [Sat, 11 Jul 2015 12:32:03 +0000 (13:32 +0100)]
pp_entersub(): move SAVETMPS next to PUSHSUB
It it intended that eventually PUSHSUB() will do the SAVETMPS itself,
so move the SAVETMPS up so that it's next to the PUSHSUB.
There should be nothing between those two points that use the TEMPS stack,
so this commit should have no functional effect.
David Mitchell [Sat, 11 Jul 2015 12:10:00 +0000 (13:10 +0100)]
pp_entersub(): remove an unnecessary condition
The code that scans the args list making mortal copies is protected by an
if (LIKELY(hasargs)) {
However, a sub called as "&foo;" (which is how hasargs is determined)
won't have pushed anything on the stack, so the first part of that code
block, "while (svp < SP)", will drop out immediately.
So skip doing the hasargs test.
NB - it's possible in theory for XS code to call call_sv() jn such a way
as to both have !hasargs but with stuff on the stack; in this worst case,
we just waste a bit of time making some mortal copies of those args.
David Mitchell [Sat, 11 Jul 2015 11:43:43 +0000 (12:43 +0100)]
pp_entersub(): mortal-copy args earlier
Move the code earlier which makes a mortal copy of any PADTMP args.
This should make no functional difference, but will shortly allow
us to move the SAVETMPS earlier too (while still coming after the
mortal copying).
David Mitchell [Sat, 11 Jul 2015 10:49:13 +0000 (11:49 +0100)]
pp_leavesub: simplify recursion test
Part of pp_leavesub() tests whether we're in recursion by looking
at CvDEPTH(cx->blk_sub.cv). Instead, just directly check
cx->blk_sub.olddepth, which is equivalent (allowing for an offset of 1)
but faster.
David Mitchell [Sat, 11 Jul 2015 10:05:55 +0000 (11:05 +0100)]
clear_defarray(): clear @_ if possible
clear_defarray() is called during sub exit to clean up @_ in the
less common case where @_ has somehow gotten reified.
At the moment it just frees the old @_, then creates a new AV and
sticks it in pad[0].
This commit changes it so that for the reasonably common case of a reified
@_ where it's not magical and only has a reference count of 1, just call
av_clear() on it, rather than freeing and recreating.
Typical code that will benefit from this change is be something like:
sub f { push @_, ...; ... }
which causes the AV to be reified, but not to become otherwise visible.
David Mitchell [Sat, 11 Jul 2015 09:52:49 +0000 (10:52 +0100)]
pp_goto(): use clear_defarray()
In pp_goto(), use the newly-added clear_defarray() function
to the clear the old @_. This ensures that POPSUB() and pp_goto()
do the same thing. Note that clear_defarray() is actually better than
the old pp_goto() code, in that it pre-sizes the newly-created array
to match the size of the array being abandoned.
David Mitchell [Sat, 11 Jul 2015 09:40:23 +0000 (10:40 +0100)]
add Perl_clear_defarray()
This function implements the less commonly used branch in the POPSUB()
macro that clears @_ in place, or abandons it and creates a new array
in pad slot 0 of the function (the common branch is where @_ hasn't been
reified, and so can be clered simply by setting fill to -1).
By moving this out to a separate function we can avoid repeating the same
code everywhere the POPSUB macro is used; but since its only used
in the less frequent cases, the extra overall of a function call doesn't
matter.
It has a currently unused arg, 'abandon', which will be used shortly.
David Mitchell [Sat, 11 Jul 2015 09:06:39 +0000 (10:06 +0100)]
avoid leaking @_ in goto
pp_goto temporarily bumps the reference count of @_ while doing
LEAVE_SCOPE(), to stop it getting prematurelly freed. If something
dies during the save stack unwinding, it will leak.
Instead, make it mortal.
David Mitchell [Thu, 9 Jul 2015 08:22:38 +0000 (09:22 +0100)]
goto.t: add freeing CV test
This code SEGVed in a cpan/ module while I was messing with pp_goto.
Add it to t/op/goto.t so that it can SEGV there instead.
David Mitchell [Sun, 5 Jul 2015 09:21:14 +0000 (10:21 +0100)]
pp_goto: do the DIEing before the POPing
Rearrange the beginning of the 'goto &func' part of pp_goto so that it
does most of its error checks (e.g. "Can't goto subroutine from an eval")
before it starts doing "return-ish" stuff. This makes the code slightly
cleaner, especially as it doesn't have to undo the SvREFCNT_inc(cv) guard
in every die branch.
David Mitchell [Sun, 5 Jul 2015 09:08:25 +0000 (10:08 +0100)]
eliminate a goto in pp_goto (!)
Replace a C-level goto with a while loop: logically equivalent,
but doesn't use a goto. (I know, I know, this is in pp_goto, but even
so...)
David Mitchell [Fri, 3 Jul 2015 10:40:01 +0000 (11:40 +0100)]
pp_goto: a couple of cosmetic changes
had a lable outdented 2, not 4 chars, and move a comment describing
what a branch does from before to after the 'if'.
David Mitchell [Fri, 3 Jul 2015 10:14:30 +0000 (11:14 +0100)]
make POP_SAVEARRAY() safe
POP_SAVEARRAY() frees the current @_ and restores it to the callers value.
As currently defined, it frees the old AV then updates GvAV(PL_defgv). If
the free old the old AV triggers a destructor for example, then in
theory something bad could happen.
I couldn't actually find a simple failure case, but I suspect that
something like
sub f { *_ = bless [], 'Foo' }
where Foo::DESTROY is an XS sub that messes with GvAV(PL_defgv), could do
it.
Anyway to play safe, this commit updates the GvAV() slot and *then* frees
the old AV. This our normal modus operandi in other places anyway.
The equivalent code in pp_goto already does this the safe way. This commit
also updates pp_goto to use the (now equivalent) POP_SAVEARRAY() macro.
David Mitchell [Thu, 2 Jul 2015 09:14:14 +0000 (10:14 +0100)]
t/perf/benchmarks: add a few sub and goto tests
David Mitchell [Wed, 1 Jul 2015 19:19:23 +0000 (20:19 +0100)]
pp_entersub: skip resetting @_
Whenever we leave a sub by whatever means (pp_leavesub, pp_return,
pp_goto, die etc) it is the responsibility of the code that pops
the SUB context to clean up the private @_ of that sub (i.e pad[0])
so that it's empty and not real.
There's some code in pp_entersub that duplicates this check. I believe
this check is unnecessary and so this commit removes it and replaces it
with an assert. It was added by
221373f04 in 1999 to fix the issue
described in
Subject: [ID
19991015.010] [BUG 5.005_62 Assertation failed:
"pp_ctl.c" line 2443]
Message-Id: <
19991016024500.A32541@athens.aocn.com>
There were two fixes applied for this issue; the other was
0253cb4. I think the second commit actually fixed the issue and the
first fix was a red herring.
If my newly-added assert fails, it implies that something needs fixing in
the context-popping code, rather than in pp_entersub.
In fact the new assert showed up one issue: the special-case handling
of @_ for &CORE::undef in pp_coreargs wasn't emptying the array,
so I added a CLEAR_ARGARRAY().
David Mitchell [Wed, 1 Jul 2015 15:50:53 +0000 (16:50 +0100)]
improve @_ commentary in pp_goto
Following on from the previous commit which removed cx.argarray,
remove 'argarray' from the comments about @_, and at the same time
generally overhaul those comments; in particular, explaining how
it's a two part process of donating the current @_ to the new sub.
David Mitchell [Wed, 1 Jul 2015 12:37:32 +0000 (13:37 +0100)]
eliminate the argarray field from the CX struct
At the end of a normal sub call there are often 3 AVs of interest
associated with @_; these are:
cx->blk_sub.savearray the caller's @_
GvAV(PL_defgv) the current sub's current @_
cx->blk_sub.argarray the current sub's original @_
Note that those last two can differ: if for example the sub does
local *_ = [];
Each sub's arg array is created and stored in pad slot 0 at the time
the sub is created. When a sub is called, pp_entersub() does
cx->blk_sub.argarray = PL_curpad[0]
The argarray field is used in two main places:
* at subroutine exit, to clear/abandon the sub's original @_;
* in pp_caller, to set @DB::args to the caller(n)'s args.
In the first case, the last few commits have arranged things so that at
that point, PL_curpad always points to the current pad of the sub being
exited from. So we can just use PL_curpad[0] rather than
cx->blk_sub.argarray.
In the second case (which is not performance critical), we can just use
cx->blk_sub.cv
and
cx->blk_sub.olddepth+1
to find the pad of that call frame's CV.
So we can eliminate the argarray field. This saves a write during
a sub call, and potentially reduces the size of the context struct.
It also makes the code marginally less confusing: there are now 3 arrays
pointed to from 3 places, rather than 3 arrays pointed to from 4 places.
The asserts added in the previous commit confirmed that using argarray
is the same as using PL_curpad[0]; They also confirmed that the current
PL_curpad matches the current CV at the current depth. Those latter
asserts are kept for now.
David Mitchell [Wed, 1 Jul 2015 11:21:06 +0000 (12:21 +0100)]
assert that it's safe to remove CX.argarray field
This commit adds assertions that demonstrate that the next commit is safe.
See the description of that commit for details.
David Mitchell [Wed, 1 Jul 2015 08:57:51 +0000 (09:57 +0100)]
Unwind save stack in sync with POPEVAL
During normal exit from an eval, both POPEVAL and LEAVE are done,
meaning that the context stack and save stack are unwound in lockstep.
However, during an exception, dounwind() does the POPEVAL but not the
LEAVE, leaving them temporarily out of step.
About a 2 years ago, with v5.19.3-139-g2537512, subs and formats were
changed so that the save stack popping was done in sync in dounwind.
This commit extends that to evals too.
I'm doing this principally so that PL_compad will always be restored at
the correct moment, which will shortly allow me to eliminate the argarray
field from the context struct.
NB: unlike POPSUB and POPFORMAT, I've added the LEAVE_SCOPE to dounwind
rather than directly adding to the POPEVAL macro - this is because the
various places that use POPEVAL typically use it earlier than the
comparable places with POPSUB, which means they aren't ready to pop the
save stack yet.
NNB: The LEAVE_SCOPE can't be extended to all context types in dounwind(),
only to sub-ish types - specifically the types that can be 'return'ed from.
This is because if you 'return' from a sub or eval, pp_return will
unwind all contexts down to the next sub or eval (discarding all the loops
etc that it escaping out of), but the args it is returning shouldn't
be prematurely freed.
David Mitchell [Wed, 1 Jul 2015 06:56:39 +0000 (07:56 +0100)]
pp_goto: skip restoring PL_comppad
Now that PL_comppad is saved in the context struct rather than on the save
stack, we can better control when and how it is restored. In the case of
pp_goto, there's no need to restore the caller's PL_comppad in the non-XS
case, since we will be immediately setting it to the new function's pad.
AS well as being slightly more efficient, this avoids restoring PL_comppad
too early, where if we subsequently croak we re-process the CXt_SUB block
in dounwind, but this time with the wrong pad.
In particular, by having always PL_curpad[0] == cx.argarray at sub exit
time, we can shortly eliminate the argarray field.
David Mitchell [Tue, 30 Jun 2015 07:03:43 +0000 (08:03 +0100)]
undef *_; goto &f: update cx.argarray
In something like
sub f { goto &g }
normally g's pad[0] is updated to hold the passed-across @_, and the
context block's argarray field is updated to point to g's @_ too.
However in the case of
sub f { undef *_; goto &g }
cx.argarray isn't being updated. This is probably harmless (I couldn't
come up with a test case that fails), but for consistency, update it too.
This is mainly so that over the next few commits, this condition will come
to apply consistently:
cx.argarray == PL_curpad[0]
and so the argarray field can be eliminated.
David Mitchell [Mon, 29 Jun 2015 11:33:35 +0000 (12:33 +0100)]
make "for my $lex {}" faster under ITHREADS
Normally at the start of a 'for' iteration (pp_enteriter), we store the
address of the GV or the address of the pad slot of the iteration variable
in the CX struct, so we can quickly access and update it in pp_iter. For
the ITHREADS case however, the pad may change if the thread is cloned, so
instead the address of PL_comppad was stored, and then updated during
cloning. This meant that on each iter, we would have to retrieve the saved
PL_comppad address from the ctx struct, retrieve the targ from the saved
my_op, and do a (perlish) array indexing.
Thuis commit makes this faster by, for the ITHREADS case, storing both
PL_comppad and svp = &PLcurpad[targ]. In pp_iter(), we're fast by directly
accessing *svp; while storing PL_comppad allows us to update both it and
svp during thread cloning.
This requires one extra pointer in the block_loop part of the context
union under threads, but this is already smaller than some other parts of
the union, so has no effect.
Note that the oldcomppad field was formerly part of the itervar_u union,
but is now a separate field within the larger block_loop struct (but only
on threaded builds).
Note also that the tests I've added I retrieved from an old WIP private
branch that contained a forerunner of this commit, so they may not be
entirely relevant to the current form of this commit. But extra tests
can never hurt, so I've included them.
David Mitchell [Mon, 29 Jun 2015 11:02:18 +0000 (12:02 +0100)]
eliminate cx->blk_sub.oldcomppad
In the CXt_SUB sub-struct of the context struct, there is a field
called oldcomppad. Despite the "old" in its name, this field actually
stores the value of PL_comppad of the new sub, not of the caller.
It's only use currently is in POPSUB() when abandoning a reified @_, to
locate PL_curpad[0] of the current sub in order to stick a new empty AV
there. This is a relatively rare occurrence, and the pad slot can be
found (slightly less efficiently) from the saved CV and its depth.
David Mitchell [Mon, 29 Jun 2015 10:36:27 +0000 (11:36 +0100)]
document unrolled PUSHSUB/POPSUB
some places in the code do some or all of the same activities as
PUSHSUB() and POPSUB(). Add comments in those places pointing out that
it's a partially unrolled PUSH/POPSUB(). This will also help if someone
greps the code looking for all the places in core that supposedly does
a PUSH/POPSUB.
David Mitchell [Mon, 29 Jun 2015 10:27:36 +0000 (11:27 +0100)]
save old PL_comppad in CXt_SUB/FORMAT block
Currently when we call a sub, the old value of PL_comppad is
saved on the save stack using SAVECOMPPAD(). Instead, save it in
a new field in the context struct, called prevcomppad. This is simpler
and more efficient.
Note that there is already a confusingly-named field in the CXt_SUB
context struct called oldcomppad, which holds the value of PL_comppad for
the *current* sub, not for its caller. So the new field had to be called
something else.
One side effect of this is that an existing bug - which causes too much
to be popped off the savestack when dieing while leaving a sub scope - is
now more noticeable, since PL_curpad and SAVEt_CLEARSV are now out of
sync: formerly, the unwinding of the save stack restored PL_curpad in
lockstep. The fix for this will come later in this branch, when the whole
issue of context stack popping order and reentrancy is addressed; for
now, a TODO test has been added.
David Mitchell [Fri, 26 Jun 2015 11:17:59 +0000 (12:17 +0100)]
pp_entersub: remove extraneous SAVETMPS
The branch that handles "no cv, try autoload" does a SAVETMPS.
This serves no purpose, since we will shortly be doing another SAVETMPS
anyway with no intervening ENTER.
David Mitchell [Thu, 25 Jun 2015 15:08:02 +0000 (16:08 +0100)]
pp_goto: SvREFCNT_dec(oldcv) *after* undef test
pp_goto does a LEAVE, then checks that the new CV hasn't been undefed
by the LEAVE. If it has, it croaks.
Move the decrementing of the old CV's ref count and depth to *after*
this check, since the POPSUB done during the croak unwind will do the
decrement also. Otherwise the old sub will be doubly freed.
David Mitchell [Thu, 25 Jun 2015 14:18:25 +0000 (15:18 +0100)]
pp_goto(): reorder LEAVE_SCOPE for consistency
pp_leavesub (via POPSUB()) does a LEAVE_SCOPE before decrementing the CV's
ref count and depth; pp_goto does it after. Reorder it for consistency
with leavesub.
At this point I make no assertion as to which way round is the most
correct.
David Mitchell [Thu, 25 Jun 2015 14:08:37 +0000 (15:08 +0100)]
pp_goto: use cx->blk_oldscopesp
POPSUB() does:
LEAVE_SCOPE(PL_scopestack[cx->blk_oldscopesp - 1])
while pp_goto(), which manually does the relevant actions from POPSUB(),
does:
LEAVE_SCOPE(PL_scopestack[PL_scopestack_ix - 1])
For consistency, make pp_goto() use cx->blk_oldscopesp instead. In fact
at that point they should both hold the same value (and I've added an
assert to that effect), since we should have just popped any nested
scopes.
David Mitchell [Thu, 25 Jun 2015 11:05:50 +0000 (12:05 +0100)]
SvREFCNT_inc(cv) recursive subs
A CXt_SUB context frame owns 1 reference count to the CV being called,
but only if it's the bottom-level call to that CV; recursive calls don't
count.
This commit changes it so that every CXt_SUB frame owns a reference count.
This removes a lot of "if (CvDEPTH(cv) < 2)" type tests from the code and
makes things generally simpler and less bug-prone.
For ordinary (non-recursive) sub calls it will now be slightly faster, as
it no longer has to do the CvDEPTH check on sub entry and exit; for subs
being recursed into, it will probably be slightly slower, as although it
no longer has to the CvDEPTH check on entry and exit, it now has to do a
refcnt ++/-- instead.
This also means that a deeply recursing sub will have a very high ref
count; but there is no new additional danger of overflow, as sv_refcnt is
U32 while xcv_depth is I32: so the latter will still overflow earlier
anyway.
David Mitchell [Thu, 25 Jun 2015 09:48:58 +0000 (10:48 +0100)]
eliminate an SAVEFREESV(cv) from PUSHSUB
When a CXt_SUB context is pushed, the reference count of the CV is
increased (and is effectively owned by that context frame). It is
decremented when the context frame is popped.
There was an issue in that the POPSUB was done before the LEAVE,
which meant that at sub exit, the sub could be freed before stuff that
referred to that sub was done (such as lexicals being cleaned up by
SAVEt_CLEARSV).
This was fixed by perl-5.005_02-2095-gb0d9ce3, which split POPSUB
into POPSUB and LEAVESUB with the latter responsible for the decrement.
So for example code might do POPSUB; LEAVE; LEAVSUB.
However this wasn't sufficient, because a similar thing happened during
die, for example
sub d {die}
my $f;
$f = sub {my $x=1; $f = 0; d};
eval{ $f->() };
since all *all* the CXt_SUB contexts were popped with POPSUB/LEAVSUB
*before* LEAVE was called.
I fixed this with perl-5.8.0-3206-gb36bdec, by adding another increment to
the CV and doing a SAVEFREESV(cv), both in PUSHSUB. This meant that
the save stack would hold at least one reference to the CV while being
unwound.
However, v5.19.3-139-g2537512 then changed things so that POPSUB also
did a LEAVE. This means that now, die unwinds the context stack and the
save stack in lockstep, so my second fix is now redundant. So this commit
undoes it, saving an rc++/-- and SAVEFREE(cv) per sub call.
Tony Cook [Wed, 3 Feb 2016 04:23:19 +0000 (15:23 +1100)]
[perl #126544] correct the first example in the fcntl documentation
Tony Cook [Wed, 3 Feb 2016 03:52:00 +0000 (14:52 +1100)]
perldelta for
23c4e91245a4
Tony Cook [Wed, 20 Jan 2016 04:35:13 +0000 (15:35 +1100)]
[perl #125540] handle already being at EOF while not finding a heredoc terminator
In some cases, S_scan_heredoc() can already be at end of file and
PL_rsfp is NULL. If we're on the final line and that line has no
newline we'd assert or crash.
Now, if we don't find that newline, we obviously can't find the
terminator, so go straight to reporting the missing terminator.
I considered setting s to PL_bufend, but that would just be more
work to print the same message.
Tony Cook [Wed, 3 Feb 2016 00:35:28 +0000 (11:35 +1100)]
Clarify sprintf() handling of + and space flags
Also with contribution by Chas. Owens.
For: RT #125471
Tony Cook [Tue, 2 Feb 2016 06:04:17 +0000 (17:04 +1100)]
perldelta for
8452c1a03e174
Tony Cook [Tue, 26 Jan 2016 04:53:34 +0000 (15:53 +1100)]
[perl #127351] add isaelem magic on *Foo::ISA = arrayref
Tony Cook [Tue, 26 Jan 2016 04:22:46 +0000 (15:22 +1100)]
[perl #127351] TODO tests for arrayref assigned to *Foo::ISA issues
Lukas Mai [Mon, 1 Feb 2016 22:42:08 +0000 (23:42 +0100)]
op.c: update comment about compiler warnings
Lukas Mai [Mon, 1 Feb 2016 22:11:57 +0000 (23:11 +0100)]
README.android: make the POD a bit nicer
Tony Cook [Mon, 1 Feb 2016 02:22:53 +0000 (13:22 +1100)]
[perl #127426] fixes for 126045 patch, restrict to MSVC, add casts
Tony Cook [Mon, 1 Feb 2016 00:43:50 +0000 (11:43 +1100)]
perldelta for
6f6d1bab334
Tony Cook [Thu, 28 Jan 2016 04:08:01 +0000 (15:08 +1100)]
[perl #126045] part revert
e9b19ab7 for vc2003 and earlier
This avoids an internal compiler error on VC 2003 and earlier
Lukas Mai [Sun, 31 Jan 2016 12:14:29 +0000 (13:14 +0100)]
PerlIO::encoding: explicitly cast char * to STDCHAR *
This should avoid the "pointer targets in assignment differ in
signedness" warning that pops up in some configurations.
Craig A. Berry [Sat, 30 Jan 2016 23:25:05 +0000 (17:25 -0600)]
Tweaks to podlators integration.
It's only perlpodstyle that we can't build the man page for since
it lives in the top-level pod/ directory. Plus there was a new test
that I had missed in the integration.
Lukas Mai [Fri, 29 Jan 2016 23:46:59 +0000 (00:46 +0100)]
ensure isASCII argument is an integer
This catches bugs such as the one fixed in commit
dcf88e34.
Lukas Mai [Sat, 30 Jan 2016 23:40:36 +0000 (00:40 +0100)]
perlop: fix broken example by deleting it [perl #119667]
Lukas Mai [Sat, 30 Jan 2016 23:16:53 +0000 (00:16 +0100)]
util.c: fix/simplify unused arg logic in my_vsnprintf
Lukas Mai [Sat, 30 Jan 2016 23:14:11 +0000 (00:14 +0100)]
mg.c: move declaration of i closer to its use
This should avoid the "unused variable 'i'" warning that pops up in some
configurations.
Craig A. Berry [Sat, 30 Jan 2016 20:37:01 +0000 (14:37 -0600)]
VMS does have the siginfo_si_* fields.
At least they are in the siginfo struct, though oddly, SA_SIGINFO
doesn't exist so they won't do much good. However, adding them
now means that if SA_SIGINFO shows up in the future they will be
tested immediately and not overlooked.
Craig A. Berry [Sat, 30 Jan 2016 20:34:25 +0000 (14:34 -0600)]
Update utils commands in configure.com.
We don't have psed any more but we do have json_pp and perlthanks.
Craig A. Berry [Thu, 28 Jan 2016 19:44:07 +0000 (13:44 -0600)]
Integrate podlators 4.05.
Karl Williamson [Fri, 11 Sep 2015 18:37:27 +0000 (12:37 -0600)]
Escape t/test.pl got vs expected strings
This is so that controls, etc. are visible.
See http://nntp.perl.org/group/perl.perl5.porters/230927
Jarkko Hietaniemi [Fri, 29 Jan 2016 23:33:47 +0000 (18:33 -0500)]
Add STATICs to S_ functions.
Jarkko Hietaniemi [Fri, 29 Jan 2016 23:24:51 +0000 (18:24 -0500)]
Do not export no text symbols starting with S_.
Lukas Mai [Sat, 30 Jan 2016 00:02:03 +0000 (01:02 +0100)]
perlhacktips: fix / properly break example of bad pointer access
Niko Tyni [Thu, 21 Jan 2016 16:17:32 +0000 (18:17 +0200)]
Fix umask for mkstemp(3) calls
With commit v5.21.0-67-g60f7fc1, perl started setting umask to 0600
before calling mkstemp(3), and then restoring it afterwards. This is
wrong as it tells open(2) to strip the owner read and write bits from
the given mode before applying it, rather than the intended negation of
leaving only those bits in place.
On modern systems which call open(2) with mode 0600 in mkstemp(3),
this clears all the created temporary file permissions. However,
any systems that use mode 0666 in mkstemp(3) (like ancient versions
of glibc) now create a file with permissions 0066, leaving world
read and write permission regardless of current umask.
Using umask 0177 instead fixes this.
Bug: https://rt.perl.org/Ticket/Display.html?id=127322
Karl Williamson [Fri, 29 Jan 2016 18:53:10 +0000 (11:53 -0700)]
regexec.c: Macro needs param to be dereferenced
This is a potential bug, but didn't show up, as real addresses are
always going to be larger than 128, and hence the macro here would show
false, and the code only used true to short circuit some other code, so
it always would take the long way.
Karl Williamson [Fri, 29 Jan 2016 17:32:26 +0000 (10:32 -0700)]
utf8.c: Add cast to suppress a warning message
This is showing up in HP-UX, e.g.
http://perl5.test-smoke.org/report/43423
Dagfinn Ilmari Mannsåker [Fri, 29 Jan 2016 10:39:31 +0000 (10:39 +0000)]
Skip SA_SIGINFO uid/pid test on POSIX-deficient OS X versions
Herbert Breunung [Thu, 28 Jan 2016 23:07:23 +0000 (18:07 -0500)]
perlretut: typo correction
Daniel Dragan [Tue, 26 Jan 2016 07:27:49 +0000 (02:27 -0500)]
fix op/infnan.t test fails with NAN conversion on VC 6
fixes
ok 443 - NAN is NaN numerically (by not being NaN)
ok 444 - NAN value stringifies as NaN
ok 445 - nan is NaN numerically (by not being NaN)
not ok 446 - nan value stringifies as NaN
ok 447 - qnan is NaN numerically (by not being NaN)
not ok 448 - qnan value stringifies as NaN
ok 449 - SNAN is NaN numerically (by not being NaN)
not ok 450 - SNAN value stringifies as NaN
ok 451 - NanQ is NaN numerically (by not being NaN)
not ok 452 - NanQ value stringifies as NaN
ok 453 - NANS is NaN numerically (by not being NaN)
not ok 454 - NANS value stringifies as NaN
ok 455 - 1.\#QNAN is NaN numerically (by not being NaN)
not ok 456 - 1.\#QNAN value stringifies as NaN
ok 457 - +1\#SNAN is NaN numerically (by not being NaN)
not ok 458 - +1\#SNAN value stringifies as NaN
ok 459 - -1.\#NAN is NaN numerically (by not being NaN)
not ok 460 - -1.\#NAN value stringifies as NaN
ok 461 - 1\#IND is NaN numerically (by not being NaN)
not ok 462 - 1\#IND value stringifies as NaN
ok 463 - 1.\#IND00 is NaN numerically (by not being NaN)
not ok 464 - 1.\#IND00 value stringifies as NaN
ok 465 - NAN(123) is NaN numerically (by not being NaN)
not ok 466 - NAN(123) value stringifies as NaN
ok 467 - NaN is not lt zero
ok 468 - NaN is not == zero
ok 469 - NaN is not gt zero
ok 470 - NaN is not lt NaN
ok 471 - NaN is not gt NaN
Caused by commit
230ee21f3e from ~5.23.5. Add special casing for VC6.
The NV to IV casts on VC are a function call called __ftol, skip executing
the NV to IV casts if the logic test tests will follow "TARGn" branch
because the NV and IV values are !=.
Steve Hay [Wed, 27 Jan 2016 08:28:33 +0000 (08:28 +0000)]
Upgrade Encode from version 2.79 to 2.80
Karl Williamson [Thu, 28 Jan 2016 02:49:44 +0000 (19:49 -0700)]
ext/POSIX/lib/POSIX.pod: Make verbatim line fit in 79 cols
Karl Williamson [Thu, 28 Jan 2016 02:38:57 +0000 (19:38 -0700)]
utf8.c: Add missing 'STATIC' to declaration
Jarkko Hietaniemi [Tue, 26 Jan 2016 03:17:09 +0000 (22:17 -0500)]
[perl #127183] Non-canonical hexadecimal floats are parsed prematurely
5.22.1 regression from 5.22.0.
Rewriting the hexfp fractional digits parsing to handle the
trickiness of having to ignore both the leading and trailing
zero bits when determining how many bits were actually given.
Daniel Dragan [Tue, 26 Jan 2016 10:24:07 +0000 (05:24 -0500)]
fix a race condition in parallel builds with Visual C
On older VCs a "gmake -j2 ..\generate_uudmap.exe ..\perlglob.exe" will
generate warnings, on newer VCs, a fatal error in 1 or the other cl.exe
process. This is because both cl.exes are trying to lock and write to
vc*0.pdb, the same file. Add PDBOUT option so uudmap and perlglob have
their own pdb files named after themselves and they cant conflict in a
parallel build.
Daniel Dragan [Tue, 26 Jan 2016 05:02:56 +0000 (00:02 -0500)]
fix link failure of APItest.dll on VC 6
alloca is the newer "standardized" name which modern VCs support.
In VC 6, only _alloca exists, which is the prestandardized name, use it to
fix a linker failure.
Tony Cook [Tue, 26 Jan 2016 21:54:15 +0000 (08:54 +1100)]
Revert "[perl #126632] more diagnostics"
This reverts commit
ef18391745841fb1df298cec3a3001be4237fb3d.
This commit was intended only to diagnose Jenkins build issues, I now
have better access to Jenkins (and the new diagnostics didn't tell me
much anyway.)