Father Chrysostomos [Tue, 18 Sep 2012 04:44:29 +0000 (21:44 -0700)]
Handle xhv_super in thread cloning
Father Chrysostomos [Sun, 16 Sep 2012 14:20:45 +0000 (07:20 -0700)]
t/run/mad.t: Avoid %ENV assignment
I see no skip on VMS, so use an %ENV localisation that it supports.
Father Chrysostomos [Sun, 16 Sep 2012 14:13:41 +0000 (07:13 -0700)]
g++ + mad fails t/run/mad.t
For some reason, g++ causes $^X to have a relative path when called
with one, whereas gcc causes it to have an absolute path:
g++:
$ ./perl -le 'print $^X'
./perl
gcc:
$ ./perl -le 'print $^X'
/Users/sprout/Perl/perl.git-copy/perl
(This is on 32-bit darwin.)
This affects mad.t’s ability to find the current perl interpreter
after a chdir.
Father Chrysostomos [Mon, 17 Sep 2012 23:55:36 +0000 (16:55 -0700)]
perldelta for #114924
Father Chrysostomos [Mon, 17 Sep 2012 23:24:40 +0000 (16:24 -0700)]
[perl #114924] Make method calls work with ::SUPER packages
Perl caches SUPER methods inside packages named Foo::SUPER. But this
interferes with actual method calls on those packages (SUPER->foo,
foo::SUPER->foo).
The first time a package is looked up, it is vivified under the name
with which it is looked up. So *SUPER:: will cause that package
to be called SUPER, and *main::SUPER:: will cause it to be named
main::SUPER.
main->SUPER::isa used to be very sensitive to the name of the
main::FOO package (where the cache is kept). If it happened to be
called SUPER, that call would fail.
Fixing that bug (commit
3c104e59d83f) caused the CPAN module named
SUPER to fail, because SUPER->foo was now being treated as a
SUPER::method call. gv_fetchmeth_pvn was using the ::SUPER suffix to
determine where to look for the method. The package passed to it (the
::SUPER package) was being used to look for cached methods, but the
package with ::SUPER stripped off was being used for the rest of
lookup.
3c104e59d83f made main->SUPER::foo work by treating SUPER
as main::SUPER in that case. Mentioning *main::SUPER:: or doing a
main->SUPER::foo call before loading SUPER.pm also caused it to fail,
even before
3c104e59d83f.
Instead of using publicly-visible packages for internal caches, we
should be keeping them internal, to avoid such side effects.
This commit adds a new member to the HvAUX struct, where a hash of GVs
is stored, to cache super methods. I cannot simpy use a hash of CVs,
because I need GvCVGEN. Using a hash of GVs allows the existing
method cache code to be used.
This new hash of GVs is not actually a stash, as it has no HvAUX
struct (i.e., no name, no mro_meta). It doesn’t even need an @ISA
entry as before (which was only used to make isa caches reset), as it
shares its owner stash’s mro_meta generation numbers. In fact, the
GVs inside it have their GvSTASH pointers pointing to the owner stash.
In terms of memory use, it is probably the same as before. Every
stash and every iterated or weakly-referenced hash is now one pointer
larger than before, but every SUPER cache is smaller (no HvAUX, no
*ISA + @ISA + $ISA[0] + magic).
The code is a lot simpler now and uses fewer stash lookups, so it
should be faster.
This will break any XS code that expects the gv_fetchmeth_pvn to treat
the ::SUPER suffix as magical. This behaviour was only barely docu-
mented (the suffix was mentioned, but what it did was not), and is
unused on CPAN.
Father Chrysostomos [Sun, 16 Sep 2012 07:20:23 +0000 (00:20 -0700)]
Revert "Set PL_comppad_name on sub entry"
This reverts commit
d2c8bf052f5a8bb99050f6d2418d77151eb4b468.
Father Chrysostomos [Sun, 16 Sep 2012 07:20:07 +0000 (00:20 -0700)]
pp.c:pp_clonecv: Use find_runcv to find the padname
See: https://rt.perl.org/rt3/Ticket/Display.html?id=113930#txn-1153156
By using find_runcv, we can revert
d2c8bf052f. This may not be the
best tradeoff in the long run, as it makes code using experimental my
subs (my experimental subs?) slower. But at least we avoid slowing
down existing code.
Father Chrysostomos [Sun, 16 Sep 2012 06:48:40 +0000 (23:48 -0700)]
pod/perlsub.pod: Warn about possible lexsub removal
Steve Hay [Mon, 17 Sep 2012 17:03:07 +0000 (18:03 +0100)]
Remove duplicate paragraph from perlref.pod
Spotted by Vincent Belaïche <vincent.b.1@hotmail.fr>
Date: Fri, 14 Sep 2012 20:23:31 +0200
Message-ID: <DUB102-W243A350D79540D31E95E2884900@phx.gbl>
Karl Williamson [Sun, 16 Sep 2012 16:51:01 +0000 (10:51 -0600)]
regexec.c: Avoid unnecessary calculation
When matching an EXACT node and the target string and the pattern differ
in utf8ness, the code prior to this patch calculated each code point from
the utf8 version in order to do the EXACT comparision with the non-utf8
version. But it is unnecessary to do this full calculation. Code
points above Latin1 cannot possibly match a non-UTF8 string; there is no
need to know precisely which code point it is in order to know that it
won't match. Similarly, invariant code points can be checked directly;
and the Latin1 variants can be downgraded for comparison by a simple
macro.
Karl Williamson [Sun, 16 Sep 2012 16:58:26 +0000 (10:58 -0600)]
utf8.h: Add macro to test if UTF8 code point isn't Latin1
Colin Kuskie [Sat, 15 Sep 2012 07:51:28 +0000 (00:51 -0700)]
Refactor t/run/noswitch.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Sat, 15 Sep 2012 07:45:44 +0000 (00:45 -0700)]
Refactor t/run/switchF.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Sat, 15 Sep 2012 07:42:36 +0000 (00:42 -0700)]
Refactor t/run/switchn.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 06:25:58 +0000 (23:25 -0700)]
Refactor t/lib/1_compile.t to use test.pl instead of making TAP by hand.
Vincent Pit [Sun, 16 Sep 2012 14:31:23 +0000 (16:31 +0200)]
Make cx_dump() display the correct gimme description
Contexts are no longer what they used to be back in 1996.
Vincent Pit [Sun, 16 Sep 2012 14:44:13 +0000 (16:44 +0200)]
Fix perl with -DPERL_POISON after commit 22ade07
The third argument to PoisonNew is the type, not the size. Also, poisoning
the contents of the sv itself is incorrect.
Steffen Mueller [Wed, 12 Sep 2012 12:52:46 +0000 (14:52 +0200)]
Save one NULL assignment per TMP
This assignment looks really rather like overzealous cleanliness.
It's a hot path. Now it's death by 999 cuts instead of 1000.
John Peacock [Sun, 16 Sep 2012 11:09:59 +0000 (07:09 -0400)]
Bring bleadperl up to parity with CPAN for version.pm
Please find attached a patch to bleadperl to bring up to date with the
CPAN release of version.pm. This release was to deal primarily with an
edge case in numifying alpha decimal versions:
https://rt.cpan.org/Ticket/Display.html?id=79259
I've also synchronized all of the other version.pm test cases, so that
the code in core is identical to the CPAN release.
Signed-off-by: David Golden <dagolden@cpan.org>
Father Chrysostomos [Sun, 16 Sep 2012 07:12:51 +0000 (00:12 -0700)]
perlδ
This completes the entries for all the patches that I authored plus a
few things by others that I happened to understand.
Father Chrysostomos [Sun, 16 Sep 2012 05:46:03 +0000 (22:46 -0700)]
[Merge] [perl #113930] Lexical subs
Father Chrysostomos [Sun, 16 Sep 2012 05:03:51 +0000 (22:03 -0700)]
Document lexical subs
Father Chrysostomos [Sun, 16 Sep 2012 05:03:35 +0000 (22:03 -0700)]
Disable lexsubs outside of feature.pm
Father Chrysostomos [Sun, 16 Sep 2012 05:02:42 +0000 (22:02 -0700)]
Add experimental lexical_subs feature
Father Chrysostomos [Sun, 16 Sep 2012 05:00:12 +0000 (22:00 -0700)]
feature.pm: Missing space
Father Chrysostomos [Sun, 16 Sep 2012 04:59:45 +0000 (21:59 -0700)]
Increase $feature::VERSION to 1.30
Father Chrysostomos [Sun, 16 Sep 2012 04:56:25 +0000 (21:56 -0700)]
Add experimental warnings categ and :lexical_subs warn ID
I reindented the tree in perllexwarn because I was simply copying and
pasting the output from:
perl regen/warnings.pl tree
Father Chrysostomos [Tue, 11 Sep 2012 06:44:11 +0000 (23:44 -0700)]
perlsub: Document state variables better
Father Chrysostomos [Tue, 11 Sep 2012 05:29:15 +0000 (22:29 -0700)]
Allow lexical sub redefinition inside eval
For non-clonable state subs, this already happened to work.
For any clonable subs, we need to clone the sub as soon as it
is defined.
For redefined state subs, we need to apply the new sub to all recur-
sion levels, as state subs are shared.
Father Chrysostomos [Tue, 11 Sep 2012 04:59:51 +0000 (21:59 -0700)]
Move my sub prototype CVs to the pad names
my subs are cloned on scope entry. To make closures work, a stub
stored in the pad (and closed over elsewhere) is cloned into.
But we need somewhere to store the prototype from which the clone is
made. I was attaching the prototype via magic to the stub in the pad,
since the pad is available at run time, but not the pad names.
That leads to lots of little games all over the place to make sure
the prototype isn’t lost when the pad is swiped on scope exit
(SAVEt_CLEARSV in scope.c). We also run the risk of losing it if an
XS module replaces the sub with another.
Instead, we should be storing it with the pad name. The previous com-
mit made the pad names available at run time, so we can move it there
(still stuffed inside a magic box) and delete much code.
This does mean that newMYSUB cannot rely on the behaviour of non-clon-
able subs that close over variables (or subs) immediately. Previ-
ously, we would dig through outer scopes to find the stub in cases
like this:
sub y {
my sub foo;
sub x {
sub {
sub foo { ... }
}
}
}
We would stop at x, which happens to have y’s stub in its pad, so
that’s no problem.
If we attach it to the pad name, we definitely have to dig past x to
get to the pad name in y’s pad.
Usually, immediate closures do not store the parent pad index, since
it will never be used. But now we do need to use it, so we modify the
code in pad.c:S_pad_findlex to set it always for my/state.
Father Chrysostomos [Mon, 10 Sep 2012 23:07:30 +0000 (16:07 -0700)]
Set PL_comppad_name on sub entry
Father Chrysostomos [Sun, 9 Sep 2012 18:09:53 +0000 (11:09 -0700)]
lexsub.t: Test state sub defined inside eval
Father Chrysostomos [Sun, 9 Sep 2012 02:28:00 +0000 (19:28 -0700)]
Honour lexical prototypes
newCVREF is changed to return a PADCV op, not an RV2CV with a PADCV
kid, to keep the rv2cv_op_cv changes to a minimum. (For some reason,
if newCVREF returns an RV2CV, we end up with two inside each other.)
I also added a test for recursion, since I nearly broke it.
Father Chrysostomos [Fri, 7 Sep 2012 05:57:50 +0000 (22:57 -0700)]
Don’t mention pkg in proto warnings for lex subs
Father Chrysostomos [Fri, 7 Sep 2012 05:11:36 +0000 (22:11 -0700)]
pad.c: Put unavailability warning in one spot
Father Chrysostomos [Fri, 7 Sep 2012 03:32:47 +0000 (20:32 -0700)]
Use the same outside logic for mysubs and formats
By using find_runcv_where both for formats and my subs nested in inner
clonable subs, we can simplify the code.
It happens to make this work ($x is visible):
use 5.01;
sub not_lexical8 {
my sub foo;
foo();
sub not_lexical9 {
my sub bar {
my $x = 'khaki car keys for the khaki car';
not_lexical8();
sub foo { warn $x }
}
bar()
}
}
not_lexical9();
This is definitely iffy code, but if making it work makes the imple-
mentation simpler, so why not?
Father Chrysostomos [Fri, 7 Sep 2012 01:05:35 +0000 (18:05 -0700)]
Fix subroutine unavailability during cloning
sub foo {
my $x;
format =
@
$x||'#'
.
}
write;
__END__
Variable "$x" is not available at - line 9.
That one’s OK.
sub foo {
my sub x {};
format =
@
&x
.
}
write;
__END__
Variable "&x" is not available at - line 9.
Assertion failed: (SvTYPE(_svmagic) >= SVt_PVMG), function S_mg_findext_flags, file mg.c, line 404.
Abort trap
That should say ‘Subroutine’. And it shouldn’t crash.
The my-sub-cloning code was not taking this case into account. The
value in the proto pad is an undef scalar.
Father Chrysostomos [Thu, 6 Sep 2012 23:03:20 +0000 (16:03 -0700)]
‘Subroutine "&x" is not available’ during compilation
sub {
my $x;
sub { eval '$x' }
}->()()
__END__
Variable "$x" is not available at (eval 1) line 2.
That one’s OK (though I wonder about the line number).
sub {
my sub x {};
sub { eval '\&x' }
}->()()
__END__
Variable "&x" is not available at (eval 1) line 1.
That should say ‘Subroutine’.
Father Chrysostomos [Tue, 4 Sep 2012 17:24:57 +0000 (10:24 -0700)]
In cv_clone, use pad ID to identify mysub outside
This code prints ARRAY(0x802e10), whereas it should print
SCALAR(0xfedbee):
undef &bar;
eval 'sub bar { my @x }';
{
my sub foo;
foo();
sub bar {
CORE::state $x;
sub foo { warn \$x }
}
}
The foo sub has a strong CvOUTSIDE pointer, but what it points to
can still be undefined and redefined. So we need to identify it
by its pad.
Father Chrysostomos [Tue, 4 Sep 2012 04:26:37 +0000 (21:26 -0700)]
CvOUTSIDE should be strong for lexsub declared in inner pack sub
PadnameOUTER (SvFAKE) entries in pads of clonable subs contain the
offset in the parent pad where the closed-over entry is to be found.
The pad itself does not reference the outer lexical until the sub is
cloned at run time.
newMYSUB had to account for that by following CvOUTSIDE for
PadnameOUTER entries, to account for cases like this:
my sub foo;
my sub bar { sub foo {} }
The sub foo{} definition would have to find the my sub foo declaration
from outside and store the sub there.
That code was not accounting for named package subs, which close over
variables at compile time, so they don’t need (and don’t) store a par-
ent offset.
So outcv would point to bar in this case:
my sub foo;
sub bar { sub foo {} }
If outcv matched CvOUTSIDE(foo), then CvOUTSIDE was made weak.
That does not help in cases like this:
undef *bar;
{
my sub foo;
sub bar { sub foo {} }
}
If foo has a weak CvOUTSIDE pointer, then it will still point to bar
after bar is freed, which does not help when the sub is cloned and
tries to look at CvROOT(CvOUTSIDE).
If the pad name is marked PadnameOUTER, even if it has no parent pad
index, newMYSUB needs to leave the CvOUTSIDE pointer strongc.
Also, pad_fixup_inner_anons did not account for subs with strong
CvOUTSIDE pointers whose CvOUTSIDE point to the sub whose pad is being
iterated through.
Father Chrysostomos [Wed, 15 Aug 2012 01:10:40 +0000 (18:10 -0700)]
Use the right outside for my subs defined in inner subs
In this example,
{
my sub foo;
sub bar {
sub foo { }
}
}
the foo sub is cloned when the scope containing the ‘my sub’ declara-
tion is entered, but foo’s CvOUTSIDE pointer points to something other
than the active sub. cv_clone assumes that the currently-running sub
is the right sub to close over (at least for subs; formats are another
matter). That was true in the absence of my subs. This commit
changes it to account.
I had to tweak the test, which was wrong, because sub foo was closing
over a stale var.
Father Chrysostomos [Tue, 14 Aug 2012 19:24:43 +0000 (12:24 -0700)]
Fix Peek.t
Father Chrysostomos [Tue, 14 Aug 2012 05:56:05 +0000 (22:56 -0700)]
Preserve outside pointers of my subs with string eval
The CvHASEVAL flag lets cv_clone know that the clone needs to have its
CvOUTSIDE pointer set, for the sake of string evals’ being able to
look up variables.
It was only being set on anonymous subs. It should be set for all
clonable subs. It doesn’t actually hurt to set it on all types of
subs, whether clonable or not, since it has no effect on non-clon-
able subs.
Father Chrysostomos [Mon, 13 Aug 2012 00:57:35 +0000 (17:57 -0700)]
Fix up outside pointers for my subs
I had not yet fixed Perl_pad_fixup_inner_anons to account for the
fact that my sub prototype CVs are stored in magic attached to
the SV slot in the pad, rather than directly in the pad. It also
did not like & entries that close over subs defined in outer
or inner subs (‘my sub foo; sub bar; sub bar { &foo } }’ and
‘sub bar; sub bar { my sub foo; sub { sub foo { } } }’ respectively).
This was resulting in assertion failures, unsurprisingly.
Some of the tests I added, which were causing assertion failures, are
now failing for other reasons, and are marked as to-do.
Father Chrysostomos [Sat, 4 Aug 2012 01:01:06 +0000 (18:01 -0700)]
perly.y: Remove MYSUB
This token is not used any more.
Father Chrysostomos [Fri, 3 Aug 2012 19:41:11 +0000 (12:41 -0700)]
CvNAME_HEK_set
Father Chrysostomos [Fri, 3 Aug 2012 16:23:15 +0000 (09:23 -0700)]
Clone my subs on scope entry
The pad slot for a my sub now holds a stub with a prototype CV
attached to it by proto magic.
The prototype is cloned on scope entry. The stub in the pad is used
when cloning, so any code that references the sub before scope entry
will be able to see that stub become defined, making these behave
similarly:
our $x;
BEGIN { $x = \&foo }
sub foo { }
our $x;
my sub foo { }
BEGIN { $x = \&foo }
Constants are currently not cloned, but that may cause bugs in
pad_push. I’ll have to look into that.
On scope exit, lexical CVs go through leave_scope’s SAVEt_CLEARSV sec-
tion, like lexical variables. If the sub is referenced elsewhere, it
is abandoned, and its proto magic is stolen and attached to a new stub
stored in the pad. If the sub is not referenced elsewhere, it is
undefined via cv_undef.
To clone my subs on scope entry, we create a sequence of introcv and
clonecv ops. See the huge comment in block_end that explains why we
need two separate ops for each CV.
To allow my subs to be defined in inner subs (my sub foo; sub { sub
foo {} }), pad_add_name_pvn and S_pad_findlex now upgrade the entry
for a my sub to a CV to begin with, so that fake entries added to pads
(fake entries are those that reference outer pads) can share the same
CV. Otherwise newMYSUB would have to add the CV to every pad that
closes over the ‘my sub’ declaration. newMYSUB no longer throws away
the initial value replacing it with a new one.
Prototypes are not currently visible to sub calls at compile time,
because the lexer sees the empty stub. A future commit will
solve that.
When I added name heks to CV’s I made mistakes in a few places, by not
turning on the CVf_NAMED flag, or by not clearing the field when free-
ing the hek. Those code paths were not exercised enough by state
subs, so the problems did not show up till now. So this commit fixes
those, too.
One of the tests in lexsub.t, involving foreach loops, was incorrect,
and has been fixed. Another test has been added to the end for a par-
ticular case of state subs closing over my subs that I broke when ini-
tially trying to get sibling my subs to close over each other, before
I had separate introcv and clonecv ops.
Father Chrysostomos [Fri, 3 Aug 2012 16:29:38 +0000 (09:29 -0700)]
cv_clone: panic for no pad
cv_clone has serendipitously gained the ability to clone CVs without
pads. It is not clear that we want to add this ability to this API
function, because we would be stuck supporting it, even if we came up
with a better interface. It used to crash or fail an assertion if
there was no pad.
Father Chrysostomos [Thu, 2 Aug 2012 20:45:31 +0000 (13:45 -0700)]
pad.c: Let S_cv_clone clone stubs
This will be used by cv_clone_into (which does not exist yet) in a
later commit. pp_clonecv will use cv_clone_into.
Teasing out the pad-related and non-pad-related parts of cv_clone
was the easiest way to do this. Now the pad stuff is in a separate
function.
Father Chrysostomos [Mon, 30 Jul 2012 01:47:48 +0000 (18:47 -0700)]
op.c: Remove proto storage optimisation for lex subs
It was already #if 0’d out. This optimisation, copied from package
subs, only makes sense when there is autoloading, which lexical subs
don’t do. Hence, lexical stubs will be rare indeed, so having an
optimisation for those just creates more nooks to hide bugs.
Father Chrysostomos [Fri, 3 Aug 2012 05:11:08 +0000 (22:11 -0700)]
Add clonecv op type
This will be used for cloning a ‘my’ sub on scope entry.
I was going to use pp_padcv for this, but it would end up having a
top-level if/else.
Father Chrysostomos [Fri, 27 Jul 2012 01:21:02 +0000 (18:21 -0700)]
Add introcv op type
This will be used for introducing ‘my’ subs on scope entry, by turning
off the stale flag.
Father Chrysostomos [Thu, 26 Jul 2012 19:38:14 +0000 (12:38 -0700)]
Let state sub fwd decls and nested subs work in anons
I had this working:
state sub foo;
sub other {
sub foo { # defines the state sub declared outside
...
}
}
But it failed inside an anonymous subroutine:
sub {
state sub foo;
sub other {
sub foo { # defines the state sub declared outside
...
}
}
}
When an anonymous (or otherwise clonable) sub is cloned, any state
vars, and, likewise, any state subs, inside it are cloned, too.
In the first example above the state sub forward declaration creates
a subroutine stub. The ‘other’ sub’s ‘sub foo’ declaration creates a
pad entry in other’s pad that closes over the outer foo immediately,
so the same stub is visible in two pads. The sub foo {} declaration
uses that stub.
When the outer sub containing the forward declaration is clonable,
the pad entry is not closed over immediately at compile time, because
the pad entry is just a prototype, not the actual value that will be
shared by the clone and its nested subs. So the inner pad entry does
not contain the sub.
So the actual creation of the sub, if it only looks at the inner
pad (other’s pad), will not see the stub, and will not attach a
body to it.
This was the result:
$ ./miniperl -e 'CORE::state sub foo; CORE::state sub bar { sub foo {warn called} }; foo()'
called at -e line 1.
$ ./miniperl -e 'sub { CORE::state sub foo; CORE::state sub bar { sub foo {warn called} }; foo() }->()'
Undefined subroutine &foo called at -e line 1.
This commit fixes that by having newMYSUB follow the CvOUTSIDE chain
to find the original pad entry where it defines the sub, if the for-
ward declaration is occurs outside and has not been closed over yet.
Father Chrysostomos [Fri, 13 Jul 2012 06:31:52 +0000 (23:31 -0700)]
Add proto magic type
This will be used for storing the prototype CV of a ‘my’ sub. The
clone needs to occupy the pad entry so that padcv ops will be able to
find it. That means the clone has to displace its prototype. In case
the same sub is called recursively, we still need to be able to access
the prototype.
Father Chrysostomos [Wed, 11 Jul 2012 03:18:48 +0000 (20:18 -0700)]
First stab at my sub
This does just enough to get things to compile.
They currently do weird things in edge cases, including ‘Bizarre
copy of CODE’.
‘my sub’ now produces a SUB token, and goes through the same grammar
rule as ‘state sub’ and just plain ‘sub’. The separate MYSUB branch
of the barestmt rule will go soon, as it is now unused.
Father Chrysostomos [Tue, 10 Jul 2012 05:25:24 +0000 (22:25 -0700)]
op.c:newMYSUB: Pop scope after creating sub
I was popping the scope before creating the sub in order to expose the
parent pad, where the new sub is to be stored.
That can cause problems, since ops may still be created that get
attached to the new sub. Those ops will end up using the parent sub’s
slab in that case. If the parent sub does not finish compiling, due
to an error, it may clean out its slab, freeing ops that the inner sub
is using, so the inner sub, when freed, will try to free ops that are
no longer in allocated memory, as the slab is gone. Most of the time,
the inner ops won’t have been reused for anything, so the op type will
still be OP_FREED, and op_free will do nothing (except a single bad
read). But debugging builds detect that and fail an assertion.
Popping the scope afterwards actually does simplify things, surpris-
ingly enough.
I was able to produce this bug with a one-liner, but it did not fail
as part of the test suite. So this fix includes no test.
Since the o variable in newMYSUB is a padop, it can only be freed when
its pad is active. It is created before the sub, so it cannot be
freed until the scope has been popped, so it has to go at the bot-
tom. If an error occurs during newMYSUB, opslab_force_free will take
care of it.
Father Chrysostomos [Tue, 10 Jul 2012 01:02:33 +0000 (18:02 -0700)]
dump.c: Dump CvNAME_HEK
Father Chrysostomos [Mon, 9 Jul 2012 20:00:28 +0000 (13:00 -0700)]
Remove & from redef warnings for lex subs
This is just for consistency with package subs.
Father Chrysostomos [Mon, 9 Jul 2012 19:52:48 +0000 (12:52 -0700)]
lexsub.t: Fix another test
The problem with writing to-do tests is that it is very easy to get
the tests wrong, such that they continue to fail even when the prob-
lems they test for are fixed.
Father Chrysostomos [Mon, 9 Jul 2012 13:29:09 +0000 (06:29 -0700)]
Clone state subs in anon subs
Since state variables are not shared between closures, but only
between invocations of the same closure, state subs should behave
the same way.
This was a little tricky. When we clone a sub, we now clone inner
state subs at the same time. When walking through the pad, cloning
items, we cannot simply clone the inner sub when we see it, because it
may close over things we haven’t cloned yet:
sub {
state sub foo;
my $x
sub foo { $x }
}
We can’t just delay cloning it and do it afterwards, because they may
be multiple subs closing over each other:
sub {
state sub foo;
state sub bar;
sub foo { \&bar }
sub bar { \&foo }
}
So *all* the entries in the new pad must be filled before any inner
subs can be cloned.
So what we do is put a stub in place of the cloned sub. And then
in a second pass clone the inner subs, reusing the stubs from the
first pass.
Father Chrysostomos [Sun, 8 Jul 2012 21:51:10 +0000 (14:51 -0700)]
perldiag: closure referents → closure references
This goes back to
2ba9eb46.
Father Chrysostomos [Sun, 8 Jul 2012 21:42:39 +0000 (14:42 -0700)]
Don’t say ‘variable &foo’ in warnings
It should be ‘subroutine &foo’. (It could be ‘subroutine foo’, but we
use both forms elsewhere, and &foo is the easier to implement, the &
already being contained in the pad name.)
Father Chrysostomos [Sun, 8 Jul 2012 21:28:22 +0000 (14:28 -0700)]
lexsub.t: Fix some tests
I got this working a few commits ago, but the tests mentioned the
wrong sub name.
Father Chrysostomos [Sun, 8 Jul 2012 21:18:43 +0000 (14:18 -0700)]
Make pad_fixup_inner_anons cope with closed-over subs
When a sub starts being parsed, a new CV is created. When it fin-
ishes, it is stored in its final location. If there is a stub there
already, the pad is copied to the stub and the body attached thereto.
Since there may be closures inside the sub whose CvOUTSIDE
pointers point to the temporary CV used during compilation,
pad_fixup_inner_anons is called, to reassign all those
CvOUTSIDE pointers.
This happens in cases like this:
sub f;
sub f { sub { } }
When a sub closes over a lexical item in an outer sub, the inner sub
gets its own pad entry with the same value as the outer pad entry.
This means that, now that we have lexical subs (currently just state
subs), we can end up with a pad entry (&s) holding a sub whose
CvOUTSIDE does not point to the sub (f) that owns the pad:
state sub s { }
sub f { s() }
If the f sub has to reuse a stub, then pad_fixup_inner_anons gets to
see that, and complains bitterly:
$ ./perl -Ilib -E 'state sub s; sub f; sub f { s() }'
Assertion failed: (CvOUTSIDE(innercv) == old_cv), function Perl_pad_fixup_inner_anons, file pad.c, line 2095.
Abort trap
Father Chrysostomos [Sun, 8 Jul 2012 06:46:52 +0000 (23:46 -0700)]
‘Undefined subroutine &foo called’ for lex subs
instead of just ‘Undefined subroutine called’ without the name.
Father Chrysostomos [Sun, 8 Jul 2012 06:11:23 +0000 (23:11 -0700)]
op.c:newMYSUB: inline var used only once
as of the previous commit
Father Chrysostomos [Sun, 8 Jul 2012 06:07:55 +0000 (23:07 -0700)]
Lexical stubs should not AUTOLOAD
There is a feature that allows stubs to fall back to their GVs’
CVs when called. If I reference a stub, e.g., \&bar, and then
bar is autoloaded, the AUTOLOAD sub assigning *bar = *foo or
*bar = sub {...}, I can still call the stub to which I have a refer-
ence, and it will fall back to the overloaded sub.
That is all fine and dandy, but it causes any stub that references a
GV via its CvGV pointer to call that GV’s CV. If we name a lexical
sub by pointing its CvGV pointer at the GV whose name we want it to
have, then the lexical sub, if undefined, will try to fall back to an
autoloaded sub.
That causes things to gang agley in cases like this:
use 5.01;
sub foo { } # package sub
state sub foo;
foo(); # calls lexical sub; falls back to package sub
While we could fix this by flagging the sub and checking for the flag
in pp_entersub (as we do with anonymous subs), it is better simply to
use a HEK, instead of a GV. Since a GV is quite heavyweight for stor-
ing just a name, I was going to do that anyway, eventually. Doing it
now fixes a bug.
Father Chrysostomos [Sun, 8 Jul 2012 00:35:10 +0000 (17:35 -0700)]
Allow CVs to point to HEKs rather than GVs
This will allow named lexical subs to exist independent of GVs.
Father Chrysostomos [Sat, 7 Jul 2012 19:18:49 +0000 (12:18 -0700)]
Implement padcv
State subs can now be referenced and called. Most of the tests in
lexsub.t are now passing. I noticed mistakes in a couple of the
tests and corrected them. In doing so I got an assertion failure
during compilation, so the tests in question I wrapped in a skipped
string eval.
State subs are now mostly working, but there are a few things to
clean up still.
Father Chrysostomos [Fri, 6 Jul 2012 06:28:43 +0000 (23:28 -0700)]
Test state subs
Most of these tests are still to-do. The previous commit got every-
thing compiling at least. Then I went through putting eval{} around
all the dying tests and marking the failing tests as to-do.
At least this way I don’t have to do everything at once (even though
that was how I wrote the tests).
About the only thing that works is constant inlining, of all things.
Father Chrysostomos [Sat, 7 Jul 2012 06:35:15 +0000 (23:35 -0700)]
Look up state subs in the pad
This commit does just enough to get things compiling. The padcv op
is still unimplemented (in fact, converting the padany to a padcv is
still not done), so you can’t actually run the code yet.
Bareword lookup in yylex now produces PRIVATEREF tokens for state
subs, so the grammar has been adjusted to accept a ‘subname’ in sub
calls (PRIVATEREF or WORD) where previously only a WORD was permitted.
Father Chrysostomos [Fri, 6 Jul 2012 21:31:31 +0000 (14:31 -0700)]
op.c:newMYSUB: disable stub optimisation
It will be a lot easier to get things working without this, for now.
It can be reënabled later. It might not be worth it, though, as
AUTOLOADing will ignore lexical subs, and this optimisation is mainly
for AUTOLOAD stubs that are rarely used.
Father Chrysostomos [Fri, 6 Jul 2012 06:22:21 +0000 (23:22 -0700)]
Store state subs in the pad
In making ‘sub foo’ respect previous ‘our sub’ declarations in a
recent commit, I actually made ‘state sub foo’ into a syntax error.
(At the time, I patched up MYSUB in perly.y to keep the tests for ‘"my
sub" not yet implemented’ still working.) Basically, it was creat-
ing an empty pad entry, but returning something that perly.y was not
expecting.
This commit adjusts the grammar to allow the SUB branch of barestmt to
accept a PRIVATEREF for its subname, in addition to a WORD. It reuses
the subname rule that SUB used to use (before our subs were added),
gutting it to remove the special block handling, which SUB now tokes
care of. That means the MYSUB rule will no longer turn on CvSPECIAL
on the PL_compcv that is going to be thrown away anyway.
The code for special blocks (BEGIN, END, etc.) that turns on CvSPECIAL
now checks for state subs and skips those. It only applies to our
subs and package subs.
newMYSUB has now actually been written. It basically duplicates
newATTRSUB, except for GV-specific things. It does currently vivify a
GV and set CvGV, but I am hoping to change that later. I also hope to
merge some of the code later, too.
I changed the prototype of newMYSUB to make it easier to use. It is
not used anywhere on CPAN and has always simply died, so that should
be all right.
Father Chrysostomos [Thu, 5 Jul 2012 17:41:05 +0000 (10:41 -0700)]
lexsub.t: Add test name, test override from another pkg
The bareword logic in toke.c looks up GVs in various places. This
tests that we are bypassing those correctly.
Father Chrysostomos [Thu, 5 Jul 2012 06:18:32 +0000 (23:18 -0700)]
Let barewords look up our subs
These take precedence over built-in keywords (just as my $AUTOLOAD
shadows the package var), but not the keyword plugin, as the latter
takes precedence over labels, and these don’t.
Father Chrysostomos [Wed, 4 Jul 2012 21:09:46 +0000 (14:09 -0700)]
toke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
There is no need to allocate a separate ‘tmpbuf’ and then copy it into
PL_tokenbuf afterwards.
Father Chrysostomos [Wed, 4 Jul 2012 16:13:17 +0000 (09:13 -0700)]
Make ‘sub foo{}’ respect ‘our foo’
This commit switches all sub definitions, whether with ‘our’ or not,
to using S_force_ident_maybe_lex (formerly known as S_pending_ident).
This means that an unqualified (no our/my/state or package prefix)
‘sub foo’ declaration does a pad lookup, just like $foo.
It turns out that the vivification that I added to the then
S_pending_ident for CVs was unnecessary and actually buggy. We
*don’t* want to autovivify GVs for CVs, because they might be con-
stants or forward declarations, which are stored in a simpler form.
I also had to change the subname rule used by MYSUB in perly.y, since
it can now be fed a PRIVATEREF, which it does not expect. This may
prove to be temporary, but it keeps current tests passing.
Father Chrysostomos [Wed, 4 Jul 2012 07:17:55 +0000 (00:17 -0700)]
Fix our sub with proto
yylex must emit exactly one token each time it is called. Some-
times yylex needs to parse several tokens at once. That’s what
the various force functions are for. But that is also what
PL_pending_ident is for.
The various force_next, force_word, force_ident, etc., functions keep
a stack of tokens (PL_nextval/PL_nexttype) that yylex will check imme-
diately when called.
PL_pending_ident is used to track a single identifier that yylex will
hand off to S_pending_ident to handle.
S_pending_ident is the only piece of code for resolving an identi-
fier that could be lexical but could also be a package variable.
force_ident assumes it is looking for a package variable.
force_* takes precedence over PL_pending_ident.
All this means that, if an identifier needs to be looked up in the pad
on the next yylex invocation, it has to use PL_pending_ident, and the
force_* functions cannot be used at the same time.
Not realising that, when I made ‘our sub foo’ store the sub in the
pad I also made ‘our sub foo ($)’ into a syntax error, because it
was being parsed as ‘our sub ($) foo’ (the prototype being ‘forced’);
i.e., the pending tokens were being pulled out of the ‘queue’ in the
wrong order. (I put queue in quotes, because one queue and one unre-
lated buffer together don’t exactly count as ‘a queue’.)
Changing PL_pending_ident to have precedence over the force stack
breaks ext/XS-APItest/t/swaptwostmts.t, because the statement-parsing
interface does not localise PL_pending_ident. It could be changed to
do that, but I don’t think it is the right solution.
Having two separate pending token mechanisms makes things need-
lessly fragile.
This commit eliminates the PL_pending_ident mechanism and
modifies S_pending_ident (renaming it in the process to
S_force_ident_maybe_lex) to work with the force mechanism. I was
going to merge it with force_ident, but the two make incompatible
assumptions that just complicate the code if merged. S_pending_ident
needs the sigil in the same string buffer, to pass to the pad inter-
face. force_ident needs to be able to work without a sigil present.
So now we only have one queue for pending tokens and the order is more
predictable.
Father Chrysostomos [Tue, 3 Jul 2012 04:26:13 +0000 (21:26 -0700)]
Make do sub() respect our declarations
Father Chrysostomos [Mon, 2 Jul 2012 19:29:48 +0000 (12:29 -0700)]
lexsub.t: Fix a test
This is not testing what I meant it to test: that ‘sub d’ will respect
a preceding ‘our sub d;’. If ‘sub d’ is in the same package, it makes
no difference, so the test tests nothing.
It turns out this does not work yet.
Father Chrysostomos [Mon, 2 Jul 2012 16:07:31 +0000 (09:07 -0700)]
Use test.pl in lexsub.t
I thought cmd/ couldn’t use test.pl, but was mistaken.
Father Chrysostomos [Mon, 2 Jul 2012 05:53:41 +0000 (22:53 -0700)]
Make &foo respect our sub
This changes &foo to go through S_pending_ident (by setting
PL_pending_ident, which causes yylex to defer to S_pending_ident for
the next token) the way $foo and %foo do.
This necessitated reducing the maximum identifier length of &foo from
252 to 251, making it match @foo, $foo, etc. So somebody’s JAPH might
break. :-)
Father Chrysostomos [Sun, 1 Jul 2012 06:20:25 +0000 (23:20 -0700)]
Allocate ‘our sub’ in the pad
Currently the name is only allocated there. Nothing fetches it yet.
Notes on the implementation:
S_pending_ident contains the logic for determining whether $foo or
@foo refers to a lexical or package variable.
yylex defers to S_pending_ident if PL_pending_ident is set.
The KEY_sub case in yylex is changed to set PL_pending_ident instead
of using force_word. For package variables (including our),
S_pending_ident returns a WORD token, which is the same thing that
force_word produces. So *that* aspect of this change does not affect
the grammar. However....
The barestmt rule’s SUB branch begins with ‘SUB startsub subname’.
startsub is a null rule that creates a new sub in PL_compcv via
start_subparse(). subname is defined in terms of WORD and also checks
whether this is a special block, turning on CvSPECIAL(PL_compcv) if
it is. That flag has to be visible during compilation of the sub.
But for a lexical name, such as ‘our foo’, to be allocated in the
right pad, it has to come *before* startsub, i.e., ‘SUB subname
startsub’.
But subname needs to modify the sub that startsub created, set-
ting the flag.
So I copied (not moved, because MYSUB still uses it) the name-checking
code from the subname rule into the SUB branch of barestmt. Now that
uses WORD directly instead of invoking subname. That allows the code
there to set everything up in the right order.
Father Chrysostomos [Sun, 1 Jul 2012 06:00:11 +0000 (23:00 -0700)]
Add padcv to Opcode.pm
Father Chrysostomos [Sun, 1 Jul 2012 05:29:28 +0000 (22:29 -0700)]
padcv op type
Father Chrysostomos [Sun, 1 Jul 2012 00:31:32 +0000 (17:31 -0700)]
Don’t allow name after our/state sub
It was a mistake that this was ever allowed.
Karl Williamson [Sat, 15 Sep 2012 18:27:22 +0000 (12:27 -0600)]
PATCH: [perl #82954] Make "Can't do {n,m} with n > m into warning
This commit now causes this situation to warn instead of dying. The
portion of the regular expression that can't match is optimized into an
OPFAIL.
Chris 'BinGOs' Williams [Sat, 15 Sep 2012 11:45:06 +0000 (12:45 +0100)]
Update Sys-Syslog to CPAN version 0.32
[DELTA]
0.32 -- 2012.09.14 -- Sebastien Aperghis-Tramoni (SAPER)
[BUGFIX] CPAN-RT#69040: Don't modify @_ in syslog().
[BUGFIX] Restore compatibility with Perl 5.6.0.
[DOC] Perl-RT#81858: Fix some spelling errors (Peter J. Acklam).
Father Chrysostomos [Sat, 15 Sep 2012 05:55:56 +0000 (22:55 -0700)]
Fix build under C++
Commit
9ac6f7d90 was missing a few casts.
Father Chrysostomos [Sat, 15 Sep 2012 05:08:19 +0000 (22:08 -0700)]
[perl #114888] Localise PL_comppad_name in cv_clone
In 9ef8d56 I made closures share their pad name lists, and not just
the names themselves, for speed (no need to SvREFCNT_inc each name and
copy the list).
To make that work, I had to set PL_comppad_name in cv_clone, before
the pad_new call. But I failed to move the PL_comppad_name localisa-
tion from pad_new to cv_clone.
So cv_clone would merrily clobber the previous value of
PL_comppad_name *before* localising it.
This only manifested itself in source filters. Most of the time,
pp_anoncode is called at run time when either no code is being com-
piled (PL_comppad_name is only used at compile time) or inside a
BEGIN block which itself localises PL_comppad_name. But inside a
Filter::Util::Call source filter there was no buffer like that to
protect it.
This meant that pad name creation (my $x) would create the name in the
PL_comppad_name belonging to the last-cloned sub. A subsequent name
lookup ($x) would look in the correct place, as it uses the moral
equivalent of PadlistNAMES(CvPADLIST(PL_compcv)), not PL_comppad_name.
So it would not find it, resulting in a global variable or a stricture
violation.
Father Chrysostomos [Fri, 14 Sep 2012 21:20:07 +0000 (14:20 -0700)]
Make SUPER::method respect method changes in moved pkg
->SUPER::method calls inside the Foo package cache the method for
reuse inside the stash Foo::SUPER.
Before the call, @Foo::SUPER::ISA is set to "Foo", so that those
caches will be invalidated properly. (@ISA has the magic to make that
work.) The actual value in @Foo::SUPER::ISA unused.
Now we have two types of package names. If you alias the Foo package
and then clobber the original entry:
*Bar:: = *Foo::;
undef *Foo::;
__PACKAGE__ and HvNAME will return Foo still, but HvENAME (the effec-
tive name) will return Bar, because that is where the package is to be
found.
As of the previous commit, the package used for ISA is based on the
effective name, Bar::SUPER in this case.
But @Bar::SUPER::ISA is still set to Foo. So even if we make changes
to methods inherited by what is now the Bar package, a previous method
cached in *Bar::SUPER::method will be reused.
BEGIN {
*Bar:: = *Foo::;
undef *Foo::;
}
package Bar;
@ISA = 'Baz';
*Baz::m = sub { "method 1" };
anthying->SUPER::m;
undef *Baz::m;
*Baz::m = sub { "method 2" };
warn anything->SUPER::m;
__END__
method 1 at - line 11.
Father Chrysostomos [Fri, 14 Sep 2012 20:35:53 +0000 (13:35 -0700)]
Make SUPER::method calls work in moved stashes
BEGIN {
*foo:: = *bar::;
*bar:: = *baz;
}
package foo;
@ISA = 'door';
sub door::dohtem { 'dohtem' }
warn bar->SUPER::dohtem;
__END__
Can't locate object method "dohtem" via package "bar::SUPER" at - line 8.
When gv_fetchmethod_pvn_flags looks up a package it changes SUPER to
__PACKAGE__ . "::SUPER" first. Then gv_fetchmeth_pvn uses HvNAME on
the package and strips off the ::SUPER suffix if any, before doing
isa lookup.
The problem with using __PACKAGE__ (actually HvNAME) is that it might
not be possible to find the current stash under that name. HvENAME
should be used instead.
The above example happens to work if @ISA is changed to ‘our @ISA’,
but that is because of an @ISA bug.
Father Chrysostomos [Fri, 14 Sep 2012 20:13:30 +0000 (13:13 -0700)]
Make SUPER:: in main less sensitive
$ perl -e '$main::SUPER::; sub bar::bar{} @ISA = bar; main->SUPER::bar'
$ perl -e '$SUPER::; sub bar::bar{} @ISA = bar; main->SUPER::bar'
Can't locate object method "bar" via package "main" at -e line 1.
(That’s 5.10.1. More recent perls say package "SUPER".)
The only differnce that $SUPER:: variable makes is the name of
the SUPER:: package. It ends up being called SUPER instead of
main::SUPER.
This causes problems because gv_fetchmeth_pvn, seeing a package end-
ing in ::SUPER, strips off the ::SUPER before doing isa lookup.
But SUPER does not end in ::SUPER, so this commit adjusts
gv_fetchmeth_pvn to account.
Father Chrysostomos [Fri, 14 Sep 2012 19:32:28 +0000 (12:32 -0700)]
method.t: Add basic tests for SUPER
Father Chrysostomos [Fri, 14 Sep 2012 17:19:58 +0000 (10:19 -0700)]
method.t: Test more method-BLOCK edge cases
Father Chrysostomos [Fri, 14 Sep 2012 17:12:33 +0000 (10:12 -0700)]
cop.h: Remove obsolete comment
623e6609 (2 Apr 2006) added this to cop.h:
+/* FIXME NATIVE_HINTS if this is changed from op_private (see perl.h) */
+#define CopHINTS_get(c) ((c)->op_private + 0)
+#define CopHINTS_set(c, h) STMT_START { \
+ (c)->op_private \
+ = (U8)((h) & HINT_PRIVATE_MASK); \
+ } STMT_END
+
d5ec2987 (20 May 2006) made this change, ignoring the FIXME:
/* FIXME NATIVE_HINTS if this is changed from op_private (see perl.h) */
-#define CopHINTS_get(c) ((c)->op_private + 0)
+#define CopHINTS_get(c) ((c)->cop_hints + 0)
#define CopHINTS_set(c, h) STMT_START { \
- (c)->op_private \
- = (U8)((h) & HINT_PRIVATE_MASK); \
+ (c)->cop_hints = (h); \
} STMT_END
There is nothing to be fixed here, as vmsish.h uses ->op_private
directly, instead of using the CopHINTS macros. Even having caller
return cop_hints instead of op_private doesn’t hurt, as newly-created
cops copy the vms hints from PL_hints to op_private. So assigning
(caller $n)[8] to $^H will still work.
Father Chrysostomos [Fri, 14 Sep 2012 13:28:21 +0000 (06:28 -0700)]
pp_ctl.c:caller: Remove obsolete comment
This was added in
f3aa04c29a, but stopped being relevant in
d5ec2987912.
Father Chrysostomos [Fri, 14 Sep 2012 13:20:34 +0000 (06:20 -0700)]
Prevent assertion failure with ‘no a a 3’
This particular syntax error, whittled down from ‘no if $] >= 5.17.4
warnings => "deprecated"’ (which contains a type), causes the parser
to try to free an op from the new sub (for the BEGIN block) after
freeing the new sub.
This happens on line 526 of perly.c. It should not be necessary for
the parser to free the op at this point, since after an error any ops
owned by incomplete subs’ slabs will be freed.
I’m leaving the other three instances of op_free in perly.c in place,
at least for now, since there are cases where the forced token stack
prevents ops from being freed when their subs are.
Father Chrysostomos [Fri, 14 Sep 2012 07:16:35 +0000 (00:16 -0700)]
Increase $warnings::VERSION to 1.14
Father Chrysostomos [Fri, 14 Sep 2012 06:46:46 +0000 (23:46 -0700)]
Stop lexical warnings from turning off deprecations
Some warnings, such as deprecation warnings, are on by default:
$ perl5.16.0 -e '$*'
$* is no longer supported at -e line 1.
But turning *on* other warnings will turn them off:
$ perl5.16.0 -e 'use warnings "void"; $*'
Useless use of a variable in void context at -e line 1.
Either all warnings in any given scope are controlled by lexical
hints, or none of them are.
When a single warnings category is turned on or off, if the warn-
ings were controlled by $^W, then all warnings are first turned on
lexically if $^W is 1 and all warnings are turned off lexically
if $^W is 0.
That has the unfortunate affect of turning off warnings when it was
only requested that warnings be turned on.
These categories contain default warnings:
ambiguous
debugging
deprecated
inplace
internal
io
malloc
utf8
redefine
syntax
glob
inplace
overflow
precedence
prototype
threads
misc
Most also contain regular warnings, but these contain *only*
default warnings:
debugging
deprecated
glob
inplace
malloc
So we can treat $^W==0 as equivalent to qw(debugging deprecated glob
inplace malloc) when enabling lexical warnings.
While this means that some default warnings will still be turned off
by ‘use warnings "void"’, it won’t be as many as before. So at least
this is a step in the right direction.
(The real solution, of course, is to allow each warning to be turned
off or on on its own.)