summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-07-23 15:56:04 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-07-23 15:56:04 +0000
commit59af01353dbbede40ae5b5d1b0330b847ffb82dc (patch)
tree35d80e0b0eafdd89028fd3a511661fbcce085826
parent76cd736e66383afee2dc798500e6d884d1cd0922 (diff)
downloadperl-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.h2
-rwxr-xr-xopcode.pl2
-rw-r--r--pp.c9
-rwxr-xr-xt/op/each.t17
4 files changed, 21 insertions, 9 deletions
diff --git a/opcode.h b/opcode.h
index ab279becb2..629eef45f1 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 56d8342a16..8f480d6ee0 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 3bd26f4cc9..c7fd585d54 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 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";
+}
+