From b80b6069675e4e4c5169294fdad71ea1b2b85824 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sat, 24 Mar 2001 14:33:09 +0000 Subject: [PATCH] Re: B::Deparse bug (5.6.0) Message-ID: <20010324143309.B17734@puffinry.freeserve.co.uk> p4raw-id: //depot/perl@9325 --- op.c | 2 -- pp.c | 10 ++++++++++ t/lib/b.t | 7 ++++++- t/op/repeat.t | 15 ++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/op.c b/op.c index 59643e7..87ee1af 100644 --- a/op.c +++ b/op.c @@ -977,8 +977,6 @@ Perl_scalar(pTHX_ OP *o) switch (o->op_type) { case OP_REPEAT: - if (o->op_private & OPpREPEAT_DOLIST) - null(((LISTOP*)cBINOPo->op_first)->op_first); scalar(cBINOPo->op_first); break; case OP_OR: diff --git a/pp.c b/pp.c index 37a4b25..c40efef 100644 --- a/pp.c +++ b/pp.c @@ -1232,6 +1232,16 @@ PP(pp_repeat) (void)SvPOK_only_UTF8(TARG); else (void)SvPOK_only(TARG); + + if (PL_op->op_private & OPpREPEAT_DOLIST) { + /* The parser saw this as a list repeat, and there + are probably several items on the stack. But we're + in scalar context, and there's no pp_list to save us + now. So drop the rest of the items -- robin@kitsite.com + */ + dMARK; + SP = MARK; + } PUSHTARG; } RETURN; diff --git a/t/lib/b.t b/t/lib/b.t index 019a1e8..b10479d 100755 --- a/t/lib/b.t +++ b/t/lib/b.t @@ -15,7 +15,7 @@ use warnings; use strict; use Config; -print "1..17\n"; +print "1..18\n"; my $test = 1; @@ -35,6 +35,11 @@ ok; print "not " if "{\n \$test /= 2 if ++\$test;\n}" ne $deparse->coderef2text(sub {++$test and $test/=2;}); ok; + +print "not " if "{\n -((1, 2) x 2);\n}" ne + $deparse->coderef2text(sub {-((1,2)x2)}); +ok; + { my $a = <<'EOF'; { diff --git a/t/op/repeat.t b/t/op/repeat.t index c030ba9..26f567d 100755 --- a/t/op/repeat.t +++ b/t/op/repeat.t @@ -2,7 +2,7 @@ # $RCSfile: repeat.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:21 $ -print "1..20\n"; +print "1..23\n"; # compile time @@ -96,3 +96,16 @@ print join('', (split(//,"123")) x 2) eq '123123' ? "ok 19\n" : "not ok 19\n"; # jhi@iki.fi # print "\xdd" x 24 eq "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" ? "ok 20\n" : "not ok 20\n"; + +# When we use a list repeat in a scalar context, it behaves like +# a scalar repeat. Make sure that works properly, and doesn't leave +# extraneous values on the stack. +# -- robin@kitsite.com + +my ($x, $y) = scalar ((1,2)x2); +print $x eq "22" ? "ok 21\n" : "not ok 21\n"; +print !defined $y ? "ok 22\n" : "not ok 22\n"; + +# Make sure the stack doesn't get truncated too much - the left +# operand of the eq binop needs to remain! +print (77 eq scalar ((1,7)x2) ? "ok 23\n" : "not ok 23\n"); -- 2.7.4