| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
| |
This reverts commit c56d7fa9134de66efe85a2fd70b28069c2629e0d.
Also un-TODO's the new test for this issue.
Fixes #21044
|
|
|
|
| |
Fix spelling on various files pertaining to core Perl.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Perl_leave_adjust_stacks(), which is called by all the scope-exiting ops
(pp_leave, pp_leavesub etc), handles scalar context by updating the list
of SVs on the stack to be returned to be just the one-item list at the
top of the stack (all other items on the stack being discarded).
For the special case of scalar context and no items on the return list,
it instead puts &PL_sv_undef at the lowest point on the stack and skips
most of the rest of the function. The rest of the function includes
things like shuffling down any args to be returned, which obliterates
any other stuff on that stack that needs discarding. For example in
for (qw(a b c)) { ....; return qw(x y z); ... }
the stack contains a b c x y z; the a,b,c need discarding and the x,y,z
shifting down.
This commit removes the 'skip rest' special behaviour, and makes scalar
return of an empty list behave the same as a scalar return of a
non-empty list. So it pushes &PL_sv_undef at the top of the stack,
then goes through the normal "shift and copy the top arg down the stack"
code path.
This is slightly less efficient, but this is relatively rare condition,
and will make converting Perl_leave_adjust_stacks() to handle a
reference-counted stack easier.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This function was creating a var is_tied that was not necessary,
and using unnecessarily convoluted code to achieve its goals. Its
still somewhat convoluted, but less so. Since we no longer have to
predeclare all variables, moving the bulk of the var decls down
makes the code more clear, and ensures that nothing ends up
uninitialized.
GCC 12 warnings seems to have crappy warnings and overly senstivie ones
as well. The actual usage was from line 1912 in pp_hot.c, yet the
warning mumbles a lot about embed.h. Feh. Note as far as I am concerned
this warning was bogus, except that it highlighted unnecessarily
convoluted code that should be cleaned up.
In file included from perl.h:6197,
from pp_hot.c:36:
embed.h: In function ‘S_padhv_rv2hv_common’:
embed.h:981:49: warning:
‘mg’ may be used uninitialized [-Wmaybe-uninitialized]
981 | # define magic_scalarpack(a,b) \
Perl_magic_scalarpack(aTHX_ a,b)
| ^~~~~~~~~~~~~~~~~~~~~
pp_hot.c:1878:12: note: ‘mg’ was declared here
1878 | MAGIC *mg;
| ^~
Fixes Github Issue #20816
|
|
|
|
|
|
| |
SvIMMORTAL SVs cannot be prematurely freed and so there is no need
to create a mortal copy of them. They also will not leak, so there
is no need to add the SV* to the temp stack.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
I am kinda surprised this issue was not picked up by one of our
other test files. I would have expected one of the t/re/regexp.t
based patches to validate list context matches populating the list
properly. But apparently not! So when I fixed branch reset in
fe5492d916201ce31a107839a36bcb1435fe7bf0 I missed the list context
logic. This fixes the oversight. Thanks to Andreas Koenig for the
BBC report on this.
This also changes the code to use SSize_t for various length related
operations, the original code was using I32 which might break on
very very long strings. Thanks to Tony C for pointing that out.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When svpv_base == svpv_buf, svpv_p would be set to point before the
buffer, which is undefined.
This appears to be what gcc 13 is complaining about in #20678,
despite that report including what appears to be a completely valid
address, on a line where the value of svpv_p is now within the range
of svpv_buf.
An intermediate approach to this used:
temp = svpv_p;
if (svpv_p++ == svpv_end)
break
but this is also incorrect, since svpv_p would end up as an invalid
pointer, though gcc UBSAN didn't pick that up.
Fixes #20678.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
RX_OFFS() exposes a bit too much about how capture buffers are represented.
This adds RX_OFFS_START() and RX_OFFS_END() and RX_OFFS_VALID() to replace
most of the uses of the RX_OFFS() macro or direct access to the rx->off[]
array. (We add RX_OFFSp() for those rare cases that should have direct
access to the array.) This allows us to replace this logic with more
complicated macros in the future. Pretty much anything using RX_OFFS() is
going to be broken by future changes, so changing the define allows us to
track it down easily.
Not all use of the rx->offs[] array are converted; some uses are required
for the regex engine internals, but anything outside of the regex engine
should be using the replacement macros, and most things in the regex internals
should use it also.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In a nutshell, for a long time the minimum PV length (hardcoded
in Perl_sv_grow) has been 10 bytes and the minimum AV array size
(hardcoded in av_extend_guts) has been 4 elements.
These numbers have been used elsewhere for consistency (e.g.
Perl_sv_grow_fresh) in the past couple of development cycles.
Having a standard definition, rather than hardcoding in multiple
places, is more maintainable. This commit therefore introduces
into perl.h:
PERL_ARRAY_NEW_MIN_KEY
PERL_STRLEN_NEW_MIN
(Note: Subsequent commit(s) will actually change the values.)
|
|
|
|
|
|
|
|
| |
This commit:
* Adds support for negative keys, as per the original AELEMFAST_LEX
* Changes an if() check for a "useless assignment to a temporary" into
an assert, since this condition should never be true when the LHS is
the result of an array fetch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit introduces a new OP to replace simple cases of OP_SASSIGN
and OP_AELEMFAST_LEX. (Similar concept to GH #19943)
For example, `my @ary; $ary[0] = "boo"` is currently implemented as:
7 <2> sassign vKS/2 ->8
5 <$> const[PV "boo"] s ->6
- <1> ex-aelem sKRM*/2 ->7
6 <0> aelemfast_lex[@ary:1,2] sRM ->7
- <0> ex-const s ->-
But now will be turned into:
6 <1> aelemfastlex_store[@ary:1,2] vKS ->7
5 <$> const(PV "boo") s ->6
- <1> ex-aelem sKRM*/2 ->6
- <0> ex-aelemfast_lex sRM ->6
- <0> ex-const s ->-
This is intended to be a transparent performance optimization.
It should be applicable for RHS optrees of varying complexity.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This would previously clear the stream error state in any case
where sv_gets() failed and the error state was set.
This included normal files, which meant that the fact that an error
occurred was no longer reflected in the stream state.
For reads from ARGV this was a no-op, since nextargv() re-opens the
input stream by calling do_open6() which closes the old input stream
silently.
For glob() (and really only for miniperl, since File::Glob is used for
a full perl) leaving the stream in an error state could be confusing
for the error reporting done when do_close() fails, since it would
fail if the stream has an error state, but we report it as the
underlying pclose() failing due to the child process failing in some
way.
Since this now leaves the error state on the stream, the close()
calls in the test updated by this commit would fail, changing its
output. Since the result of those closes didn't seem related
to the purpose of the test, I changed it not throw an error on
either close() failing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit introduces a new OP to replace simple cases
of OP_SASSIGN and OP_PADSV.
For example, 'my $x = 1' is currently implemented as:
1 <;> nextstate(main 1 -e:1) v:{
2 <$> const(IV 1) s
3 <0> padsv[$x:1,2] sRM*/LVINTRO
4 <2> sassign vKS/2
But now will be turned into:
1 <;> nextstate(main 1 -e:1) v:{
2 <$> const(IV 1) s
3 <1> padsv_store[$x:1,2] vKMS/LVINTRO
This intended to be a transparent performance optimization.
It should be applicable for RHS optrees of varying complexity.
|
|
|
|
| |
Or, in pp_gv it's also allowed to be a reference to a CV
|
|
|
|
|
|
|
|
|
|
|
| |
Several of these were missing:
cMETHOP, cMETHOPo, kMETHOP
Also, the field-accessing ones:
cMETHOP_meth cMETHOP_rclass cMETHOPo_meth cMETHOPo_rclass
This commit adds them all, and use them to neaten other code where
appropriate.
|
|
|
|
| |
Length just isn't needed, and often took more cpu-time than the actual regex.
|
|
|
|
|
|
| |
Although one of the macros associated with the JMPENV facility
is inconsistently called JMPENV_JUMP(), fix all code comments
and debugging output to eliminate any references to JUMPENV.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Within the "inlined av_fetch() for simple cases" fast path, we already
operate within the bounding conditions of the if() statement. Once
AvARRAY(av)[key] is found to be null, a call of av_fetch(av,key,lval)
here just boils down to a single line:
return lval ? av_store(av,key,newSV_type(SVt_NULL)) : NULL;
Checking the rest of pp_aelemfast, it's clear that within the fast
path, if (!sv) and (!lval), the function must eventually
PUSHs(&PL_sv_undef). So the fast path might as well do that directly.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There's no efficient way to create a mortal SV of any type other than
SVt_NULL (via sv_newmortal). The options are either to do:
* SV* sv = sv_newmortal; sv_upgrade(sv, SVt_SOMETYPE);
but sv_upgrade is needlessly inefficient on new SVs.
* SV* sv = sv_2mortal(newSV_type(SVt_SOMETYPE)
but this will perform runtime checks to see if (sv) and if (SvIMMORTAL(sv),
and for a new SV we know that those answers will always be yes and no.
This commit adds a new inline function which is basically a mortalizing
wrapper around the now-inlined newSV_type.
|
|
|
|
|
|
|
|
|
|
|
|
| |
When a function outside of sv.c creates a SV via newSV(0):
* There is a call to Perl_newSV
* A SV head is uprooted and its flags set
* A runtime check is made to effectively see if 0 > 0
* The new SV* is returned
Replacing newSV(0) with newSV_type(SVt_NULL) should be more efficient,
because (assuming there are SV heads to uproot), the only step is:
* A SV head is uprooted and its flags set
|
|
|
|
|
|
|
|
|
|
| |
In a few places, SVs can be created more efficiently or new SVs
can be assigned to more efficiently. Small changes included:
* Use sv_setpvn_fresh instead of sv_setpvn
* Use sv_mortalcopy_flags instead of sv_newmortal + sv_setsv_flags
* newSVsv_flags instead of newSV + sv_setsv_flags
* sv_newmortal instead of sv_2mortal(newSV(0))
* Remove a SvGROW(sv, 257) following a newSV(257)
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Move some other variable declarations into a tighter scope, and initialise
variables at the point of declaration where possible.
With the recent changes, the function consists of a 4-way switch inside a
loop, where each iteration of the loop will take the same case in the
switch. This implies a branch taken on each iteration of the loop, which
is less efficient than the alternative structure of taking the branch once
and then looping.
However, the way the code is structured (particularly how two of the cases
share code, by jumping sideways), means that rewriting it to "switch first"
structure would not be clearer (and likely would also be hard to get
right). Hence it seems better to let a compiler optimiser choose what is
best. However, it might not realise that CxTYPE(cx) won't be changed, even
as a side effect of any function called by this code. Hence hoist it into a
constant variable to make this unequivocal.
|
|
|
|
|
| |
This commit provides the runtime changes needed to iterate for loops over
two or more variables.
|
|
|
|
|
|
|
| |
Add braces and indent a block that will become a `for` loop in the next
commit. With the exception of these and merging 3 opening braces onto the
`if` or `else` on the previous lines, this commit is purely a whitespace
change.
|
| |
|
|
|
|
|
| |
Otherwise it will return wrong results, unless other code happens to
have iterated over %ENV. This bug has probably existed forever.
|
|
|
|
|
|
|
|
|
|
|
| |
These are identified as being static shared COW strings whose string
buffer points directly at PL_Yes / PL_No
Define sv_setbool() and sv_setbool_mg() macros
Use sv_setbool() where appropriate
Have sv_dump() annotate when an SV's PV buffer is one of the PL_(Yes|No) special booleans
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The code that handled hashes and arrays was removed by commit 2517717a8902:
The cases for SVt_PVAV and SVt_PVHV in pp_defined are unreachable.
Remove them, and hit to the C compiler that it's unlikely that someone used
`defined` on a subroutine.
These have been unreachable since `defined @array` and `defined %hash`
became syntax errors. Whilst the same PP code is used for // and //=,
expressions such as`@a // @b` put the left array (or hash) in scalar
context, meaning that it always returns a define value.
(Should we warn on these?)
However, it turns out that that the removed code was reachable by XS code
generating data structures that would be "illegal" in pure Perl (eg also
triggering "Bizarre copy of ..." errors). Hence with -DDEBUGGING, add logic
to report problematic cases, instead of silently continuing with changed
behaviour.
|
|
|
|
|
|
| |
We know how many pairs of keys/values are on the stack, so pre-extend the
hash to the appropriate size, instead of letting the hash needlessly re-size
one or more times during the assignment loop.
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Remove them, and hit to the C compiler that it's unlikely that someone used
`defined` on a subroutine.
These have been unreachable since `defined @array` and `defined %hash`
became syntax errors. Whilst the same PP code is used for // and //=,
expressions such as`@a // @b` put the left array (or hash) in scalar
context, meaning that it always returns a define value.
(Should we warn on these?)
|
| |
|
|
|
|
| |
AvREIFY_only() is about to be applied
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
This just detabifies to get rid of the mixed tab/space indentation.
Applying consistent indentation and dealing with other tabs are another issue.
Done with `expand -i`.
* vutil.* left alone, it's part of version.
* Left regen managed files alone for now.
|
|
|
|
|
|
|
|
| |
Remove a bit of a hack done by me 2 years ago to shut up a compiler warning
which did a cast to RW of a constant string.
Since the field which the const string is assigned to is never modified,
just make that field const instead.
|
|
|
|
|
|
|
| |
I was never happy with this short form, and other people weren't either.
Now that most things are better expressed in terms of av_count, convert
the few remaining items that are clearer when referring to an index into
using the fully spelled out form
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
GH #16685
In
@a = ($x, undef, undef) = (1))
@a should have 3 elements. v5.25.6-79-gb09ed995ad broke this and was
returning one element.
The fix is simple: that previous commit made it so that elements were
pushed back onto the stack only if they weren't immortal, so
&PL_sv_undef was getting skipped. Make it so they always are.
|
| |
|
|
|
|
|
| |
It only does anything under PERL_GLOBAL_STRUCT, which is gone.
Keep the dNOOP defintion for CPAN back-compat
|
|
|
|
|
| |
Mostly in comments and docs, but some in diagnostic messages and one
case of 'or die die'.
|
|
|
|
|
|
|
|
| |
This fixes #17612
This adds an inline function to pp_hot to be called to determine if
debugging info should be output or not, regardless of whether it comes
from -Dr, or from a 'use re Debug' statement
|
|
|
|
| |
This makes things easier to read.
|