Change 34501 by [EMAIL PROTECTED] on 2008/10/17 16:58:16

        Integrate:
        [ 34492]
        Integrate:
        [ 33074]
        In POPLOOP, if CxITERVAR(cx) is non-NULL, then so is itersave, and
        itersave is a less complex expression for the C compiler.
        
        [ 33075]
        Restore the else block accidently eaten by change 33074.
        
        [ 34493]
        Integrate:
        [ 33076]
        As itersave points to the initial CxITERVAR(), and the state of
        SvPADMY() does not change over the duration of the scope, we can
        perform conditional actions at loop push time. For the non-pad case,
        a reference to the initial CxITERVAR() is already held on the scope
        stack thanks to SAVEGENERICSV(*svp); in pp_enteriter. So there is no
        need to save another reference to it in itersave - it's not going away.
        
        [ 34495]
        Integrate:
        [ 33080]
        Investigation reveals that the work of restoring the iterator to the
        pad is shared between POPLOOP, using itersave, and the end of scope
        restore action requested by Perl_save_padsv(). In fact, the only user
        of SAVEt_PADSV is pp_enteriter, and it already provides enough
        information to allow it to perform the sv_2mortal() in POPLOOP.
        So make it do so. Rather than creating a new routine, use the existing
        routine because nothing else (at least nothing else known to Google's
        codesearch) uses it. But rename it just in case something we can't see
        is being naughty and using our private functions - they will get
        link errors against 5.12.
        
        All this means that itersave is now redundant. So remove it.
        This makes struct context 48 bytes on ILP32 platforms with 32bit IVs,
        down from 64 bytes in 5.10. 33% more context stack in the same memory.
        
        [ 33083]
        Subject: [PATCH] util.c: some consting
        From: Steven Schubiger <[EMAIL PROTECTED]>
        Date: Fri, 25 Jan 2008 01:10:52 +0100
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 34171]
        Subject: [PATCH] Tests for [perl #57564] and [perl #24524] Refcounting 
bug
        From: Bram <[EMAIL PROTECTED]>
        Date: Tue, 05 Aug 2008 19:58:00 +0200
        Message-ID: <[EMAIL PROTECTED]>
        
        
        [Modified for maint by
         1: Keeping the old Perl_save_padsv()
         2: Keeping its save type
         3: Not removing itersave from struct block_loop
        
         The seemingly unrelated change 33083 happened to have the update to
         global.sym that I'd missed committing in 33080]
        
        [ 34496]
        Integrate:
        [ 34494]
        Clarify which save types are in mathoms, which aren't used, and which
        still are in use.
        
        [ 34497]
        Fix an (apparent) logic bug for SAVEt_PADSV - whatever happens, the
        POPs must balance the PUSHes.

Affected files ...

... //depot/maint-5.8/perl/cop.h#45 integrate
... //depot/maint-5.8/perl/embed.fnc#249 integrate
... //depot/maint-5.8/perl/embed.h#189 integrate
... //depot/maint-5.8/perl/global.sym#80 integrate
... //depot/maint-5.8/perl/pp_ctl.c#194 integrate
... //depot/maint-5.8/perl/proto.h#240 integrate
... //depot/maint-5.8/perl/scope.c#73 integrate
... //depot/maint-5.8/perl/scope.h#32 integrate
... //depot/maint-5.8/perl/sv.c#392 integrate
... //depot/maint-5.8/perl/t/op/ref.t#15 integrate

Differences ...

==== //depot/maint-5.8/perl/cop.h#45 (text) ====
Index: perl/cop.h
--- perl/cop.h#44~33417~        2008-03-03 07:53:24.000000000 -0800
+++ perl/cop.h  2008-10-17 09:58:16.000000000 -0700
@@ -462,6 +462,9 @@
 #else
     SV **      itervar;
 #endif
+    /* Eliminated in blead by change 33080, but for binary compatibility
+       reasons we can't remove it from the middle of a struct in a maintenance
+       release, so it gets to stay, and be set to NULL.  */
     SV *       itersave;
     SV *       iterlval;
     AV *       iterary;
@@ -479,17 +482,13 @@
         : (SV**)NULL)
 #  define CX_ITERDATA_SET(cx,idata)                                    \
        CX_CURPAD_SAVE(cx->blk_loop);                                   \
-       if ((cx->blk_loop.iterdata = (idata)))                          \
-           cx->blk_loop.itersave = SvREFCNT_inc(*CxITERVAR(cx));       \
-       else                                                            \
-           cx->blk_loop.itersave = NULL;
+       cx->blk_loop.itersave = NULL;                                   \
+       cx->blk_loop.iterdata = (idata);
 #else
 #  define CxITERVAR(c)         ((c)->blk_loop.itervar)
 #  define CX_ITERDATA_SET(cx,ivar)                                     \
-       if ((cx->blk_loop.itervar = (SV**)(ivar)))                      \
-           cx->blk_loop.itersave = SvREFCNT_inc(*CxITERVAR(cx));       \
-       else                                                            \
-           cx->blk_loop.itersave = NULL;
+       cx->blk_loop.itersave = NULL;                                   \
+       cx->blk_loop.itervar = (SV**)(ivar);
 #endif
 #define CxLABEL(c)     (0 + (c)->blk_loop.label)
 #define CxHASARGS(c)   (0 + (c)->blk_sub.hasargs)
@@ -508,16 +507,6 @@
 
 #define POPLOOP(cx)                                                    \
        SvREFCNT_dec(cx->blk_loop.iterlval);                            \
-       if (CxITERVAR(cx)) {                                            \
-            if (SvPADMY(cx->blk_loop.itersave)) {                      \
-               SV ** const s_v_p = CxITERVAR(cx);                      \
-               sv_2mortal(*s_v_p);                                     \
-               *s_v_p = cx->blk_loop.itersave;                         \
-           }                                                           \
-           else {                                                      \
-               SvREFCNT_dec(cx->blk_loop.itersave);                    \
-           }                                                           \
-       }                                                               \
        if (cx->blk_loop.iterary && cx->blk_loop.iterary != PL_curstack)\
            SvREFCNT_dec(cx->blk_loop.iterary);
 

==== //depot/maint-5.8/perl/embed.fnc#249 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#248~34412~   2008-09-23 13:16:51.000000000 -0700
+++ perl/embed.fnc      2008-10-17 09:58:16.000000000 -0700
@@ -738,6 +738,7 @@
 Ap     |void   |save_vptr      |NN void* pptr
 Ap     |void   |save_re_context
 Ap     |void   |save_padsv     |PADOFFSET off
+Ap     |void   |save_padsv_and_mortalize|PADOFFSET off
 Ap     |void   |save_sptr      |NN SV** sptr
 Ap     |SV*    |save_svref     |NN SV** sptr
 #ifdef USE_5005THREADS

==== //depot/maint-5.8/perl/embed.h#189 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#188~33476~     2008-03-11 10:24:08.000000000 -0700
+++ perl/embed.h        2008-10-17 09:58:16.000000000 -0700
@@ -761,6 +761,7 @@
 #define save_vptr              Perl_save_vptr
 #define save_re_context                Perl_save_re_context
 #define save_padsv             Perl_save_padsv
+#define save_padsv_and_mortalize       Perl_save_padsv_and_mortalize
 #define save_sptr              Perl_save_sptr
 #define save_svref             Perl_save_svref
 #ifdef USE_5005THREADS
@@ -2898,6 +2899,7 @@
 #define save_vptr(a)           Perl_save_vptr(aTHX_ a)
 #define save_re_context()      Perl_save_re_context(aTHX)
 #define save_padsv(a)          Perl_save_padsv(aTHX_ a)
+#define save_padsv_and_mortalize(a)    Perl_save_padsv_and_mortalize(aTHX_ a)
 #define save_sptr(a)           Perl_save_sptr(aTHX_ a)
 #define save_svref(a)          Perl_save_svref(aTHX_ a)
 #ifdef USE_5005THREADS

==== //depot/maint-5.8/perl/global.sym#80 (text+w) ====
Index: perl/global.sym
--- perl/global.sym#79~33454~   2008-03-08 15:09:00.000000000 -0800
+++ perl/global.sym     2008-10-17 09:58:16.000000000 -0700
@@ -437,6 +437,7 @@
 Perl_save_vptr
 Perl_save_re_context
 Perl_save_padsv
+Perl_save_padsv_and_mortalize
 Perl_save_sptr
 Perl_save_svref
 Perl_save_threadsv

==== //depot/maint-5.8/perl/pp_ctl.c#194 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#193~34313~    2008-09-07 15:03:35.000000000 -0700
+++ perl/pp_ctl.c       2008-10-17 09:58:16.000000000 -0700
@@ -1696,11 +1696,10 @@
     else
 #endif /* USE_5005THREADS */
     if (PL_op->op_targ) {
+       SAVEPADSVANDMORTALIZE(PL_op->op_targ);
 #ifndef USE_ITHREADS
        svp = &PAD_SVl(PL_op->op_targ);         /* "my" variable */
-       SAVESPTR(*svp);
 #else
-       SAVEPADSV(PL_op->op_targ);
        iterdata = INT2PTR(void*, PL_op->op_targ);
        cxtype |= CXp_PADVAR;
 #endif

==== //depot/maint-5.8/perl/proto.h#240 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#239~34412~     2008-09-23 13:16:51.000000000 -0700
+++ perl/proto.h        2008-10-17 09:58:16.000000000 -0700
@@ -1147,6 +1147,7 @@
 PERL_CALLCONV void     Perl_save_vptr(pTHX_ void* pptr);
 PERL_CALLCONV void     Perl_save_re_context(pTHX);
 PERL_CALLCONV void     Perl_save_padsv(pTHX_ PADOFFSET off);
+PERL_CALLCONV void     Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off);
 PERL_CALLCONV void     Perl_save_sptr(pTHX_ SV** sptr);
 PERL_CALLCONV SV*      Perl_save_svref(pTHX_ SV** sptr);
 #ifdef USE_5005THREADS

==== //depot/maint-5.8/perl/scope.c#73 (text) ====
Index: perl/scope.c
--- perl/scope.c#72~33475~      2008-03-11 10:06:04.000000000 -0700
+++ perl/scope.c        2008-10-17 09:58:16.000000000 -0700
@@ -413,14 +413,14 @@
 }
 
 void
-Perl_save_padsv(pTHX_ PADOFFSET off)
+Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
 {
     SSCHECK(4);
     ASSERT_CURPAD_ACTIVE("save_padsv");
-    SSPUSHPTR(PL_curpad[off]);
+    SSPUSHPTR(SvREFCNT_inc_simple_NN(PL_curpad[off]));
     SSPUSHPTR(PL_comppad);
     SSPUSHLONG((long)off);
-    SSPUSHINT(SAVEt_PADSV);
+    SSPUSHINT(SAVEt_PADSV_AND_MORTALIZE);
 }
 
 SV **
@@ -924,12 +924,18 @@
            else
                PL_curpad = NULL;
            break;
-       case SAVEt_PADSV:
+       case SAVEt_PADSV_AND_MORTALIZE:
            {
                const PADOFFSET off = (PADOFFSET)SSPOPLONG;
+               SV **svp;
                ptr = SSPOPPTR;
-               if (ptr)
-                   AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR;
+               assert (ptr);
+               svp = AvARRAY((PAD*)ptr) + off;
+               /* This mortalizing used to be done by POPLOOP() via itersave.
+                  But as we have all the information here, we can do it here,
+                  save even having to have itersave in the struct.  */
+               sv_2mortal(*svp);
+               *svp = (SV*)SSPOPPTR;
            }
            break;
        case SAVEt_SAVESWITCHSTACK:
@@ -941,16 +947,44 @@
                PL_curstackinfo->si_stack = f;
            }
            break;
-           /* These are only saved in mathoms.c */
+
+           /* This would be a mathom, but Perl_save_svref() calls a static
+              function, S_save_scalar_at(), so has to stay in this file.  */
        case SAVEt_SVREF:                       /* scalar reference */
            value = (SV*)SSPOPPTR;
            ptr = SSPOPPTR;
            av = NULL; /* what to refcnt_dec */
            goto restore_sv;
+
+           /* These are only saved in mathoms.c */
+       case SAVEt_NSTAB:
+           gv = (GV*)SSPOPPTR;
+           (void)sv_clear((SV*)gv);
+           break;
        case SAVEt_LONG:                        /* long reference */
            ptr = SSPOPPTR;
            *(long*)ptr = (long)SSPOPLONG;
            break;
+       case SAVEt_IV:                          /* IV reference */
+           ptr = SSPOPPTR;
+           *(IV*)ptr = (IV)SSPOPIV;
+           break;
+
+           /* This case is rendered redundant by the integration of change
+              33078. See the comment near Perl_save_padsv().  */
+       case SAVEt_PADSV:
+           {
+               const PADOFFSET off = (PADOFFSET)SSPOPLONG;
+               ptr = SSPOPPTR;
+               if (ptr)
+                   AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR;
+               else {
+                 /* Can we ever get here?
+                    POPs must balance PUSHes.  */
+                   (void) SSPOPPTR;
+               }
+           }
+           break;
        case SAVEt_I16:                         /* I16 reference */
            ptr = SSPOPPTR;
            *(I16*)ptr = (I16)SSPOPINT;
@@ -959,14 +993,6 @@
            ptr = SSPOPPTR;
            *(I8*)ptr = (I8)SSPOPINT;
            break;
-       case SAVEt_IV:                          /* IV reference */
-           ptr = SSPOPPTR;
-           *(IV*)ptr = (IV)SSPOPIV;
-           break;
-       case SAVEt_NSTAB:
-           gv = (GV*)SSPOPPTR;
-           (void)sv_clear((SV*)gv);
-           break;
        case SAVEt_DESTRUCTOR:
            ptr = SSPOPPTR;
            (*SSPOPDPTR)(ptr);
@@ -1105,9 +1131,6 @@
                PTR2UV(cx->blk_loop.iterary));
        PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n",
                PTR2UV(CxITERVAR(cx)));
-       if (CxITERVAR(cx))
-           PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n",
-               PTR2UV(cx->blk_loop.itersave));
        PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%"UVxf"\n",
                PTR2UV(cx->blk_loop.iterlval));
        break;
@@ -1143,6 +1166,21 @@
 #endif /* DEBUGGING */
 }
 
+/* This is rendered a mathom by the integration of change 33078. However, until
+   we have versioned mathom logic in mathoms.c, we can't move it there for
+   5.10.1, as other code in production may have linked to it.  */
+
+void
+Perl_save_padsv(pTHX_ PADOFFSET off)
+{
+    SSCHECK(4);
+    ASSERT_CURPAD_ACTIVE("save_padsv");
+    SSPUSHPTR(PL_curpad[off]);
+    SSPUSHPTR(PL_comppad);
+    SSPUSHLONG((long)off);
+    SSPUSHINT(SAVEt_PADSV);
+}
+
 /*
  * Local variables:
  * c-indentation-style: bsd

==== //depot/maint-5.8/perl/scope.h#32 (text) ====
Index: perl/scope.h
--- perl/scope.h#31~33449~      2008-03-06 06:14:52.000000000 -0800
+++ perl/scope.h        2008-10-17 09:58:16.000000000 -0700
@@ -57,6 +57,7 @@
 #  define SAVEt_GP     SAVEt_GP_OLD
 #endif
 #define SAVEt_STACK_CXPOS      44
+#define SAVEt_PADSV_AND_MORTALIZE      46
 
 #ifndef SCOPE_SAVES_SIGNAL_MASK
 #define SCOPE_SAVES_SIGNAL_MASK 0
@@ -130,6 +131,7 @@
 #define SAVEPPTR(s)    save_pptr((char**)&(s))
 #define SAVEVPTR(s)    save_vptr((void*)&(s))
 #define SAVEPADSV(s)   save_padsv(s)
+#define SAVEPADSVANDMORTALIZE(s)       save_padsv_and_mortalize(s)
 #define SAVEFREESV(s)  save_freesv((SV*)(s))
 #define SAVEMORTALIZESV(s)     save_mortalizesv((SV*)(s))
 #define SAVEFREEOP(o)  save_freeop((OP*)(o))

==== //depot/maint-5.8/perl/sv.c#392 (text) ====
Index: perl/sv.c
--- perl/sv.c#391~34489~        2008-10-15 07:37:39.000000000 -0700
+++ perl/sv.c   2008-10-17 09:58:16.000000000 -0700
@@ -9958,8 +9958,6 @@
                ncx->blk_loop.oldcomppad
                    = (PAD*)ptr_table_fetch(PL_ptr_table,
                                            ncx->blk_loop.oldcomppad);
-               ncx->blk_loop.itersave  = sv_dup_inc(ncx->blk_loop.itersave,
-                                                    param);
                ncx->blk_loop.iterlval  = sv_dup_inc(ncx->blk_loop.iterlval,
                                                     param);
                ncx->blk_loop.iterary   = av_dup_inc(ncx->blk_loop.iterary,
@@ -10274,13 +10272,13 @@
            i = POPINT(ss,ix);
            TOPINT(nss,ix) = i;
            break;
-       case SAVEt_PADSV:
+       case SAVEt_PADSV_AND_MORTALIZE:
            longval = (long)POPLONG(ss,ix);
            TOPLONG(nss,ix) = longval;
            ptr = POPPTR(ss,ix);
            TOPPTR(nss,ix) = any_dup(ptr, proto_perl);
            sv = (SV*)POPPTR(ss,ix);
-           TOPPTR(nss,ix) = sv_dup(sv, param);
+           TOPPTR(nss,ix) = sv_dup_inc(sv, param);
            break;
        case SAVEt_BOOL:
            ptr = POPPTR(ss,ix);
@@ -10364,6 +10362,17 @@
                    = pv_dup(old_state->re_state_reg_starttry);
                break;
            }
+       case SAVEt_PADSV:
+           /* Nothing should be using this any more, post the integration of
+              blead change 33080. But keep it, in case something out there is
+              generating these on the scope stack.  */
+           longval = (long)POPLONG(ss,ix);
+           TOPLONG(nss,ix) = longval;
+           ptr = POPPTR(ss,ix);
+           TOPPTR(nss,ix) = any_dup(ptr, proto_perl);
+           sv = (SV*)POPPTR(ss,ix);
+           TOPPTR(nss,ix) = sv_dup(sv, param);
+           break;
        default:
            Perl_croak(aTHX_
                       "panic: ss_dup inconsistency (%"IVdf")", (IV) type);

==== //depot/maint-5.8/perl/t/op/ref.t#15 (xtext) ====
Index: perl/t/op/ref.t
--- perl/t/op/ref.t#14~34293~   2008-09-06 01:58:18.000000000 -0700
+++ perl/t/op/ref.t     2008-10-17 09:58:16.000000000 -0700
@@ -8,7 +8,7 @@
 require 'test.pl';
 use strict qw(refs subs);
 
-plan(175);
+plan(182);
 
 # Test glob operations.
 
@@ -571,6 +571,18 @@
 ok (!eval { $pvbm->() }, 'PVBM is not a CODE ref');
 ok (!eval { $rpvbm->foo }, 'PVBM is not an object');
 
+# bug 24254
+is( runperl(stderr => 1, prog => 'map eval qq(exit),1 for 1'), "");
+is( runperl(stderr => 1, prog => 'eval { for (1) { map { die } 2 } };'), "");
+is( runperl(stderr => 1, prog => 'for (125) { map { exit } (213)}'), "");
+is( runperl(stderr => 1, prog => 'map die,4 for 3'), "Died at -e line 1.\n");
+is( runperl(stderr => 1, prog => 'grep die,4 for 3'), "Died at -e line 1.\n");
+is( runperl(stderr => 1, prog => 'for $a (3) [EMAIL PROTECTED] {die} 4,5}'), 
"Died at -e line 1.\n");
+
+# bug 57564
+is( runperl(stderr => 1, prog => 'my $i;for $i (1) { for $i (2) { } }'), "");
+
+
 # Bit of a hack to make test.pl happy. There are 3 more tests after it leaves.
 $test = curr_test();
 curr_test($test + 3);
End of Patch.

Reply via email to