| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This adds the array_base feature to feature.pm
Perl_feature_is_enabled has been modified to use PL_curcop, rather
than PL_hintgv, so it can work with run-time hints as well.
(PL_curcop holds the current state op at run time, and &PL_compiling
at compile time, so it works for both.) The hints in $^H are not
stored in the same place at compile time and run time, so the FEATURE_IS_ENABLED macro has been modified to check first whether
PL_curop == &PL_compiling.
Since array_base is on by default with no hint for it in %^H, it is
a ‘negative’ feature, whose entry in %^H turns it off. feature.pm
has been modified to support such negative features. The new FEATURE_IS_ENABLED_d can check whether such default features
are enabled.
This does make things less efficient, as every version declaration
now loads feature.pm to disable all features (including turning off
array_base, which entails adding an entry to %^H) before loading the
new bundle. I have plans to make this more efficient.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
As mentioned in ticket #24346, scalar() should not change lvalueness.
The fact that it did was a side effect of the implementation and a
bug. foo(scalar substr(....)) should pass a substr lvalue to foo just
as it would without scalar() or with a $ prototype (which is meant to
be equivalent to scalar()).
This also makes it possible to force scalar context in list assignment
to lvalue subroutines, as in (foo(), scalar bar()) = @list.
|
|
|
|
| |
And don’t look in the hint hash unless the LOCALIZE_HH hint is set.
|
|
|
|
|
|
|
|
| |
• Version declarations now unload all features before loading the
specified feature bundle.
• Explicit use/no strict overrides any implicit strict-loading done by
version declarations, whether before or after use of strict.pm.
• ‘use 5.01’ or earlier disables any implicitly-enabled strictures.
|
|
|
|
|
|
|
|
| |
24fcb59fc optimised substr assignment in void context down to four-arg
substr, causing considerable speed-up, but did not take the extra step
of marking the substr op itself as being in void context, so pp_substr
was still constructing a return value. This commit speed things up
just a tiny bit more.
|
|
|
|
|
|
|
| |
In commit 1a35f9ffb I forgot to make an inlined OP_RUNCV op a PVOP in
ck_entersub_args_core (which inlines a &CORE::sub).
This caused crashes on Linux, but not on OS X, for some reason.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In void context we can optimise
substr($foo, $bar, $baz) = $replacement;
to something like
substr($foo, $bar, $baz, $replacement);
except that the execution order must be preserved. So what we actu-
ally do is
substr($replacement, $foo, $bar, $baz);
with a flag to indicate that the replacement comes first. This means
we can also optimise assignment to two-argument substr the same way.
Although optimisations are not supposed to change behaviour,
this one does.
• It stops substr assignment from calling get-magic twice, which means
the optimisation makes things less buggy than usual.
• It causes the uninitialized warning (for an undefined first argu-
ment) to mention the substr operator, as it did before the previous
commit, rather than the assignment operator. I think that sort of
detail is minor enough.
I had to make the warning about clobbering references apply whenever
substr does a replacement, and not only when used as an lvalue. So
four-argument substr now emits that warning. I would consider that a
bug fix, too.
Also, if the numeric arguments to four-argument substr and the
replacement string are undefined, the order of the uninitialized warn-
ings is slightly different, but is consistent regardless of whether
the optimisation is in effect.
I believe this will make 95% of substr assignments run faster. So
there is less incentive to use what I consider the less readable form
(the four-argument form, which is not self-documenting).
Since I like naïve benchmarks, here are Before and After:
$ time ./miniperl -le 'do{$x="hello"; substr ($x,0,0) = 34;0}for 1..1000000'
real 0m2.391s
user 0m2.381s
sys 0m0.005s
$ time ./miniperl -le 'do{$x="hello"; substr ($x,0,0) = 34;0}for 1..1000000'
real 0m0.936s
user 0m0.927s
sys 0m0.005s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If __SUB__ is not inside a closure, it can be optimised to a constant.
We can only do this in the peephole optimiser, as we cannot tell
whether PL_compcv will become a closure until we reach the end
of the sub.
The __SUB__ op cannot simply be replaced with a const op, as the par-
ent op is not readily available in the peephole optimiser and, hence,
we cannot change its pointer.
So we have to convert the runcv op itself into a const op. So it
has to be the same size. This commit makes it a PVOP, since newPVOP,
unlike newSVOP, allows a null pv. To avoid adding workarounds to B
modules, I put an exception in newPVOP’s assertion, instead of chang-
ing the type in regen/opcodes.
But B::Deparse still had to be updated to avoid infinite recursion.
|
|
|
|
|
|
|
|
|
|
|
| |
A slight mistake in the evalbytes.t test script caused a lot of tests
not be testing what they were supposed to be testing for. I used
'qq(\x...)' instead of qq('\x...'). (I.e., I was trying to embed lit-
eral Unicode characters in the string, rather than pass escapes to
evalbytes.)
I had wondered at the time why it worked without my doing anything, so
I probably should have looked deeper.
|
| |
|
| |
|
|
|
|
|
| |
After much alternation, altercation and alteration, __SUB__ is
finally here.
|
|
|
|
|
|
|
|
|
|
| |
The logic surrounding subroutine redefinition warnings (to warn or not
to warn?) was in three places. Over time, they drifted apart, to the
point that newXS was following completely different rules. It was
only warning for redefinition of functions in the autouse namespace.
Recent commits have brought it into conformity with the other redefi-
nition warnings.
Obviously it’s about time we put it in one function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There is no reason why constant redefinition warnings should be
default warnings for sub foo(){1}, but not for newCONSTSUB (which
calls newXS, which triggers the warning).
To make this work properly, I also had to import sv.c’s ‘are these
const subs from the same SV originally?’ logic. Constants created
with XS can have NULL for the SV (they return an empty list or
&PL_sv_undef), which means sv.c’s logic will stop *this=\&that from
warning if both this and that are such XS-created constants.
newCONSTSUB needed to be consistent with that. It required tweaking a
test I added a few commits ago, which arguably shouldn’t have warned
the way it was written.
As of this commit (and before it, too, come to think of it),
newXS_len_flags’s calling convention is quite awful and would need to
be throughly re-thunk before being made into an API, or probably sim-
ply never made into an API.
|
|
|
|
|
| |
Putting inside the if() condition allows me to add an || in the
next commit.
|
|
|
|
|
|
|
|
|
|
|
| |
In perldiag, this is listed as (S), which means that outside of any
use/no warnings scope it always warns, regardless of $^W.
But this warning was ignoring use/no warnings, too.
There were actually tests for this oddity, but I think those were
added by mistake, or this was just not thought through. I cannot see
how this is not a bug.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
newCONSTSUB uses the compile-time warning hints, instead of the run-
time hints. This means that
use warnings;
BEGIN {
no warnings;
some_XS_function_that_calls_new_CONSTSUB();
}
may trigger a redefinition warning, whereas it should be analogous to
use warnings;
BEGIN {
no warnings;
*foo = \&bar;
}
which does not warn.
newCONSTSUB localises PL_curcop and sets it to &PL_compiling. When it
does that, it needs to copy the hints over.
Running tests inside eval is not reliable without a test count, so I
added one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This also restores the subroutine redefinition warning for newly-cre-
ated XSUBs outside the autouse package. See below.
This commit added the exemption to fix a known bug, that loading a
module and importing from it would cause a redefinition warning if
there were an autouse stub:
perl-5.004_03-1092-g2f34f9d
commit 2f34f9d4825ac9262ece854fc4c50479f4838ff8
Author: Ilya Zakharevich <ilya@math.berkeley.edu>
Date: Mon Mar 2 16:36:02 1998 -0500
Make autouse -w-safe
p4raw-id: //depot/perl@781
The subroutine redefinition warning occurs in three places.
This commit removed the autouse exemption from two
of them. I can’t see how it wasn’t a mistake, as <5104D4DBC598D211B5FE0000F8FE7EB202D49EE9@mbtlipnt02.btlabs.bt.co.uk>
(the apparent source of the patch, makes no mention of it:
perl-5.005_02-2920-ge476b1b
commit e476b1b5c29f354cf8dad61a9fc6d855bdfb5b7d
Author: Gurusamy Sarathy <gsar@cpan.org>
Date: Sun Feb 20 22:58:09 2000 +0000
lexical warnings update, ability to inspect bitmask in calling
scope, among other things (from Paul Marquess)
p4raw-id: //depot/perl@5170
This commit refactored things to remove some compiler warnings, but
in doing so reversed the logic of the condition, causing redefini-
tion warnings for newly-created XSUBs to apply only to subs from the
autouse package:
perl-5.8.0-5131-g66a1b24
commit 66a1b24beb76ea873ad4caa57ee3ab9df945afbf
Author: Andy Lester <andy@petdance.com>
Date: Mon Jun 6 05:11:07 2005 -0500
Random cleanups #47
Message-ID: <20050606151107.GC7022@petdance.com>
p4raw-id: //depot/perl@24735
I’ve basically reinstated the changes in 2f34f9d4, but with tests
this time.
It may not make sense for autouse to be exempt for newATTRSUB and
newXS, but keeping the logic surrounding the warning as close as
possible to being the same could allow future refactorings to
merge them.
|
| |
|
|
|
|
|
|
|
|
|
| |
It accepts a length as well as a pv for the name.
Since newXS_flags is marked with M in embed.fnc and is undocumented,
technically policy allows me to change it, but there are files
throughout cpan/ that use newXS_flags. So it seemed safer to add a
new function.
|
|
|
|
|
|
| |
Now that newCONSTSUB_flags has a length parameter, new ATTRSUB can
record the length and pass that to newCONSTSUB_flags, instead of using
strlen to get it.
|
|
|
|
|
| |
This function was added after 5.14.0, so it is not too late to
change it. It is currently unused.
|
|
|
|
|
|
|
|
|
| |
Those require() calls are compiled as BASEOPs, so it is invalid to look for
their op_first member when they are translated to a call to the global
override subroutine. The new entersub call should get $_ in its argument
list instead.
This fixes [perl #78260].
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Usually when a BEGIN block exits it has to set PL_curcop to
&PL_compiling, so that subsequent compiled code in the surrounding
scope will have the right warning hints during compilation.
If an XS function creates a BEGIN block via newXS or newATTRSUB, how-
ever, the assumption that compilation will resume as soon as the block
exits is false.
This can be demonstrated with this code, which warns about CHECK and
INIT blocks created too late when it shouldn’t due to ‘no warnings’:
use warnings;
eval q|
BEGIN{
no warnings;
package XS::APItest; require XSLoader; XSLoader::load()
}
|;
In every case where it is correct for BEGIN to set PL_curcop to
&PL_compiling when it exits it is actually just restoring it to its
previous value, so localisation is the right fix.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
This function evaluates its argument as a byte string, regardless of
the internal encoding. It croaks if the string contains characters
outside the byte range. Hence evalbytes(" use utf8; '\xc4\x80' ")
will return "\x{100}", even if the original string had the UTF8 flag
on, and evalbytes(" '\xc4\x80' ") will return "\xc4\x80".
This has the side effect of fixing the deparsing of CORE::break under
‘use feature’ when there is an override.
|
|
|
|
|
| |
(modified by the committer only to apply when the unicode_eval
feature is enabled)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Class::ClassDecorator was crashing during compilation on this line:
@{"$name\::ISA"} = ( reverse @_ );
I presume this was due to commit 540dd770, which changed the way the
inplace-reverse optimisation is activated, because the crash happens
in S_inplace_aassign. But deleting even one line of code here or
there makes the crash go away (hence the lack of tests).
This is my reasoning for how this commit eliminates the crash:
@{""} = reverse @_
compiles down to
b <2> aassign[t5] vKS/COMMON ->c
- <1> ex-list lK ->8
3 <0> pushmark s ->4
7 <@> reverse[t4] lK/1 ->8
4 <0> pushmark s ->5
6 <1> rv2av[t3] lK/1 ->7
5 <#> gv[*_] s ->6
- <1> ex-list lK ->b
8 <0> pushmark s ->9
a <1> rv2av[t1] lKRM*/1 ->b
- <@> scope sK ->a
- <0> ex-nextstate v ->9
9 <$> const[PV ""] s ->a
Notice that the second rv2av does not have an a gv op as its child,
but a scope instead.
In S_inplace_aassign, which checks to see whether the optimisation is
even possible, oleft refers to the second rv2av above (with scope as
its child; i.e., @{""}) while oright refers to the first rv2av (with
gv as its child; @_).
This check to make sure the left side is an array
/* Check the lhs is an array */
if (!oleft ||
(oleft->op_type != OP_RV2AV && oleft->op_type != OP_PADAV)
|| oleft->op_sibling
|| (oleft->op_private & OPpLVAL_INTRO)
)
return;
does not check the op type of the rv2av’s child.
So this check, a little further on, to see whether the arrays are the
same on both sides (which applies only to rv2av; padav is handled
further on):
/* check the array is the same on both sides */
if (oleft->op_type == OP_RV2AV) {
if (oright->op_type != OP_RV2AV
|| !cUNOPx(oright)->op_first
|| cUNOPx(oright)->op_first->op_type != OP_GV
|| cGVOPx_gv(cUNOPx(oleft)->op_first) !=
cGVOPx_gv(cUNOPx(oright)->op_first)
)
return;
assumes that cUNOPx(oleft)->op_first is a gv op.
That is not the case when the lhs is @{""}, so
cGVOPx_gv(some_scope_op) ends up trying to read
((PADOP*)some_scope_op)->op_padix under threaded perls, passing
that ‘index’ (which is actually the scope op’s op_first field) to
PAD_SV[...], consequently reading past the end of the pad and possibly
into unallocated territory; hence the crash.
|
|
|
|
|
|
|
| |
Following Michael Schwern’s suggestion, here is a warning for those
hapless folks who use $[ for version checks.
It applies whenever $[ is used in one of: < > <= >=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit makes CORE::glob bypassing glob overrides.
A side effect of the fix is that, with the default glob implementa-
tion, undefining *CORE::GLOBAL::glob no longer results in an ‘unde-
fined subroutine’ error.
Another side effect is that compilation of a glob op no longer assumes
that the loading of File::Glob will create the *CORE::GLOB::glob type-
glob. ‘++$INC{"File/Glob.pm"}; sub File::Glob::csh_glob; eval '<*>';’
used to crash.
This is accomplished using a mechanism similar to lock() and
threads::shared. There is a new PL_globhook interpreter varia-
ble that pp_glob calls when there is no override present. Thus,
File::Glob (which is supposed to be transparent, as it *is* the
built-in implementation) no longer interferes with the user mechanism
for overriding glob.
This removes one tier from the five or so hacks that constitute glob’s
implementation, and which work together to make it one of the buggiest
and most inconsistent areas of Perl.
|
|
|
|
|
|
|
|
|
|
| |
This stops PL_curstash from pointing to a freed-and-reused scalar in
cases like ‘package Foo; BEGIN {*Foo:: = *Bar::}’.
In such cases, another BEGIN block, or any subroutine definition,
would cause a crash. Now it just happily proceeds. newATTRSUB and
newXS have been modified not to call mro_method_changed_in in such
cases, as it doesn’t make sense.
|
|
|
|
|
| |
This function was declared static in embed.fnc, but the actual function
definition was missing the 'STATIC'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit moves attribute handling in newATTRSUB so that it happens
after the op tree is attached to the sub. So when the sub is freed,
the op tree goes with it, instead af leaking when an attribute han-
dler dies.
Witness what happens without that:
$ PERL_DESTRUCT_LEVEL=2 ./perl -Ilib -le 'BEGIN {$^H{a}="b"}; sub foo:bar{1}'
Invalid CODE attribute: bar at -e line 1
BEGIN failed--compilation aborted at -e line 1.
Unbalanced string table refcount: (1) for "a" at (null) line 1 during global destruction.
It was the ‘Unbalanced string table’ warnings that alerted me to the
problem. The fairly new t/uni/attrs.t happens to trigger this bug.
Not that this told me anything, but I did a binary search which lead
me to this commit:
commit b3ca2e834c3607fd8aa8736a51aa3a2b8bba1044
Author: Nicholas Clark <nick@ccl4.org>
Date: Fri Mar 31 13:45:57 2006 +0000
Serialise changes to %^H onto the current COP. Return the compile time
state of %^H as an eleventh value from caller. This allows users to
write pragmas.
That commit started indirectly storing HEKs in cops (in the hints
hash), which means we have an easy way to tell when ops are leaking.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Did you know that a subroutine’s prototype can be modified with s///?
Don’t look:
*AUTOLOAD = *Internals'SvREFCNT;
my $f = "Just another "; eval{main->$f};
print prototype AUTOLOAD;
$f =~ s/Just another /Perl hacker,\n/;
print prototype AUTOLOAD;
You did look, didn’t you? You must admit that’s creepy.
The problem goes back to this:
commit adb5a9ae91a0bed93d396bb0abda99831f9e2e6f
Author: Doug MacEachern <dougm@covalent.net>
Date: Sat Jan 6 01:30:05 2001 -0800
[patch] xsub AUTOLOAD fix/optimization
Message-ID: <Pine.LNX.4.10.10101060924280.24460-100000@mojo.covalent.net>
Allow AUTOLOAD to be an xsub and allow such xsubs
to avoid use of $AUTOLOAD.
p4raw-id: //depot/perl@8362
which includes this:
+ if (CvXSUB(cv)) {
+ /* rather than lookup/init $AUTOLOAD here
+ * only to have the XSUB do another lookup for $AUTOLOAD
+ * and split that value on the last '::',
+ * pass along the same data via some unused fields in the CV
+ */
+ CvSTASH(cv) = stash;
+ SvPVX(cv) = (char *)name; /* cast to loose constness warning */
+ SvCUR(cv) = len;
+ return gv;
+ }
That ‘unused’ field is not unused. It’s where the prototype is
stored. So, not only is it clobbering the prototype, it’s also leak-
ing it by assigning over the top of SvPVX. Furthermore, it’s blindly
assigning someone else’s string, which could be freed before it’s
even used.
Since it has been documented for a long time that SvPVX contains the
name of the AUTOLOADed sub, and since the use of SvPVX for prototypes
is documented nowhere, we have to preserve the former.
So this commit makes the prototype and the sub name share the same
buffer, in a manner resembling that which CvFILE used before I changed
it with bad4ae38.
There are two new internal macros, CvPROTO and CvPROTOLEN for retriev-
ing the prototype.
|
|
|
|
|
|
|
|
| |
If the stash in question has no name, the attempt to generate the
warning will cause a crash.
Simply skipping the warning is this case is fine, as this is will into
‘undefined’ territory (but it still shouldn’t crash).
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
| |
It is no longer used in core (having been superseded by
cv_ckproto_len_flags), is unused on CPAN, and is not part of the API.
The cv_ckproto ‘public’ macro is modified to use the _flags version.
I put ‘public’ in quotes because, even before this commit, cv_ckproto
was using a non-exported function, and hence could never have worked
on a strict linker (or whatever you call it).
|
|
|
|
|
|
|
|
|
|
|
|
| |
This means that eval "sub foo ($;\0whoops) { say @_ }" will correctly
include \0whoops in the CV's prototype (while complaining about illegal
characters), and that
use utf8;
BEGIN { $::{"foo"} = "\$\0L\351on" }
BEGIN { eval "sub foo (\$\0L\x{c3}\x{a9}on) {};"; }
will not warn about a mismatched prototype.
|
|
|
|
|
|
|
|
| |
This makes perl -E '$::{example} = "\x{30cb}"; say prototype example;'
store and fetch the correctly flagged prototype.
With this, all TODO tests in gv.t pass; The next commit will deal
with making the parsing of prototypes nul-clean.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
newXS was merged into newXS_flags; added a line in the docs
recommeding using that instead.
newCONSTSUB got a _flags version, which generates the CV in
the right glob if passed the UTF-8 flag.
|
|
|
|
|
|
|
| |
other macros are written by regen/opcode.pl into opnames.h
Generate OP_IS_NUMCOMPARE the same way, and get a micro-optimization.
Adds a new 'S<' operand type for the numeric comparison ops.
Needs make regen.
|