summaryrefslogtreecommitdiff
path: root/t/op/goto.t
Commit message (Collapse)AuthorAgeFilesLines
* Avoid goto into glob test failure on VMS.Craig A. Berry2018-03-081-3/+5
| | | | | glob() does not return a list on VMS, so joining its result fails expectations for this test.
* Allow goto into glob’s argFather Chrysostomos2018-02-241-1/+3
| | | | | | | | | | | | $ ./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-1/+11
| | | | | 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-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* [perl #130936] Forbid some cases of inward gotoFather Chrysostomos2018-01-081-1/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* permit goto at top level of multicalled subZefram2017-01-231-1/+10
| | | | | | | | | A multicalled sub is reckoned to be a pseudo block, out of which it is not permissible to goto. However, the test for a pseudo block was being applied too early, preventing not just escape from a multicalled sub but also a goto at the top level within the sub. This is a bug similar, but not identical, to [perl #113938]. Now the test is deferred, permitting goto at the sub's top level but still forbidding goto out of it.
* Patch unit tests to explicitly insert "." into @INC when needed.H.Merijn Brand2016-11-111-1/+1
| | | | | require calls now require ./ to be prepended to the file since . is no longer guaranteed to be in @INC.
* t/op/goto.t: tests for RT #45091Dan Collins2016-10-211-1/+28
|
* Use set_up_inc for several unit testsNicolas R2016-08-181-1/+1
| | | | | | | | | | | | | | | Use set_up_inc when require.pl is loaded move plan outside of BEGIN block when no tests are run at BEGIN time. Using set_up_inc allow to run these tests under minitest but also compile them using B::C. This also has the advantage to use a single control point for @INC setup. Note: some tests cannot use 'require test.pl', unshfit is then used for them.
* Tired of looking up old bug numbersFather Chrysostomos2016-07-291-1/+1
| | | | | Some of this is ugly, but that’s because I wrote a one-liner to do it. It’s good enough for practical purposes.
* goto.t: add freeing CV testDavid Mitchell2016-02-031-1/+17
| | | | | This code SEGVed in a cpan/ module while I was messing with pp_goto. Add it to t/op/goto.t so that it can SEGV there instead.
* pp_goto: SvREFCNT_dec(oldcv) *after* undef testDavid Mitchell2016-02-031-1/+25
| | | | | | | | | pp_goto does a LEAVE, then checks that the new CV hasn't been undefed by the LEAVE. If it has, it croaks. Move the decrementing of the old CV's ref count and depth to *after* this check, since the POPSUB done during the croak unwind will do the decrement also. Otherwise the old sub will be doubly freed.
* Add a test for a goto regression from Aug 2010 fixed in Oct 2014.Nicholas Clark2015-09-301-1/+33
| | | | | | | | | | | An obscure bug involving goto within the same scope in the presence of compile-time optimised away blocks was introduced in Aug 2010 by commit ac56e7de46621c6f, "Peephole optimise adjacent pairs of nextstate ops." The bug was fixed in Oct 2014 by commit f5b5c2a37af87535, "Simplify double-nextstate optimisation" Add a test, to ensure that we don't regress.
* t/op/goto.t: Generalize for non-ASCII platformsKarl Williamson2015-03-051-2/+2
|
* Test preamble: unify to dot slash test dot plJarkko Hietaniemi2014-10-081-1/+1
|
* [perl #119949] Stop undef *_, goto &sub from crashingFather Chrysostomos2014-01-181-1/+18
| | | | | | | | Commit 049bd5ffd62b fixed problems with the wrong @_ being visible after *_ modification followed by goto. In so doing, it made it possible for a null to be placed at the start of the target sub’s pad, because it was not checking that the array it got from PL_defgv was actually non-null. Simply adding the check makes everything work.
* Stop &xsub and goto &xsub from crashing on undef *_Father Chrysostomos2013-09-061-1/+8
| | | | | | | | | | | | | | | | $ perl -e 'undef *_; &Internals::V' Segmentation fault: 11 $ perl -e 'sub { undef *_; goto &Internals::V }->()' $ perl5.18.1 -e 'sub { undef *_; goto &Internals::V }->()' Segmentation fault: 11 The goto case is actually a regression from 5.16 (049bd5ffd62), as goto used to ignore changes to *_. (Fixing one bug uncovers another.) We shouldn’t assume that GvAV(PL_defgv) (*_{ARRAY}) gives us anything. While we’re at it, since we have to add extra checks anyway, use them to speed up empty @_ in goto (by checking items, rather than arg).
* Use defelems for (goto) &xsub callsFather Chrysostomos2013-09-061-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before ce0d59f: $ perl -e '++$#_; &utf8::encode' Modification of a read-only value attempted at -e line 1. As of ce0d59f: $ ./perl -Ilib -e '++$#_; &utf8::encode' Assertion failed: (sv), function Perl_sv_utf8_encode, file sv.c, line 3581. Abort trap: 6 Calling sub { utf8::encode($_[0]) } should be more or less equivalent to calling utf8::encode, but it is not in this case: $ ./perl -Ilib -we '++$#_; &{sub { utf8::encode($_[0]) }}' Use of uninitialized value in subroutine entry at -e line 1. In the first two examples above, an implementation detail is leaking through. What you are seeing is not the array element, but a place- holder that indicates an element that has not been assigned to yet. We should use defelem magic so that what the XSUB assigns to will cre- ate an array element (as happens with utf8::encode($_[0])). All of the above applies to goto &xsub as well.
* t/op/goto.t: Provide descriptions for remaining tests lacking them.James E Keenan2012-12-141-8/+8
| | | | | Focus of these descriptions: Simply enable user to more easily locate tests in file.
* pp_goto: Call get-magic before choosing goto typeFather Chrysostomos2012-12-051-1/+7
| | | | | | Deciding whether this is goto-label or goto-sub can only correctly happen after get-magic has been invoked, as get-magic can cause the argument to begin or cease to be a subroutine reference.
* [perl #43077] Make goto &sub leave @_ aloneFather Chrysostomos2012-11-111-2/+17
| | | | | It is a little tricky, as we have to hang on to @_ while unwinding the effects of local @_.
* Produce the right error for goto "\0"Father Chrysostomos2012-05-211-1/+6
| | | | | | | | Since we have supported for embedded nulls in strings, we shouldn’t be using if(*label) to see whether label has a non-zero length. It’s probably not possible to get a null into a label, but we should still say ‘can’t find’ rather than ‘must have’ in that case.
* [perl #111794] Make goto "" like goto ${\""}Father Chrysostomos2012-05-211-1/+8
| | | | | | | | | | | | The logic was written in such a way that goto "" just happened to slip past all the checks and cause pp_goto to return NULL for the next op, which means the end of the program. goto ${\""} dies with ‘goto must have label’, so goto "" should as well. This also adds other tests for that error, which was apparently untested till now.
* Fix for perl #112316: Wrong behavior regarding labels with same prefixBrian Fraser2012-04-061-1/+26
| | | | | | | | The code that compared non UTF-8 labels neglected to check that the label's length was equal before comparing them with a memEQ, which lead to code that used labels with the same prefixes to fail: ./perl -Ilib -E 'CATCH: { CATCHLOOP: { last CATCH; } die }'
* [perl #99850] SEGV when destructor undefs goto &subFather Chrysostomos2011-11-271-1/+12
| | | | | | | | If goto &sub triggers a destructor that undefines &sub, a crash ensues. This commit adds an extra check in pp_goto after the unwinding of the previous sub’s scope.
* Fix recursion warning for ‘no warnings; goto &sub’Father Chrysostomos2011-09-171-1/+5
| | | | | | | | | Commit 309aab3a made goto &foo make the lexical hints of the caller of the sub containing the goto visible when foo is called. CORE subs need this to function properly when ‘goneto’. But in that commit I put the PL_curcop assignment before the recursion check, causing the warning settings of the caller to be used, instead of those at the goto. This commit moves the PL_curcop further down in pp_goto.
* Under minitest, skip tests in op/g{oto,v}.t that need PerlIO::scalar.Nicholas Clark2011-02-211-6/+9
|
* permit labels to be stackedZefram2010-12-131-1/+31
| | | | | Liberalise label syntax a little more, by allowing multiple adjacent labels with no intervening statements, as in "foo: bar: baz:".
* Replaced 'unlink' with 'unlink_all' in t/op/goto.tBrad Gilbert2010-12-081-1/+1
|
* permit labels to appear before declarationsZefram2010-10-231-1/+75
| | | | | | | | Include <label> in productions before <decl> and <package_block>. This means that labels can now appear at the beginning of all statement-like things. There was no technical reason for the restriction of labels to substantive statements, and that restriction in any case couldn't be applied to PLUGSTMT-based plugged-in declarations.
* Peephole optimise adjacent pairs of nextstate ops.Nicholas Clark2010-08-271-1/+7
| | | | | | | | | | | | | | | | | | | | | Previously, in code such as use constant DEBUG=>0; sub GAK { warn if DEBUG; print "stuff\n"; } the ops for C<warn if DEBUG;> would be folded to a null op (ex-const), but the nextstate op would remain, resulting in a runtime op dispatch of nextstate, nextstate, ... The execution of a sequence of nexstate ops is indistinguishable from just the last nextstate op, so teach the peephole optimiser to eliminate the first of a pair of nextstate ops. (Except where the first carries a label, as labels mustn't be eliminated by the optimiser, and label usage isn't conclusively known at compile time.)
* Fix RT #74290 - regression for labels immediately before string evals.Nicholas Clark2010-04-171-1/+10
| | | | | | Fix location identified by Father Chrysostomos, who also offered a patch, but this patch is more efficient, as it avoids any allocation. Test code based on his test example.
* deprecate "goto" to jump into a constructGerard Goossen2009-11-211-3/+18
|
* Mark all .t and .pm files as non executableRafael Garcia-Suarez2009-06-061-0/+0
|
* Use test.pl's tempfile().Nicholas Clark2008-08-071-3/+3
| | | p4raw-id: //depot/perl@34180
* Fix up change 31494Jerry D. Hedden2007-06-291-2/+1
| | | | | | From: "Jerry D. Hedden" <jdhedden@cpan.org> Message-ID: <1ff86f510706290902k57b540a5n446fad22c1afdab0@mail.gmail.com> p4raw-id: //depot/perl@31504
* Add a TODO test cases RT# 43403.Steve Peters2007-06-281-1/+15
| | | p4raw-id: //depot/perl@31494
* Two test workarounds for VMSCraig A. Berry2005-12-181-4/+4
| | | p4raw-id: //depot/perl@26396
* $SIG{__WARN__} = sub { goto &foo } could recurse infinitelyDave Mitchell2005-07-171-1/+11
| | | p4raw-id: //depot/perl@25160
* disallow eval { goto &foo }Dave Mitchell2005-05-211-1/+8
| | | | | | | | eval 'goto &foo' is already banned, and the try-version usually coredumps due to the code assuming the CxEVAL is actually a CxSUB. Anyway exiting an eval but preserving "it's" @_ doesn't make much sense. p4raw-id: //depot/perl@24532
* Fix test numerotationRafael Garcia-Suarez2005-05-041-2/+2
| | | p4raw-id: //depot/perl@24386
* make goto.t use test.pl, strict and warningsDave Mitchell2005-05-041-116/+107
| | | p4raw-id: //depot/perl@24385
* [perl #35214] SEGV when next is followed by a gotoDave Mitchell2005-05-041-1/+23
| | | | | next and redo didn't restore PL_curcop p4raw-id: //depot/perl@24384
* [perl #32039] Chained goto &sub drops data too early.Dave Mitchell2004-10-231-1/+9
| | | | | | | Change 22373 to stop a memory leak in goto &foo intead caused the elements of @_ to be freed too early. This revised fix just transfers the reifiedness of the old @_ to the new @_ p4raw-id: //depot/perl@23418
* make pp_goto() cope potential stack reallocation in EXTENDDave Mitchell2004-08-141-1/+16
| | | | | | The code for goto &foo had local pointers to the stack that pointed to the wrong place after a realloc. p4raw-id: //depot/perl@23217
* Re: 2 patches: goto.t, B.pm/xsJim Cromie2004-08-101-21/+124
| | | | | Message-ID: <4118CDA4.3060700@divsol.com> p4raw-id: //depot/perl@23213
* [perl #29708] Problem with autouse (causing Perl to crash)Dave Mitchell2004-05-301-1/+14
| | | | | @_ sometimes wasn't getting created right p4raw-id: //depot/perl@22870
* Fix bug #24108: Goto +foo brokenRafael Garcia-Suarez2003-10-081-1/+9
| | | | | the fix having been suggested by xmath via Juerd. p4raw-id: //depot/perl@21425
* Re: [perl #22299] goto doesn't find labelDave Mitchell2003-05-261-1/+26
| | | | | | | | | | | Date: Sat, 24 May 2003 12:25:17 +0100 Message-ID: <20030524112517.GA11761@fdgroup.com> Subject: [PATCH] Re: [perl #22299] goto doesn't find label From: Dave Mitchell <davem@fdgroup.com> Date: Mon, 26 May 2003 13:47:11 +0100 Message-ID: <20030526124710.GA17670@fdgroup.com> p4raw-id: //depot/perl@19625
* [PATCH #2] Re: [perl #22181] goto undefines my() variablesDave Mitchell2003-05-241-1/+12
| | | | | | | | | | | Date: Thu, 22 May 2003 10:13:19 +0100 Message-ID: <20030522091319.GA4568@fdgroup.com> Subject: Re: [PATCH #2] Re: [perl #22181] goto undefines my() variables From: Dave Mitchell <davem@fdgroup.com> Date: Fri, 23 May 2003 17:09:44 +0100 Message-ID: <20030523160944.GC9194@fdgroup.com> p4raw-id: //depot/perl@19610