diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-07-23 15:56:04 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-07-23 15:56:04 +0000 |
commit | 59af01353dbbede40ae5b5d1b0330b847ffb82dc (patch) | |
tree | 35d80e0b0eafdd89028fd3a511661fbcce085826 | |
parent | 76cd736e66383afee2dc798500e6d884d1cd0922 (diff) | |
download | perl-59af01353dbbede40ae5b5d1b0330b847ffb82dc.tar.gz |
avoid useless use of target for pp_each(); also fixes bugs due to
refcount held by the target
p4raw-id: //depot/perl@3727
-rw-r--r-- | opcode.h | 2 | ||||
-rwxr-xr-x | opcode.pl | 2 | ||||
-rw-r--r-- | pp.c | 9 | ||||
-rwxr-xr-x | t/op/each.t | 17 |
4 files changed, 21 insertions, 9 deletions
@@ -1923,7 +1923,7 @@ EXT U32 PL_opargs[] = { 0x00026e04, /* aelemfast */ 0x00026404, /* aelem */ 0x00046801, /* aslice */ - 0x00009608, /* each */ + 0x00009600, /* each */ 0x00009608, /* values */ 0x00009608, /* keys */ 0x00003600, /* delete */ @@ -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 @@ -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 9063c2c3ed..879c0d0fd3 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"; +} + |