summaryrefslogtreecommitdiff
path: root/pp_hot.c
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Perl_leave_adjust_stacks: don't make mortal copies of SvIMMORTAL SVs"Tony Cook2023-05-121-7/+0
| | | | | | | | This reverts commit c56d7fa9134de66efe85a2fd70b28069c2629e0d. Also un-TODO's the new test for this issue. Fixes #21044
* Remove duplicate "the" in commentsElvin Aslanov2023-05-031-1/+1
| | | | Fix spelling on various files pertaining to core Perl.
* Fix some typos in commentsmauke2023-03-111-14/+10
|
* add code comments concerning grep and map markstack usageDavid Mitchell2023-02-281-0/+51
|
* simplify scope-exit empty scalar contextDavid Mitchell2023-02-281-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* pp_hot.c - rework padhv_rv2hv_common fix maybe-uninit warning on gcc 12Yves Orton2023-02-191-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Perl_leave_adjust_stacks: don't make mortal copies of SvIMMORTAL SVsRichard Leach2023-02-131-0/+7
| | | | | | 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.
* pp_hot.c - fix branch reset matches in list contextYves Orton2023-01-271-22/+78
| | | | | | | | | | | | | | 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.
* pp_multiconcat: don't set svpv_p to an invalid pointerTony Cook2023-01-171-2/+3
| | | | | | | | | | | | | | | | | | | | | 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.
* regexec engine - wrap and replace RX_OFFS() with better abstractionsYves Orton2023-01-111-20/+16
| | | | | | | | | | | | | | | | 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.
* Extract minimum PV buffer/AV element size to common definitionsRichard Leach2022-11-211-1/+2
| | | | | | | | | | | | | | | | | 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.)
* AELEMFASTLEX_STORE - support negative keys, skip unnecessary checkRichard Leach2022-10-221-9/+9
| | | | | | | | 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.
* OP_AELEMFASTLEX_STORE - combined sassign/aelemfast_lexRichard Leach2022-09-071-0/+50
| | | | | | | | | | | | | | | | | | | | | | 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.
* only clear the stream error state in readline() for glob()Tony Cook2022-08-311-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Implement OP_PADSV_STORE - combined sassign/padsv OPRichard Leach2022-08-171-0/+42
| | | | | | | | | | | | | | | | | | | | | 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.
* assert() in pp_gv and pp_gvsv that the GV really is a GVPaul "LeoNerd" Evans2022-08-031-0/+4
| | | | Or, in pp_gv it's also allowed to be a reference to a CV
* Define the remaining convenience cMETHOP* macrosPaul "LeoNerd" Evans2022-08-031-8/+8
| | | | | | | | | | | 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.
* pp_subst: optimize by not calling utf8_lengthLoren Merritt2022-07-201-5/+6
| | | | Length just isn't needed, and often took more cpu-time than the actual regex.
* s/JUMPENV/JMPENV/gDavid Mitchell2022-06-201-1/+1
| | | | | | 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.
* pp_aelemfast: include fast return for non-lvalsRichard Leach2022-06-151-0/+3
| | | | | | | | | | | | | 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.
* perl.c, pp_hot.c: Fix typos in commentsKarl Williamson2022-05-191-1/+1
|
* Perl_newSV_type_mortal - new inline function introduced and usedRichard Leach2022-03-071-6/+4
| | | | | | | | | | | | | | | 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.
* Inlined newSV_type(SVt_NULL) leaner than non-inlined newSV(0)Richard Leach2022-03-071-2/+2
| | | | | | | | | | | | 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
* Misc microoptimizations when dealing with new SVsRichard Leach2021-12-041-14/+7
| | | | | | | | | | 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)
* pp_match: newSVpvn_flags now more efficient than sv_newmortal + sv_setpvn.Richard Leach2021-11-011-4/+7
|
* Note why this if block in pp_iter is emptyNicholas Clark2021-10-151-0/+5
|
* Move reading CxTYPE(cx) out of the loop, to be clear that it doesn't change.Nicholas Clark2021-10-151-11/+10
| | | | | | | | | | | | | | | | | | | 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.
* Iterate for loops $n-at-a-time in PP_ITER.Nicholas Clark2021-10-151-15/+77
| | | | | This commit provides the runtime changes needed to iterate for loops over two or more variables.
* Re-indent the case statement in pp_iter, ready for the next commit.Nicholas Clark2021-10-151-131/+129
| | | | | | | 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.
* pp_match: remove is_utf8_string check, used by removed (v5.24) \C char classRichard Leach2021-10-131-1/+1
|
* On VMS, %ENV in scalar context must call prime_env_iter()Nicholas Clark2021-09-121-0/+13
| | | | | Otherwise it will return wrong results, unless other code happens to have iterated over %ENV. This bug has probably existed forever.
* Add SvIsBOOL() macro to test for SVs being boolean-intentPaul "LeoNerd" Evans2021-09-101-1/+1
| | | | | | | | | | | 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
* In pp_defined assert that the SV is not a hash or array.Nicholas Clark2021-09-081-0/+9
| | | | | | | | | | | | | | | | | | | | 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.
* Pre-extend hashes in list assignment before assigning to them.Nicholas Clark2021-08-231-0/+5
| | | | | | 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.
* pp_defined: modify OP_DEFINED paths to use TOPs and RETSETsRichard Leach2021-08-171-8/+5
|
* The cases for SVt_PVAV and SVt_PVHV in pp_defined are unreachable.Nicholas Clark2021-07-261-13/+3
| | | | | | | | | | | 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?)
* Rename G_ARRAY to G_LIST; provide back-compat when not(PERL_CORE)Paul "LeoNerd" Evans2021-06-021-15/+15
|
* Perl_clear_defarray - array does not actually need ZeroingRichard Leach2021-05-261-1/+1
| | | | AvREIFY_only() is about to be applied
* Perl_clear_defarray: faster array creation via new macro+functionRichard Leach2021-05-261-4/+3
|
* Remove a double negative from a comment, clarifying that this is the default.Nicholas Clark2021-04-241-2/+2
|
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-1262/+1262
| | | | | | | | | | | 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.
* pp_multiconcat(): tweak a constDavid Mitchell2020-08-281-2/+2
| | | | | | | | 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.
* Use av_top_index() instead of av_tindex()Karl Williamson2020-08-191-2/+2
| | | | | | | 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
* pp_hot.c: Convert to use av_count()Karl Williamson2020-08-191-1/+1
|
* list assign in list context: honour LHS undefDavid Mitchell2020-08-111-1/+1
| | | | | | | | | | | | | | | 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.
* pp.c/pp_hot.c - add NV<->NV case to numerical comparison opsRichard Leach2020-07-301-3/+9
|
* Remove use of dVAR in coreDagfinn Ilmari Mannsåker2020-07-201-3/+1
| | | | | It only does anything under PERL_GLOBAL_STRUCT, which is gone. Keep the dNOOP defintion for CPAN back-compat
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-2/+2
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* pp_match(): output regex debugging infoKarl Williamson2020-03-181-3/+49
| | | | | | | | 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
* pp_match: Use 'z' length modifier to format sizesKarl Williamson2020-03-181-3/+3
| | | | This makes things easier to read.