| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
| |
This adds a new function to sv.c, sv_ref, which is a nul-and-UTF8
clean version of sv_reftype. pp_ref now uses that.
sv_ref() not only returns the SV, but also takes in an SV
to modify, so we can say both sv_ref(TARG, obj, TRUE); and
sv = sv_ref(NULL, obj, TRUE);
|
|
|
|
|
| |
Some tests in t/uni/bless.t are TODO, as ref() isn't
clean yet.
|
| |
|
| |
|
|
|
|
| |
They were nearly identical.
|
|
|
|
|
| |
They are almost identical. This gives the compiler less code
to digest.
|
|
|
|
| |
These ops considered typeglobs read-only, even if they weren’t.
|
|
|
|
|
|
| |
$[ remains as a variable. It no longer has compile-time magic.
At runtime, it always reads as zero, accepts a write of zero, but dies
on writing any other value.
|
|
|
|
|
|
|
|
|
|
|
| |
There are so many cases that use this incantation to get around
gv_fetchsv’s calling of get-magic--
STRLEN len;
const char *name = SvPV_nomg_const(sv,len);
gv = gv_fetchpvn_flags(name, len, flags | SvUTF8(sv), type);
--that it’s about time we had a shorthand.
|
|
|
|
|
|
| |
and silences some compiler warnings.
I do not understand the code in toke.c but the change aligns the code
with other uses of FUN0OP, it has no warnings and does not break any test.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Magical variables usually get autovivified, even in rvalue context,
because Perl is trying to pretend they have been there all along.
That means defined(${"."}) will autovivify $. and return true.
Until CORE subs were introduced, there were no subroutines that popped
into existence when looked at.
This commit makes rv_2cv use the GV_ADDMG flag added in commit
23496c6ea. When this flag is passed, gv_fetchpvn_flags creates a GV
but does not add it to the stash until it finds out that it is creat-
ing a magical one. The CORE sub code calls newATTRSUB, which expects
to add the CV to the stash itself. So the gv has to be added there
and then. So gv_fetchpvn_flags is also adjusted to add the gv to the
stash right before calling newATTRSUB, and to tell itself that the
GV_ADDMG flag is actually off.
It might be better to move the CV-creation code into op.c and inline
parts of newATTRSUB, to avoid fiddling with the addmg variable (and
avoid prototype checks on CORE subs), but that refactoring should
probably come in separate commits.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This resolves perl bug #97978.
Many built-in variables, like $], are actually created on the fly
when first accessed. Perl likes to pretend that these variables have
always existed, so it autovivifies the *] glob even in rvalue context
(e.g., defined *{"]"}, close "]").
The list of variables that were autovivified was maintained separ-
ately (in is_gv_magical_sv) from the code that actually creates
them (gv_fetchpvn_flags). ‘Maintained’ is not actually precise: it
*wasn’t* being maintained, and there were new variables that never
got added to is_gv_magical_sv and one deleted variable that was
never removed.
There are only two pieces of code that call is_gv_magical_sv, both in
pp.c: S_rv2gv (called by *{} and also the implicit *{} that functions
like close() provide) and Perl_softrefxv (called by ${}, @{}, %{}).
In both cases, the glob is immediately autovivified if
is_gv_magical_sv returns true.
So this commit eliminates the extra maintenance burden by extirpat-
ing is_gv_magical_sv altogether, and replacing it with a new flag to
gv_fetchpvn_flags, GvADDMG, which will autovivify a glob *if* it’s a
magical one.
It does make defined(*{"frobbly"}) slightly slower, in that it creates
a temporary glob and then frees it when it sees nothing magical has
been done with it. But this case is rare enough it should not matter.
At least I got rid of the bugginess.
|
|
|
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::unpack to be called through references and
via ampersand syntax.
It moves the $_-handling code in pp_coreargs inside the parameter
loop, so it can apply to the second parameter, not just the first.
Consequently, a mkdir test has been added that ensures implicit $_
is not used for mkdir’s second argument; i.e., that the $_-handling
code’s if() condition is correct.
|
|
|
|
|
|
|
| |
This commit allows the tie, tied and untie subroutines in the CORE
namespace to be called through references and via &ersand() syntax.
pp_coreargs is modified to handle the functions with \[$@%*] in their
prototypes (which happen to be just the tie functions).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit makes &CORE::substr callable through references and via
&ersand syntax.
It’s a bit awkward, as we need a substr op that is flagged as hav-
ing 4 arguments *and* possibly returning an lvalue. The code in
op_lvalue_flags wasn’t really set up for that, so I needed to flag
the op with OPpMAYBE_LVSUB in coresub_op before it gets passed to
op_lvalue_flags. It turned out that only that was necessary, as
op_lvalue_flags does an op_private == 4 check (rather than (op_private
& 7) == 4 or some such) when checking for the 4-arg case and croak-
ing. When the op arrives in op_lvalue_flags, it’s already flagged
OPpMAYBE_LVSUB|4 which != 4.
pp_substr is also modified to check for nulls and, if necessary,
adjust its count of how many arguments were actually passed.)
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::srand to be called through references and
via ampersand syntax. pp_srand is modified to take into account the
nulls pushed on to the stack in pp_coreargs, which happens because
pp_coreargs has no other way to tell srand how many arguments it’s
actually getting. See commit 0163043a for details.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, all case changing on utf8-encoded strings used the tables on
disk, under the off-chance that there was a user-defined case change
override in effect. Now that that feature has been removed, this can't
happen, so we can use the existing built-in tables.
This code has been present and ifdef'd out since 5.10.1. New compiler
warnings forced a few other changes besides removing the #if statements
Running some primitive benchmarks showed that this sped up upper-casing of
utf8 strings in the latin1 range by 2 orders of magnitude.
|
|
|
|
|
| |
This now reflects Tom Christiansen's and my current thinking about Greek
Final Sigma
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These are grouped together because they all have \$ in their
prototypes.
This commit allows the subs in the CORE package under those names to
be called through references and via &ersand syntax.
The coreargs op in the subroutine is marked with the OPpSCALARMOD
flag. (scalar_mod_type in op.c returns true for these three ops,
indicating that the OA_SCALARREF parameter is \$, not \[$@%(&)*].)
pp_coreargs uses that flag to decide what arguments to reject.
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::rand to be called through references and
via ampersand syntax. pp_rand is modified to take into account the
nulls pushed on to the stack in pp_coreargs, which happens because
pp_coreargs has no other way to tell rand how many arguments it’s
actually getting. See commit 0163043a for details.
|
|
|
|
|
|
| |
This commit allows &CORE::open to be called through references or with
ampersand syntax. It modifies pp_coreargs not to push nulls for ops
that require a pushmark.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::lock to be called through references and
via ampersand syntax. It adds code to pp_coreargs for handling the
OA_SCALARREF case, though what it adds is currently lock-specific.
(Subsequent commits will address that.) Since lock returns the scalar
passed to it, not a copy, &CORE::lock needs to use op_leavesublv,
rather than op_leavesub. But it can’t be an lvalue sub, as
&CORE::lock = 3 should be disallowed. So we use the sneaky trick of
turning on the lvalue flag before attaching the op tree to the sub
(which causes newATTRSUB to use op_leavesublv), and then turning it
off afterwards.
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::index and &CORE::rindex to be called through
references and via ampersand syntax. pp_index is modified to take
into account the nulls pushed on to the stack in pp_coreargs, which
happens because pp_coreargs has no other way to tell pp_index how many
arguments it’s actually getting. See commit 0163043a for details.
|
|
|
|
|
| |
This check, added by ed996e63f6, is no longer necessary as of commit
f132ae694c, since PL_sv_undef takes a different path.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit afd1915d made filehandle vivification work on hash and array
elements, but in doing so it accidentally changed
*{;undef} = 3;
to do the same thing as
*{""} = 3;
while leaving
*{$some_undefined_variable}
an error.
This commit adjusts the if() conditions in S_rv2gv (formerly in
pp_rv2gv) in pp.c to make PL_sv_undef follow the same path as before.
It also removes the uninit tests from lib/warnings/pp, since they
are now errors. The uninit warning in rv2gv is only triggered now
when it is implicit, as in close(). That is already tested in
lib/warnings/9uninit.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
This commit allows the subs in the CORE package for close, getc and
readline to be called through references and via ampersand syntax. A
special case for each of them is added to pp_coreargs to deal with
calls with no arguments. Pushing a null on to the stack (which I’m
doing for other ops) won’t work, as a null already means something for
these cases: close($f) won’t vivify a typeglob if $f is a string, so
the implicit rv2gv pushes a null on to the stack.
|
|
|
|
|
|
|
| |
This commit allows the subs in the CORE package for close, getc and
readline to be called through references and via ampersand syntax. The
pp functions are modified to take into account the nulls that coreargs
pushes on to the stack to indicate that there is no argument.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit allows the CORE subroutines for functions with @
and $@ prototypes to be called through references and via amper-
sand syntax.
unlink is not included in this commit, as it requires special casing
due to its use of implicit $_.
Since these functions require a pushmark, and since it has to come
between two things that pp_coreargs does, it’s easiest to flag the
coreargs op (with the OPpCOREARGS_PUSHMARK flag added in the previous
commit) and call pp_pushmark directly from pp_coreargs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit allows &CORE::caller to be called through references and
via ampersand syntax. pp_caller is modified to take into account
two things:
1) pp_coreargs pushes a null on to the stack, since it has no other
way to tell caller whether it has an argument.
2) The value coming from pp_coreargs (when not null) is off by
one. The OPpOFFYBONE flag was added in commit 93f0bc4935 for
this purpose.
pp_coreargs is also modified, since it assumed till now that an
optional first argument was an implicit $_.
|
|
|
|
|
|
|
| |
This commit allows &CORE::bless to be called through references and
via ampersand syntax. pp_bless is modified to take into account the
nulls pushed on to the stack in pp_coreargs, since pp_coreargs has no
other way to tell bless how many arguments it’s actually getting.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This enables ampersand calls and calls through references for CORE
subs that have * and $ in their prototypes and a fixed number of
arguments.
Usually, the *-prototyped ops have their child ops wrapped in rv2gv’s
(*{}) implicitly. The rv2gv op is sometimes flagged as an autoviv-
ificatory op, such as the first argument to accept() or open().
S_is_handle_constructor contains the list of ops that turn on
that flag.
This commit makes the coreargs op use a couple of flags to serve the
same purpose. pp_coreargs itself calls S_rv2gv (split out from
pp_rv2gv recently for precisely this purpose) with arguments based on
its own flags.
Currently the autovivified glob gets a name like main::_GEN_0 instead
of main::$a. I think we can live with that.
|
|
|
|
|
| |
This allows the glob-deref logic to be use by other functions in pp.c,
like pp_coreargs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit adds all subs with a (_) prototype to the list of those
that can be called with ampersand syntax or through references. These
have bodies like this:
$ ./perl -Ilib -MO=Concise,CORE::abs -e 'BEGIN{\&CORE::abs}'
CORE::abs:
3 <1> leavesub[1 ref] K/REFC,1 ->(end)
2 <1> abs[t1] sK/1 ->3
1 <$> coreargs(IV 111) s ->2
-e syntax OK
coreargs fetches the caller’s $_ if there are no arguments passed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch prevents get-magic from executing twice during autovivifi-
cation when the op doing the autovivification is not directly nested
inside the dereferencing op.
This can happen in cases like this:
${ (), $a } = 1;
Previously (as of 5.13.something), the outer op was marked with the
OPpDEREFed flag, which indicated that get-magic had already been
called by the vivifying op (calling get-magic during vivification is
inevitable):
$ perl5.14.0 -MO=Concise -e '${ $a } = 1'
8 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 2 -e:1) v:{ ->3
7 <2> sassign vKS/2 ->8
3 <$> const[IV 1] s ->4
6 <1> rv2sv sKRM*/DREFed,1 ->7 <-- right here
- <@> scope sK ->6
- <0> ex-nextstate v ->4
5 <1> rv2sv sKM/DREFSV,1 ->6
4 <#> gv[*a] s ->5
-e syntax OK
But in the ${()...} example above, there is a list op in the way that
prevents the flag from being set inside the peephole optimizer. It’s
not even possible to set it correctly in all cases, as in this exam-
ple, which would need it both set and not set depending on which
branch of the ternary operator is executed:
${ $x ? delete $a[0] : $a[0] } = 1
Instead of setting the OPpDEREFed flag, we now make a non-magic copy
of the SV in vivify_ref (the first time get-magic is executed).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This example:
sub TIESCALAR { bless[]}
sub FETCH { warn "fetching"; "\cTAINT" }
tie my $a, "";
defined $$a;
prints ‘fetching’ three times in 5.8.8, five times (!) in 5.10-12,
four times in 5.14, and three times in blead as of ed996e63f6. Now it
only happens once.
It was commit 7a5fd60d4c that increased the number of fetches in 5.10,
but I haven’t checked which commits reduced it in 5.14.
|
|
|
|
|
|
|
|
|
|
| |
Currently <$foo> does not autovivify, but readline($foo) does, due to
the way pp_readline calls pp_rv2gv directly, with PL_op still holding
a pp_readline op, whose flags may have completely different meanings.
readline uses the OPf_SPECIAL flag to distinguish <$foo> from readline
($foo). rv2gv uses it to determine whether to autovivify; hence the
discrepancy.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit ac53db4c3f7e fixed bug #31767 (open $1 not dying), but put the
SvREADONLY check in the wrong spot, causing this bug:
$ perl -lwe 'no warnings "once"; close $x; close $+'
Name "main::x" used only once: possible typo at -e line 1.
Use of uninitialized value $x in ref-to-glob cast at -e line 1.
Modification of a read-only value attempted at -e line 1.
It shouldn’t be dying if I’m not trying to modifying it.
|
|
|
|
|
|
|
|
|
|
| |
This commit stops an implicit rv2gv from calling get-magic twice. As
a side-effect, it also squelches the duplicate warning emitted by
‘close undef’ (bug #97482).
is_gv_magical_sv is modified not to call get-magic on the sv passed to
it. It is not in the public API, and the only two callers (rv2gv and
softrefxv) have already called get-magic before calling it.
|
|
|
|
|
|
| |
sv can no longer be null at these points, as of commit 99fc7eca4,
which fixed buggy code that 7a5fd60d4 added (which resulted in
various interesting bugs and workarounds over the past few years.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There is special code in pp_rv2gv to deal with the case of built-in
variables that are created on the fly. It basically pretends that
they have always existed, even in rvalue context.
Normally, defined(*{"foo"}) will not actually create the *foo glob,
but will simply return false. defined(*{">"}), however is supposed
to return true because of the $> variable; its popping into existing
when looked at being an implementation detail. That is the whole pur-
pose of is_gv_magical_sv in gv.c.
Prior to this commit, however, defined(*{">"}) would autovivify the
GV, but then return *false*!
It was simply a matter of faulty logic in this part of pp_rv2gv:
SV * const temp = MUTABLE_SV(gv_fetchsv(sv, 0, SVt_PVGV));
if (!temp
&& (!is_gv_magical_sv(sv,0)
|| !(sv = MUTABLE_SV(gv_fetchsv(sv, GV_ADD,
SVt_PVGV))))) {
RETSETUNDEF;
}
sv = temp;
The autovivification happens in the second gv_fetchsv call. But after
the new GV is assigned to sv and the condition proves false, we reach
the sv = temp assignment which clobbers it.
|
|
|
|
|
|
|
|
|
|
| |
Commit bb1bc619 eliminated the only case that ‘goto wasref’ is called
with something that might have overloading. The only ‘goto wasref’
that remains is the autovivifying case, which cannot have any magic
(since the GV has just been created). So the wasref label can be
moved below the amagic check.
Consider this a picoöptimisation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit makes nullary subs in the CORE package callable with
ampersand syntax and through references--except for wantarray, which
is more complicated and will have its own commit.
It does this by creating an op tree like this:
$ ./perl -Ilib -MO=Concise,CORE::times -e 'BEGIN{\&CORE::times}'
CORE::times:
3 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq K ->3
1 <$> coreargs(IV 310) v ->2
2 <0> tms ->3
-e syntax OK
The coreargs op checks to make sure there are no arguments, for now.
The 310 is the op number for times (OP_TMS).
There is no nextstate op, because we want to inherit hints from
the caller.
The __FILE__, __LINE__ and __PACKAGE__ directives are implemented
like this:
$ ./perl -Ilib -MO=Concise,CORE::__FILE__ -e 'BEGIN{\&CORE::__FILE__}'
CORE::__FILE__:
7 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq K ->7
1 <$> coreargs(PV "__FILE__") v ->2
6 <2> lslice K/2 ->7
- <1> ex-list lK ->4
2 <0> pushmark s ->3
3 <$> const(IV 1) s ->4
- <1> ex-list lK ->6
4 <0> pushmark s ->5
5 <0> caller[t1] l ->6
-e syntax OK
The lslice op and its children are equivalent to (caller)[1].
|
|
|
|
| |
&CORE::foo subs will use this operator for sorting out @_.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In 5.10, lock(&foo) was an error for non-lvalue subs. For lvalue
subs, it passed &foo to the lockhook and return \&foo.
In 5.12, lock(&foo) was still an error for non-lvalue subs. For
lvalue subs, it would pass &foo to the lockhook and then either
trip an assertion (-DDEBUGGING) or return &foo, resulting in inter-
esting bugs.
Commit f4df43b5e changed lock(&lvalue_sub) to call the sub and lock
its return value.
As Reini Urban pointed out in
<CAHiT=DE5cVZbuCR3kb=Q5oCa18vo3jr5jZKmURHYha2PwF4pEQ@mail.gmail.com>,
locking a subroutine does have its uses.
Since lock(&foo) has never really worked anyway, we can still
change this.
So, for lvalue subs, this reverts back to the 5.10 behaviour. For
non-lvalue subs, it now behaves the same way, the lvalue flag making
no difference. Note that it still causes an error at run-time, if
threads::shared is loaded, as its lockhook is conservative in what
it accepts.
But this change allows for future extensibility, unlike f4df43b5e.
A note about the implementation: There are two pieces of code (at
least) in op.c that convert an entersub op into an rv2cv, one in
S_doref and the other in Perl_op_lvalue_flags. Originally (before
f4df43b5e) it was S_doref that took care of that for OP_LOCK. But
Perl_op_lvalue_flags is called first, so it would assume it was an
assignment to a sub call and croak if there was no lvalue sub in the
symbol table. This commit adds back the special case for OP_LOCK, but
in Perl_op_lvalue_flags, not S_doref.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit b8c38f0a2a65 refactored pp_prototype by moving much of its
code to a new function in op.c, called core_prototype. This served
two purposes: (1) to allow the code to be simplified, which required
the use of static functions in op.c, and (2) to allow the &CORE::subs
feature to share the same code.
But some code was moved to core_prototype which, in hindsight, did not
need to be moved, such as the ‘Can’t find an opnumber’ message.
This commit moves that code back to pp_prototype, resulting in a sim-
pler (and possibly faster, at least for &CORE::subs) core_prototype.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This refactoring requires the caller to provide the keyword
number to core_prototype. Consequently, it speeds up the code in
gv.c:gv_fetchpvn_flags by allowing it to avoid an extra call to
keyword().
This takes the place of the len parameter, which is no longer used.
It used to be used only as an argument to keyword(). Since the code
that uses strEQ is only reached if the keyword has already been veri-
fied by keyword(), the name simply cannot have embedded nulls, so len
is not necessary.
|
|
|
|
|
|
|
| |
Since it has to calculate it, it might as well provide it, so callers
do not have to go through that while(i < MAXO) loop yet again.
(The &CORE::foo feature will use this.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit moves the code for generating core prototypes into a sepa-
rate function, core_prototype, in op.c. This serves two porpoises:
• It allows the lock and tie exceptional cases to be incorporated into
the main prototype=generation code, which requires the use of a
static function in op.c.
• It allows other parts of the core (e.g., the upcoming \&CORE::foo
feature) to use the same code.
The docs for it are in a section boringly entitled ‘Functions in
op.c’, for lack of a better name. This, I believe, is the only op.c
function that is in perlintern currently, so it’s hard to see what to
name a section that will, at least for now, contain nothing else.
|
|
|
|
|
|
|
|
| |
Dereferencing ops (${}, etc.) were calling get-magic on their operand
twice if it was a symbolic reference, except for &{}.
This commit fixes that, adding tests for all the deref ops, including
&{}, for good measure.
|