This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid useless use of target for pp_each(); also fixes bugs due to
authorGurusamy Sarathy <gsar@cpan.org>
Fri, 23 Jul 1999 15:56:04 +0000 (15:56 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Fri, 23 Jul 1999 15:56:04 +0000 (15:56 +0000)
refcount held by the target

p4raw-id: //depot/perl@3727

opcode.h
opcode.pl
pp.c
t/op/each.t

index ab279be..629eef4 100644 (file)
--- 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 */
index 56d8342..8f480d6 100755 (executable)
--- 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 (file)
--- 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)
index 9063c2c..879c0d0 100755 (executable)
@@ -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";
+}
+