From: Gurusamy Sarathy Date: Fri, 23 Jul 1999 15:56:04 +0000 (+0000) Subject: avoid useless use of target for pp_each(); also fixes bugs due to X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=59af01353dbbede40ae5b5d1b0330b847ffb82dc;p=p5sagit%2Fp5-mst-13.2.git avoid useless use of target for pp_each(); also fixes bugs due to refcount held by the target p4raw-id: //depot/perl@3727 --- diff --git a/opcode.h b/opcode.h index ab279be..629eef4 100644 --- a/opcode.h +++ b/opcode.h @@ -1923,7 +1923,7 @@ EXT U32 PL_opargs[] = { 0x00026e04, /* aelemfast */ 0x00026404, /* aelem */ 0x00046801, /* aslice */ - 0x00009608, /* each */ + 0x00009600, /* each */ 0x00009608, /* values */ 0x00009608, /* keys */ 0x00003600, /* delete */ diff --git a/opcode.pl b/opcode.pl index 56d8342..8f480d6 100755 --- a/opcode.pl +++ b/opcode.pl @@ -481,7 +481,7 @@ aslice array slice ck_null m@ A L # Hashes. -each each ck_fun t% H +each each ck_fun % H values values ck_fun t% H keys keys ck_fun t% H delete delete ck_delete % S diff --git a/pp.c b/pp.c index 3bd26f4..c7fd585 100644 --- a/pp.c +++ b/pp.c @@ -2631,7 +2631,7 @@ PP(pp_aslice) PP(pp_each) { - djSP; dTARGET; + djSP; HV *hash = (HV*)POPs; HE *entry; I32 gimme = GIMME_V; @@ -2646,12 +2646,13 @@ PP(pp_each) if (entry) { PUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */ if (gimme == G_ARRAY) { + SV *val; PUTBACK; /* might clobber stack_sp */ - sv_setsv(TARG, realhv ? - hv_iterval(hash, entry) : avhv_iterval((AV*)hash, entry)); + val = realhv ? + hv_iterval(hash, entry) : avhv_iterval((AV*)hash, entry); SPAGAIN; - PUSHs(TARG); + PUSHs(val); } } else if (gimme == G_SCALAR) diff --git a/t/op/each.t b/t/op/each.t index 9063c2c..879c0d0 100755 --- a/t/op/each.t +++ b/t/op/each.t @@ -1,8 +1,6 @@ #!./perl -# $RCSfile: each.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:47 $ - -print "1..16\n"; +print "1..19\n"; $h{'abc'} = 'ABC'; $h{'def'} = 'DEF'; @@ -120,3 +118,16 @@ while (($key, $value) = each(h)) { } } if ($i == 5) { print "ok 16\n" } else { print "not ok\n" } + +{ + package Obj; + sub DESTROY { print "ok 18\n"; } + { + my $h = { A => bless [], __PACKAGE__ }; + while (my($k,$v) = each %$h) { + print "ok 17\n" if $k eq 'A' and ref($v) eq 'Obj'; + } + } + print "ok 19\n"; +} +