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.)
Father Chrysostomos [Fri, 14 Sep 2012 06:33:03 +0000 (23:33 -0700)]
Make (caller $n)[9] respect std warnings
In commit
7e4f04509c6 I forgot about caller. This commit makes the
value returned by (caller $n)[9] assignable to ${^WARNING_BITS} to
produce exactly the same warnings settings, including warnings con-
trolled by $^W.
Father Chrysostomos [Fri, 14 Sep 2012 04:23:34 +0000 (21:23 -0700)]
perldiag: 13 years for reserved word deprec. is enough
Use of ‘our’ (which was not a keyword yet) was deprecated in 1997 in
commit
85b81015bd, so that it could be used as a keyword later.
‘our’ variables were introduced in 1999 in commit
77ca0c92d2c, remov-
ing the deprecation warning.
The notice in perldiag survived, ...till now.
Father Chrysostomos [Fri, 14 Sep 2012 01:01:44 +0000 (18:01 -0700)]
perldiag: ‘Attempt to free unreffed scalar’ is S
Father Chrysostomos [Fri, 14 Sep 2012 00:50:15 +0000 (17:50 -0700)]
perlhacktips.pod: readonly ops update (again)
Father Chrysostomos [Thu, 13 Sep 2012 21:08:46 +0000 (14:08 -0700)]
sv.c: %vd printf format microöptimisation
The %vd printf format does not need to make two copies of a version
object’s stringification or stringify the object twice.
Father Chrysostomos [Thu, 13 Sep 2012 20:00:12 +0000 (13:00 -0700)]
Fix %vd with alpha version
There are five problems with it:
First, this warning is not suppressible, even with -X:
$ perl -Xe' sprintf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.
To keep the behaviour as close as possible to what it was already
without the incorrect behaviour, I have made it a default warning.
Secondly, putting it in the internal category does not make sense.
internal is a subset of severe, and contains warnings that indicate
internal inconsistencies, like ‘Scalars leaked’ and ‘Unbalanced string
table refcount’. It should be in the printf warnings category.
Thirdly, if we turn warnings on explicitly, we see this:
$ perl -we '() = sprintf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.
Invalid conversion in printf: "%v" at -e line 1.
%vd is not invalid. That warning is bogus.
Fourthly, %vd itself gets output when fed an alpha version:
$ perl -Xe 'printf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.
[%vd]
If an argument is missing or invalid or what have you, the %-format
itself should not be output. An empty string makes the most sense.
Fifthly, it leaks memory. Run this and watch memory usage go up:
$ perl -e '
warn $$; $SIG{__WARN__} = sub {}; $v = new version v1.1_1;
sprintf "%vd", $v while 1
'
It does savesvpv before shortcircuiting for alphas. But the corres-
ponding Safefree comes after the shortcircuiting, which skips it.
Father Chrysostomos [Thu, 13 Sep 2012 15:35:39 +0000 (08:35 -0700)]
perldiag: ‘Unbalanced string table’ is a default warning
Father Chrysostomos [Thu, 13 Sep 2012 15:33:41 +0000 (08:33 -0700)]
perldiag: ‘Scalars leaked’ is a default warning
Craig A. Berry [Sat, 15 Sep 2012 00:43:05 +0000 (19:43 -0500)]
Add another include directory for the x2p files on VMS.
Because we now have:
#include "../unicode_constants.h"
which is a Unix-style path and cannot be combined with [.x2p] and
get a valid result.
David Mitchell [Fri, 14 Sep 2012 07:53:26 +0000 (08:53 +0100)]
[MERGE] eliminate PL_reginput
The variable PL_reginput (which is actually part of the
global/per-interpreter variable PL_reg_state), is mainly used just
locally within the S_regmatch() function. In this role, it effectively
competes with the local-to-regmatch() variable locinput, as a pointer
that tracks the current match position.
Having two variables that do this is less efficient,and makes the code
harder to understand. So this series of commits:
1) removes PL_reginput, and replaces it with a var, reginput, local to
regmatch();
2) successively removes more and uses of the reginput variable, until
3) it is eliminated altogether, leaving locinput as the sole 'here we are'
pointer.
Looking at the CPU usage of running the t/re/*.t tests on a -O2,
non-threaded build, running each test suite 3 times, gives:
before: 55.35 55.66 55.69
after: 55.10 55.13 55.33
which indicates a small performance improvement of around 0.5%.
(The CPU usage of a single run of the whole perl test suite dropped from
783.31s to 777.23s).
David Mitchell [Thu, 13 Sep 2012 21:41:02 +0000 (22:41 +0100)]
regmatch(): eliminate reginput variable
The remaining uses of reginput are all assignments; its value is
never used. So eliminate it.
Also, update the description of S_regrepeat(), which was woefully out of
date (but mentioned reginput).
David Mitchell [Thu, 13 Sep 2012 19:28:01 +0000 (20:28 +0100)]
regmatch(): remove remaining reads of reginput
In the remaining place where the value of reginput is used, its value
should always be equal to locinput, so it can be eliminated there.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Thu, 13 Sep 2012 18:58:25 +0000 (19:58 +0100)]
regmatch(): remove reginput from CURLY etc
reginput mostly tracked locinput, except when regrepeat() was called.
With a bit of jiggling, it could be eliminated for these blocks of code.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Thu, 13 Sep 2012 10:38:26 +0000 (11:38 +0100)]
regmatch(): remove reginput from CURLYM
reginput, locinput and st->locinput were being used in a little
ballet to determine the length of the first match.
This is now simply locinput - st->locinput, or its unicode equivalent;
so the code can be simplified.
Elsewhere in the block: where reginput was being used, locinput and/or
nextchr already contain the same info, so use them instead.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Thu, 13 Sep 2012 10:12:40 +0000 (11:12 +0100)]
regmatch(): remove reginput from IFMATCH etc
It was being used essentially as a temporary var within the branch,
so replace it with a temp var in a new block scope.
On return in IFMATCH_A / IFMATCH_A_fail, there's no need to set reginput
any more, so don't. The SUSPEND case used to set locinput = reginput, but
at that point, the two variables already always had the same value anyway.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Thu, 13 Sep 2012 09:28:11 +0000 (10:28 +0100)]
regmatch(): remove reginput from TRIE_next_fail:
It was being used essentially as a temporary var within the branch,
so replace it with a temp var in a new block scope.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Thu, 13 Sep 2012 08:22:38 +0000 (09:22 +0100)]
regmatch(): make PUSH_STATE_GOTO dest explicit
Currently, the string position from where matching continues after a PUSH
is implicitly specified by the value of reginput, which is usually just
equal to locinput. Make this explicit by adding an extra argument to
PUSH_STATE_GOTO() etc.
This is part of a campaign to eliminate the reginput variable.
David Mitchell [Wed, 12 Sep 2012 19:10:44 +0000 (20:10 +0100)]
eliminate PL_reginput
PL_reginput (which is actually #defined to PL_reg_state.re_state_reginput)
is, to all intents and purposes, state that is only used within
S_regmatch().
The only other places it is referenced are in S_regtry() and S_regrepeat(),
where it is used to pass the current match position back and forth between
the subs.
Do this passing instead via function args, and bingo! PL_reginput is now
just a local var of S_regmatch().
Nicholas Clark [Thu, 13 Sep 2012 20:22:29 +0000 (22:22 +0200)]
Fix compilation for -DPERL_POISON and -DPERL_OLD_COPY_ON_WRITE together.
These have been present since PERL_POISON was added in June 2005 by commit
94010e71b67db040. It seems that no-one has tried compiling with both defined
together.
Nicholas Clark [Thu, 13 Sep 2012 16:13:43 +0000 (18:13 +0200)]
Fix buggy -DPERL_POISON code in S_rxres_free(), exposed by a recent test.
The code had been buggily attempting to overwrite just-freed memory since
PERL_POISON was added by commit
94010e71b67db040 in June 2005. However, no
regression test exercised this code path until recently.
Also fix the offset in the array of UVs used by PERL_OLD_COPY_ON_WRITE to
store RX_SAVED_COPY(). It now uses p[2]. Previously it had used p[1],
directly conflicting with the use of p[1] to store RX_NPARENS().
The code is too intertwined to meaningfully do these as separate commits.
Nicholas Clark [Thu, 13 Sep 2012 15:05:58 +0000 (17:05 +0200)]
Restore the build under -DPERL_OLD_COPY_ON_WRITE
This was broken as a side effect of commit
6502e08109cd003b, recently merged
to blead.
Colin Kuskie [Fri, 14 Sep 2012 02:25:24 +0000 (19:25 -0700)]
Refactor t/op/push.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 02:06:02 +0000 (19:06 -0700)]
Refactor t/run/switch0.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 01:54:13 +0000 (18:54 -0700)]
Refactor t/op/overload_integer.t to use test.pl instead of making TAP by hand.
With minor change from committer: Always assign $@ asap after an eval.
Colin Kuskie [Fri, 14 Sep 2012 01:42:37 +0000 (18:42 -0700)]
Refactor t/op/exists_sub.t to use test.pl instead of making TAP by hand.
Karl Williamson [Fri, 14 Sep 2012 03:14:54 +0000 (21:14 -0600)]
Merge branch for mostly regen/regcharclass.pl into blead
I started this work planning to enhance regen/regcharclass.pl to accept
Unicode properties as input so that some small properties used in \X
could be compiled in, instead of having to be read from disk. In doing
so, I saw some opportunities to move some EBCDIC dependencies down to a
more basic level, thus replacing quite a few existing ones with just a
couple at the lower levels. This also led to my enhancing the macros
output by regcharclass.pl to be at least as good (in terms of numbers of
branches, etc) as the hand-coded ones it replaces.
I also spotted a few bugs in existing code that hadn't been triggered
yet.
Karl Williamson [Thu, 6 Sep 2012 02:56:09 +0000 (20:56 -0600)]
utf8.h: Use machine generated IS_UTF8_CHAR()
This takes the output of regen/regcharclass.pl for all the 1-4 byte
UTF8-representations of Unicode code points, and replaces the current
hand-rolled definition there. It does this only for ASCII platforms,
leaving EBCDIC to be machine generated when run on such a platform.
I would rather have both versions to be regenerated each time it is
needed to save an EBCDIC dependency, but it takes more than 10 minutes
on my computer to process the 2 billion code points that have to be
checked for on ASCII platforms, and currently t/porting/regen.t runs
this program every times; and that slow down would be unacceptable. If
this is ever run under EBCDIC, the macro should be machine computed
(very slowly). So, even though there is an EBCDIC dependency, it has
essentially been solved.
Karl Williamson [Thu, 6 Sep 2012 02:48:15 +0000 (20:48 -0600)]
regen/regcharclass.pl: Add ability to restrict platforms
This adds the capability to skip definitions if they are for other than
a desired platform.
Karl Williamson [Thu, 6 Sep 2012 02:32:29 +0000 (20:32 -0600)]
utf8.h: Remove some EBCDIC dependencies
regen/regcharclass.pl has been enhanced in previous commits so that it
generates as good code as these hand-defined macro definitions for
various UTF-8 constructs. And, it should be able to generate EBCDIC
ones as well. By using its definitions, we can remove the EBCDIC
dependencies for them. It is quite possible that the EBCDIC versions
were wrong, since they have never been tested. Even if
regcharclass.pl has bugs under EBCDIC, it is easier to find and fix
those in one place, than all the sundry definitions.
Karl Williamson [Wed, 5 Sep 2012 21:18:09 +0000 (15:18 -0600)]
regen/regcharclass.pl: Add optimization
On UTF-8 input known to be valid, continuation bytes must be in the
range 0x80 .. 0x9F. Therefore, any tests for being within those bounds
will always be true, and may be omitted.
Karl Williamson [Wed, 5 Sep 2012 21:14:59 +0000 (15:14 -0600)]
regen/regcharclass.pl: White-space only
Indent a newly-formed block
Karl Williamson [Wed, 5 Sep 2012 21:00:52 +0000 (15:00 -0600)]
regen/regcharclass.pl: Extend previously added optimization
A previous commit added an optimization to save a branch in the
generated code at the expense of an extra mask when the input class has
certain characteristics. This extends that to the case where
sub-portions of the class have similar characteristics. The first
optimization for the entire class is moved to right before the new loop
that checks each range in it.
Karl Williamson [Wed, 5 Sep 2012 15:30:34 +0000 (09:30 -0600)]
regen/regcharclass.pl: Rmv always true components from gen'd macro
This adds a test and returns 1 from a subroutine if the condition will
always match; and in the caller it adds a check for that, and omits the
condition from the generated macro.
Karl Williamson [Tue, 4 Sep 2012 20:54:26 +0000 (14:54 -0600)]
regen/regcharclass.pl: Add an optimization
Branches can be eliminated from the macros that are generated here
by using a mask in cases where applicable. This adds checking to see if
this optimization is possible, and applies it if so.
Karl Williamson [Wed, 5 Sep 2012 16:26:22 +0000 (10:26 -0600)]
regen/regcharclass.pl: Rename a variable
I find it confusing that the array element name is the same as the full array
Karl Williamson [Tue, 4 Sep 2012 20:12:13 +0000 (14:12 -0600)]
regen/regcharclass.pl: Pass options deeper into call stack
This is to prepare for future commits which will act differently at the
deep level depending on some of the options.
Karl Williamson [Mon, 3 Sep 2012 22:59:09 +0000 (16:59 -0600)]
Use macro not swash for utf8 quotemeta
The rules for matching whether an above-Latin1 code point are now saved
in a macro generated from a trie by regen/regcharclass.pl, and these are
now used by pp.c to test these cases. This allows removal of a wrapper
subroutine, and also there is no need for dynamic loading at run-time
into a swash.
This macro is about as big as I'm comfortable compiling in, but it
saves the building of a hash that can grow over time, and removes a
subroutine and interpreter variables. Indeed, performance benchmarks
show that it is about the same speed as a hash, but it does not require
having to load the rules in from disk the first time it is used.
Karl Williamson [Mon, 3 Sep 2012 22:54:56 +0000 (16:54 -0600)]
regen/regcharclass.pl: Add new output macro type
The new type 'high' is used on only above-Latin1 code points. It is
designed for code that already knows the tested code point is not
Latin1, and avoids unnecessary tests.
Karl Williamson [Mon, 3 Sep 2012 00:29:42 +0000 (18:29 -0600)]
regen/regcharclass.pl: Add documentation
Karl Williamson [Mon, 3 Sep 2012 00:28:19 +0000 (18:28 -0600)]
regen/regcharclass.pl: Error check input better
This makes sure that the modifiers specified in the input are known to
the program.
Karl Williamson [Sun, 2 Sep 2012 22:48:14 +0000 (16:48 -0600)]
regen/regcharclass.pl: Allow comments in input
Lines whose first non-blank character is a '#' are now considered to be
comments, and ignored. This allows the moving of some lines that have
been commented out back to after the __DATA__ where they really belong.
Karl Williamson [Sun, 2 Sep 2012 21:58:41 +0000 (15:58 -0600)]
regen/unicode_constants.pl: Add name parameter
A future commit will want to use the first surrogate code point's UTF-8
value. Add this to the generated macros, and give it a name, since
there is no official one. The program has to be modified to cope with
this.
Karl Williamson [Sun, 2 Sep 2012 21:29:32 +0000 (15:29 -0600)]
Move 2 functions from utf8.c to regexec.c
One of these functions is currently commented out. The other is called
only in regexec.c in one place, and was recently revised to no longer
require the static function in utf8.c that it formerly called. They can
be made static inline.
Karl Williamson [Sun, 2 Sep 2012 20:46:38 +0000 (14:46 -0600)]
regexec.c: Use new macros instead of swashes
A previous commit has caused macros to be generated that will match
Unicode code points of interest to the \X algorithm. This patch uses
them. This speeds up modern Korean processing by 15%.
Together with recent previous commits, the throughput of modern Korean
under \X has more than doubled, and is now comparable to other
languages (which have increased themselved by 35%)
Karl Williamson [Sun, 2 Sep 2012 20:31:59 +0000 (14:31 -0600)]
regen/regcharclass.pl: Generate macros for \X processing
\X is implemented in regexec.c as a complicated series of property
look-ups. It turns out that many of those are for just a few code
points, and so can be more efficiently implemented with a macro than a
swash. This generates those.
Karl Williamson [Sun, 2 Sep 2012 20:26:20 +0000 (14:26 -0600)]
regen/regcharclass.pl: Change to work on an empty class
Future commits will add Unicode properties for this to generate macros,
and some of them may be empty in some Unicode releases. This just
causes such a generated macro to evaluate to 0.
Karl Williamson [Fri, 31 Aug 2012 23:04:30 +0000 (17:04 -0600)]
regen/regcharclass.pl: Fix bug for character '0'
The character '0' could be omitted from some generated macros due to
it's testing the value of a hash entry (getting 0 or false) instead
of if it exists or not.
Karl Williamson [Fri, 31 Aug 2012 23:00:27 +0000 (17:00 -0600)]
regen/regcharclass.pl: Work on EBCDIC platforms
This will now automatically generate macros for non-ASCII platforms,
by mapping the Unicode input to native output.
Doing this will allow several cases of EBCDIC dependencies in other code
to be removed, and fixes the bug that this previously had with non-ASCII
platforms.
Karl Williamson [Mon, 3 Sep 2012 22:22:32 +0000 (16:22 -0600)]
regen/regcharclass.pl: Remove Encode:: dependency
Newer options to unpack alleviate the need for Encode, and run faster.
Karl Williamson [Fri, 31 Aug 2012 22:39:31 +0000 (16:39 -0600)]
regen/regcharclass.pl: Handle ranges, \p{}
Instead of having to list all code points in a class, you can now use
\p{} or a range.
This changes some classes to use the \p{}, so that any changes Unicode
makes to the definitions don't have to manually be done here as well.
Karl Williamson [Sun, 2 Sep 2012 19:09:48 +0000 (13:09 -0600)]
utf8.h: Save a branch in a macro
By adding a mask, we can save a branch. The two expressions match the
exact same code points.
Karl Williamson [Sun, 2 Sep 2012 19:08:21 +0000 (13:08 -0600)]
utf8.h: White-space only
This reflows some lines to fit into 80 columns
Karl Williamson [Sun, 2 Sep 2012 19:01:50 +0000 (13:01 -0600)]
utf8.h: Correct improper EBCDIC conversion
These macros were incorrect for EBCDIC. The relationships are based on
I8, the intermediate-utf8 defined for UTF-EBCDIC, not the final encoding.
I was the culprit who did this orginally; I was confused by the names of
the conversion macros. I'm adding names that are clearer to me; which
have already been defined in utfebcdic.h, but weren't defined for
non-EBCDIC platforms.