summaryrefslogtreecommitdiff
path: root/pp_ctl.c
Commit message (Collapse)AuthorAgeFilesLines
* Misc microoptimizations when dealing with new SVsRichard Leach2021-12-041-1/+1
| | | | | | | | | | 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)
* Quote the word "defer" in exception messages about control flowPaul "LeoNerd" Evans2021-11-241-5/+5
|
* Forbid using 'goto' to jump into a 'defer' block because everything will ↵Paul "LeoNerd" Evans2021-11-231-1/+4
| | | | break when it's done
* Create `defer` syntax and `OP_PUSHDEFER` opcodePaul "LeoNerd" Evans2021-08-251-1/+67
| | | | | | | | | | | | | | | Adds syntax `defer { BLOCK }` to create a deferred block; code that is deferred until the scope exits. This syntax is guarded by use feature 'defer'; Adds a new opcode, `OP_PUSHDEFER`, which is a LOGOP whose `op_other` field gives the start of an optree to be deferred until scope exit. That op pointer will be stored on the save stack and invoked as part of scope unwind. Included is support for `B::Deparse` to deparse the optree back into syntax.
* Where the key is an SV, replace some hv_* calls with hv_*_ent equivalents.Nicholas Clark2021-07-261-4/+2
| | | | | This avoids the SvUTF8(tmpstr) ? -(I32)SvCUR(tmpstr) : (I32)SvCUR(tmpstr) code dance.
* Rename G_ARRAY to G_LIST; provide back-compat when not(PERL_CORE)Paul "LeoNerd" Evans2021-06-021-15/+15
|
* Add a comment where people might look for pp_grepwhile() to point out it ↵Paul "LeoNerd" Evans2021-04-081-0/+2
| | | | lives in pp_hot.c, not next to its sibling functions in pp_ctl.c
* try isn't treated as a sub call like eval isTony Cook2021-02-141-11/+1
| | | | | | | | | | | | | The try change added code to pp_return to skip past try contexts when looking for the sub/sort/eval context to return from. This was only needed because cx_pusheval() sets si_cxsubix to the current frame and try uses that function to push it's context, that value is then used by the dopopto_cursub() macro to shortcut walking the context stack. Since we don't need to treat try as a sub for return, list vs array checks or lvalue sub checks, don't set si_cxsubix on try.
* A totally new optree structure for try/catch involving three new optypesPaul "LeoNerd" Evans2021-02-141-22/+44
|
* [gh18540] Don't read before start of context stack in pp_return()Hugo van der Sanden2021-02-081-5/+7
| | | | Add a guard to the chunk introduced by a1325b902d for "try" support.
* Initial attempt at feature 'try'Paul "LeoNerd" Evans2021-02-041-5/+61
| | | | | | | | | * Add feature, experimental warning, keyword * Basic parsing * Basic implementation as optree fragment See also https://github.com/Perl/perl5/issues/18504
* Rename CxTRYBLOCK() to CxEVALBLOCK()Paul "LeoNerd" Evans2021-02-041-4/+4
| | | | | | CxTRYBLOCK would be confusing when we add a real CxTRY for try/catch Also renames the associated CXp_TRYBLOCK flag to CXp_EVALBLOCK
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-2639/+2639
| | | | | | | | | | | 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.
* Slience compiler warnings for NV, [IU]V compareKarl Williamson2020-11-221-1/+1
| | | | | | | | | | | | | | These were occurring on FreeBSD smokes. warning: implicit conversion from 'IV' (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion] 9223372036854775807 is IV_MAX. What needed to be done here was to use the NV containing IV_MAX+1, a value that already exists in perl.h In other instances, simply casting to an NV before doing the comparison with the NV was what was needed. This fixes #18328
* autodoc.pl: Enhance apidoc_section featureKarl Williamson2020-11-061-1/+1
| | | | | | | | | | | This feature allows documentation destined for perlapi or perlintern to be split into sections of related functions, no matter where the documentation source is. Prior to this commit the line had to contain the exact text of the title of the section. Now it can be a $variable name that autodoc.pl expands to the title. It still has to be an exact match for the variable in autodoc, but now, the expanded text can be changed in autodoc alone, without other files needing to be updated at the same time.
* Non-Configure code required to implement a strict by default optionTodd Rinaldo2020-09-151-1/+1
|
* Reorganize perlapiKarl Williamson2020-09-041-1/+1
| | | | | This uses a new organization of sections that I came up with. I asked for comments on p5p, but there were none.
* die_unwind(): global destructionNicolas R2020-08-211-1/+5
| | | | | | | | | | Fix #18063 During global destruction make sure we preserve the string by using mortalcopy. This is an update on 8c86f0238ecb5f32c2e7fba36e3edfdb54069068 change which avoided sv_mortalcopy in favor of sv_2mortal.
* pp_ctl.c: Convert to use av_count()Karl Williamson2020-08-191-23/+23
|
* Remove use of dVAR in coreDagfinn Ilmari Mannsåker2020-07-201-3/+3
| | | | | It only does anything under PERL_GLOBAL_STRUCT, which is gone. Keep the dNOOP defintion for CPAN back-compat
* Remove Symbian portDagfinn Ilmari Mannsåker2020-07-201-12/+0
| | | | | Also eliminate USE_HEAP_INSTEAD_OF_STACK and SETSOCKOPT_OPTION_VALUE_T, since Symbian was the only user of those.
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-3/+3
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* always treat undef in %INC as a failed requireTony Cook2020-01-271-2/+5
| | | | | | | | | | | Previously require would check for the specific \&PL_sv_undef SV in %INC, this meant that if %INC was copied, or undef assigned to a member the entry would erroneously be treated as if a previous require of that file was successful. So check for SvOK() instead, with appropriate magic tests. fixes #17428
* clean up quadmath_format_*() functionsTony Cook2019-11-161-6/+3
| | | | | | | | | | | This includes: - remove them from the API - simplify quadmath_format_single()'s interface, and rename it to match the new interface fixes #17288
* Faster feature checksTony Cook2019-10-301-0/+3
| | | | | | | | | | | | | | | Perform only a bit check instead of a much more expensive hash lookup to test features. For now I've just added a U32 to the cop structure to store the bits, if we need more we could either add more bits directly, or make it a pointer. We don't have the immediate need for a pointer that warning do since we don't dynamically add new features during compilation/runtime. The changes to %^H are retained so that caller() can be used from perl code to check the features enabled at a given caller's scope.
* si_cxsubix not restored on goto &XS_subDavid Mitchell2019-09-231-0/+3
| | | | | | | My recent merge commit v5.31.3-198-gd2cd363728 (temporarily reverted by v5.31.4-0-g20ef288c53) added a si_cxsubix field to the stackinfo struct to track the most recent sub context. This field wasn't being restored correctly with 'goto &XS-sub', and broke Test::Deep.
* Un-revert "[MERGE] add+use si_cxsubix field"David Mitchell2019-09-231-6/+13
| | | | | | | | original merge commit: v5.31.3-198-gd2cd363728 reverted by: v5.31.4-0-g20ef288c53 The commit following this commit fixes the breakage, which that means the revert can be undone.
* Revert "[MERGE] add+use PL_curstackinfo->si_cxsubix field"v5.31.4Max Maischein2019-09-201-13/+6
| | | | | | | | | | | | This reverts commit d2cd363728088adada85312725ac9d96c29659be, reversing changes made to 068b48acd4bdf9e7c69b87f4ba838bdff035053c. This change breaks installing Test::Deep: ... not ok 37 - Test 'isa eq' completed ok 38 - Test 'isa eq' no premature diagnostication ...
* add Perl_gimme_V() static inline fn for GIMME_VDavid Mitchell2019-09-191-0/+2
| | | | | | This function makes use of PL_curstackinfo->si_cxsubix to avoid the overhead of a call to block_gimme() when the context of the op is unknown.
* add PL_curstackinfo->si_cxsubix fieldDavid Mitchell2019-09-191-1/+5
| | | | | | | | | | | | | This tracks the most recent sub/eval/format context pushed onto the context stack. Then make dopopto_cursub use it. The previous value is saved in the cxt struct, and is restored whenever the context is popped. This adds a tiny overhead for every sub call, but speeds up other operations, such as determining the caller context when returning a value from a sub - this has to be dpne for every sub call where the last expression is context sensitive, so its often a win.
* add dopopto_cursub() macro to pp_ctl.cDavid Mitchell2019-09-191-6/+7
| | | | short for dopoptosub(cxstack_ix), a common idiom in that file.
* Avoid panic when last s///g is tainted and utf8David Mitchell2019-09-141-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | RT #134409 In a repeated substitution, where the replacement is an expression, and when the last replacement value is both tainted and utf8, and everything earlier has been plain, and the final string is suitably shorter than the original, a panic resulted: sv_pos_b2u: bad byte offset, blen=1, byte=6 This is because when at the end, taint magic is being being added to the target of the s///, the target SV has already had its buffer updated with the shorter result string, but still has the pos() magic set which corresponded to the original longer string (this pos value would, in the normal flow of things, be reset shortly afterwards). One quirk of sv_magic(), which adds any sort of magic including taint magic, is that it always checks for the presence of pos() magic, and if so, converts the byte to utf8 offset if necessary. This was seeing the invalid pos() offset and panicing. The check was added by v5.19.3-111-g25fdce4a16: "Stop pos() from being confused by changing utf8ness" It seems like a bit of hack to recalibrate pos() each time sv_magic() is called, but I've left that alone (sleeping dogs and all that) and instead added a hack in the taint code path in pp_substcont to reset pos before setting taint.
* (perl #134266) make sure $@ is writable when we write to itTony Cook2019-08-081-2/+8
| | | | | | | | when unwinding. Since except_sv might be ERRSV we try to preserve it's value, if not the actual SV (which we have an extra refcount on if it is except_sv).
* (perl #133695) "0".."-1" should act like 0..-1Hauke D2019-08-081-3/+7
| | | | | | | | | | | | | | | | | | Previously, *any* string beginning with 0, including the string "0" itself, would be subject to the magic string auto-increment, instead of being treated like a number. This meant that "-2".."-1" was the same as -2..-1 and "1".."-1" was the same as 1..-1, but "0".."-1" was the same as "0".."99". This patch fixes that inconsistency, while still allowing ranges like "01".."31" to produce the strings "01", "02", ... "31", which is what the "begins with 0" exception was intended for. This patch also expands the documentation in perlop and states the rules for the range operator in list context with both operands being strings more explicitly. See also #18165 and #18114.
* pp_ctl.c: Use safe UTF8SKIPKarl Williamson2019-03-191-1/+2
|
* Use sv_catpvs where appropriate vs sv_catpvKarl Williamson2018-08-061-4/+4
| | | | | This moves calculations definitely to compile time; some optimizing compilers may already do this, but some may not.
* Allow goto into glob’s argFather Chrysostomos2018-02-241-0/+1
| | | | | | | | | | | | $ ./perl -Ilib -Xe 'goto foo; glob do { foo: $1}' Can't "goto" into a binary or list expression at -e line 1. What binary or list expression? True, glob has the *precedence* of a list operator, but so does not: $ ./perl -Ilib -Xe 'goto foo; not do { foo: $1}; prt "ok\n"' ok Glob seems to be the only exception, due to its ‘special’ op tree.
* [perl #132854] Allow goto into first arg of bin opFather Chrysostomos2018-02-231-0/+8
| | | | | This particular case does not risk any stack corruption, and there is a CPAN module depending on it working (PerlX::AsyncAwait).
* [perl #132799] Fix goto within block within exprFather Chrysostomos2018-02-041-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When goto looks for a label, it builds up a list of ops to enter. But it begins its search a little too far out relative to the ‘goto’. Hence, the first op gets skipped. In 6d90e983841, I forbade same cases of inward goto-into-expression to avoid stack corruption and crashes. I did this by pushing a marker on to the list of ops to enter, indicating that an error should be thrown instead. Because goto starts the search too far up the context stack, it would sometimes end up looking inside an expression, which would cause the first op on the entry list to be such a marker, meaning that the next item, which should have been skipped, would not be. That could really screw up the context stack for cases like: my $e = eval { goto label; label: } because the entry list would be: <croak-marker> entertry instead of the previous: entertry Hence, entertry (which enters eval{}) would be executed from *within* the eval, causing the exit of the eval to leave an eval on the context stack. Crashes ensued. This commit fixes it by checking whether we have moved past the begin- ning of the list of entry ops before pushing a croak-marker on to it. Goto’s implementation is really complex, and always has been. It could be greatly simplified now thot ops have parent pointers. But that should wait for another developement cycle.
* Fix goto-into-string-eval under PERL_UNICODEFather Chrysostomos2018-01-121-0/+1
| | | | | | | | | | More precisely, goto-to-jump-into-the-parameter-of-a-string-eval, which is tested in goto.t as of 6d90e98384, but fails as of that commit under PERL_UNICODE, because entereval gets a second kid op (a hintseval op) and ‘looks like’ a list operator, which 6d90e98384 generally forbad. The easiest way to fix this is simply to add another exception.
* [perl #130936] Forbid some cases of inward gotoFather Chrysostomos2018-01-081-6/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit in general forbids entry into the parameter of a binary or list operator, to avoid crashes and stack corruption. In cases like goto f; push @array, do { f: } and goto f; $a + do { f: }; it’s not possible to fix this in general. Cases like goto f; do { f: } + $a; (jumping into the first parameter) have never caused problems, but I went ahead and forbad that usage too, since it would be too compli- cated to figure out exactly which parameter is being jumped into. (It’s not impossible; it would just double the amount of code used to find labels.) List operators taking just a simple list, such as die(), have never worked properly, because goto() bypasses the pushmark. They could be made to work, but that would require extra work to distinguish cases like push and print that have a first operand (sometimes implicit for print) of a specific type. I figured it was easier just to forbid jumping into any list operator. It’s also much easier to document.
* revert smartmatch to 5.27.6 behaviourZefram2017-12-291-46/+643
| | | | | | | | | | | | | The pumpking has determined that the CPAN breakage caused by changing smartmatch [perl #132594] is too great for the smartmatch changes to stay in for 5.28. This reverts most of the merge in commit da4e040f42421764ef069371d77c008e6b801f45. All core behaviour and documentation is reverted. The removal of use of smartmatch from a couple of tests (that aren't testing smartmatch) remains. Customisation of a couple of CPAN modules to make them portable across smartmatch types remains. A small bugfix in scope.c also remains.
* make false whereso yield undef in scalar contextZefram2017-12-231-1/+4
| | | | Fixes [perl #132634].
* pp_ctl.c: Add -D output for inward gotoFather Chrysostomos2017-12-171-0/+2
|
* merge branch zefram/dumb_matchZefram2017-12-171-643/+46
|\
| * internally change "when" to "whereso"Zefram2017-12-051-18/+18
| | | | | | | | | | The names of ops, context types, functions, etc., all change in accordance with the change of keyword.
| * change "when" keyword to "whereso"Zefram2017-12-051-2/+2
| |
| * merge leavegiven op type into leaveloopZefram2017-12-051-26/+1
| | | | | | | | | | The leaveloop op type can already do the whole job, with leavegiven being a near duplicate of it. Replace all uses of leavegiven with leaveloop.
| * make "outside a loop" error messages consistentZefram2017-11-291-1/+1
| | | | | | | | | | | | The message for leaving a "when" block outside a loop had different wording from the message for performing "next" et al outside a loop. Make the "when" message consistent with the existing loop control ones.
| * remove unused CXp_FOR_DEF and OPpITER_DEFZefram2017-11-291-4/+0
| | | | | | | | | | These were used to identify foreach loops that qualify as topicalizers. That's no longer a relevant classification.