From: Yitzchak Scott-Thoennes Date: Mon, 4 Mar 2002 16:24:32 +0000 (-0800) Subject: Re: [PATCH] Re: [ID 20000922.001] Implicit comparison to $. not performed before... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e3399f9b267135d193509ba5240514af04e9fec;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] Re: [ID 20000922.001] Implicit comparison to $. not performed before filehandle read Message-ID: p4raw-id: //depot/perl@15054 --- diff --git a/op.h b/op.h index 604eaa3..1cbacb3 100644 --- a/op.h +++ b/op.h @@ -105,6 +105,7 @@ Deprecated. Use C instead. /* On pushre, re is /\s+/ imp. by split " " */ /* On regcomp, "use re 'eval'" was in scope */ /* On OP_READLINE, was <$filehandle> */ + /* On RV2[SG]V, don't create GV--in defined()*/ /* old names; don't use in new code, but don't break them, either */ #define OPf_LIST OPf_WANT_LIST diff --git a/pp_ctl.c b/pp_ctl.c index eb13949..81a96de 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -896,13 +896,16 @@ PP(pp_flip) else { dTOPss; SV *targ = PAD_SV(PL_op->op_targ); - int flip; + int flip = 0; if (PL_op->op_private & OPpFLIP_LINENUM) { - struct io *gp_io; - flip = PL_last_in_gv - && (gp_io = GvIO(PL_last_in_gv)) - && SvIV(sv) == (IV)IoLINES(gp_io); + if (GvIO(PL_last_in_gv)) { + flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)); + } + else { + GV *gv = gv_fetchpv(".", TRUE, SVt_PV); + if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv)); + } } else { flip = SvTRUE(sv); } @@ -980,11 +983,23 @@ PP(pp_flop) else { dTOPss; SV *targ = PAD_SV(cUNOP->op_first->op_targ); + int flop = 0; sv_inc(targ); - if ((PL_op->op_private & OPpFLIP_LINENUM) - ? (GvIO(PL_last_in_gv) - && SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv))) - : SvTRUE(sv) ) { + + if (PL_op->op_private & OPpFLIP_LINENUM) { + if (GvIO(PL_last_in_gv)) { + flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)); + } + else { + GV *gv = gv_fetchpv(".", TRUE, SVt_PV); + if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv)); + } + } + else { + flop = SvTRUE(sv); + } + + if (flop) { sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0); sv_catpv(targ, "E0"); } diff --git a/t/op/flip.t b/t/op/flip.t index d9fa736..70666ac 100755 --- a/t/op/flip.t +++ b/t/op/flip.t @@ -4,7 +4,7 @@ chdir 't' if -d 't'; -print "1..10\n"; +print "1..15\n"; @a = (1,2,3,4,5,6,7,8,9,10,11,12); @@ -19,6 +19,9 @@ if ($y eq '12E0123E0') {print "ok 7\n";} else {print "not ok 7\n";} @a = ('a','b','c','d','e','f','g'); +{ +local $.; + open(of,'harness') or die "Can't open harness: $!"; while () { (3 .. 5) && ($foo .= $_); @@ -34,5 +37,32 @@ if (($x...$x) eq "1") {print "ok 9\n";} else {print "not ok 9\n";} # coredump reported in bug 20001018.008 readline(UNKNOWN); $. = 1; - print "ok 10\n" unless 1 .. 10; + $x = 1..10; + print "ok 10\n"; +} + } + +if (!defined $.) { print "ok 11\n" } else { print "not ok 11 # $.\n" } + +use warnings; +my $warn=''; +$SIG{__WARN__} = sub { $warn .= join '', @_ }; + +if (0..2) { print "ok 12\n" } else { print "not ok 12\n" } + +if ($warn =~ /uninitialized/) { print "ok 13\n" } else { print "not ok 13\n" } +$warn = ''; + +$x = "foo".."bar"; + +if ((() = ($warn =~ /isn't numeric/g)) == 2) { + print "ok 14\n" +} +else { + print "not ok 14\n" +} +$warn = ''; + +$. = 15; +if (15..0) { print "ok 15\n" } else { print "not ok 15\n" }