Change 34495 by [EMAIL PROTECTED] on 2008/10/16 20:45:27
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]
Affected files ...
... //depot/maint-5.10/perl/cop.h#9 integrate
... //depot/maint-5.10/perl/embed.fnc#13 integrate
... //depot/maint-5.10/perl/embed.h#8 integrate
... //depot/maint-5.10/perl/global.sym#3 integrate
... //depot/maint-5.10/perl/pp_ctl.c#21 integrate
... //depot/maint-5.10/perl/proto.h#11 integrate
... //depot/maint-5.10/perl/scope.c#3 integrate
... //depot/maint-5.10/perl/scope.h#3 integrate
... //depot/maint-5.10/perl/sv.c#28 integrate
... //depot/maint-5.10/perl/t/op/ref.t#3 integrate
Differences ...
==== //depot/maint-5.10/perl/cop.h#9 (text) ====
Index: perl/cop.h
--- perl/cop.h#8~34493~ 2008-10-16 11:44:37.000000000 -0700
+++ perl/cop.h 2008-10-16 13:45:27.000000000 -0700
@@ -431,6 +431,9 @@
OP * next_op;
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;
/* (from inspection of source code) for a .. range of strings this is the
current string. */
@@ -465,18 +468,13 @@
: (SV**)NULL)
# define CX_ITERDATA_SET(cx,idata) \
CX_CURPAD_SAVE(cx->blk_loop); \
- if ((cx->blk_loop.iterdata = (idata)) && SvPADMY(*CxITERVAR(cx))) \
- 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)) \
- && SvPADMY(*CxITERVAR(cx))) \
- 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)
@@ -502,12 +500,6 @@
#define POPLOOP(cx) \
SvREFCNT_dec(cx->blk_loop.iterlval); \
- if (cx->blk_loop.itersave) { \
- SV ** const s_v_p = CxITERVAR(cx); \
- assert(SvPADMY(cx->blk_loop.itersave)); \
- sv_2mortal(*s_v_p); \
- *s_v_p = cx->blk_loop.itersave; \
- } \
if (cx->blk_loop.iterary && cx->blk_loop.iterary != PL_curstack)\
SvREFCNT_dec(cx->blk_loop.iterary);
==== //depot/maint-5.10/perl/embed.fnc#13 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#12~34411~ 2008-09-23 13:01:01.000000000 -0700
+++ perl/embed.fnc 2008-10-16 13:45:27.000000000 -0700
@@ -777,6 +777,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
p |OP* |sawparens |NULLOK OP* o
==== //depot/maint-5.10/perl/embed.h#8 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#7~34410~ 2008-09-23 12:31:18.000000000 -0700
+++ perl/embed.h 2008-10-16 13:45:27.000000000 -0700
@@ -784,6 +784,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 PERL_CORE
@@ -3086,6 +3087,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 PERL_CORE
==== //depot/maint-5.10/perl/global.sym#3 (text+w) ====
Index: perl/global.sym
--- perl/global.sym#2~33139~ 2008-01-30 15:19:42.000000000 -0800
+++ perl/global.sym 2008-10-16 13:45:27.000000000 -0700
@@ -464,6 +464,7 @@
Perl_save_vptr
Perl_save_re_context
Perl_save_padsv
+Perl_save_padsv_and_mortalize
Perl_save_sptr
Perl_save_svref
Perl_scan_bin
==== //depot/maint-5.10/perl/pp_ctl.c#21 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#20~34270~ 2008-09-05 05:56:09.000000000 -0700
+++ perl/pp_ctl.c 2008-10-16 13:45:27.000000000 -0700
@@ -1852,11 +1852,10 @@
SAVESETSVFLAGS(PAD_SVl(PL_op->op_targ),
SVs_PADSTALE, SVs_PADSTALE);
}
+ 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.10/perl/proto.h#11 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#10~34411~ 2008-09-23 13:01:01.000000000 -0700
+++ perl/proto.h 2008-10-16 13:45:27.000000000 -0700
@@ -2103,6 +2103,7 @@
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)
__attribute__nonnull__(pTHX_1);
==== //depot/maint-5.10/perl/scope.c#3 (text) ====
Index: perl/scope.c
--- perl/scope.c#2~33157~ 2008-01-31 13:43:37.000000000 -0800
+++ perl/scope.c 2008-10-16 13:45:27.000000000 -0700
@@ -412,15 +412,15 @@
}
void
-Perl_save_padsv(pTHX_ PADOFFSET off)
+Perl_save_padsv_and_mortalize(pTHX_ PADOFFSET off)
{
dVAR;
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);
}
void
@@ -929,12 +929,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:
@@ -965,6 +971,20 @@
ptr = SSPOPPTR;
*(long*)ptr = (long)SSPOPLONG;
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 {
+ /* Bug, surely? We need to balance the push with a pop here.
+ */
+ }
+ }
+ break;
case SAVEt_I16: /* I16 reference */
ptr = SSPOPPTR;
*(I16*)ptr = (I16)SSPOPINT;
@@ -1097,9 +1117,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;
@@ -1135,6 +1152,22 @@
#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)
+{
+ dVAR;
+ 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.10/perl/scope.h#3 (text) ====
Index: perl/scope.h
--- perl/scope.h#2~33123~ 2008-01-30 03:45:08.000000000 -0800
+++ perl/scope.h 2008-10-16 13:45:27.000000000 -0700
@@ -54,6 +54,7 @@
#define SAVEt_COMPILE_WARNINGS 43
#define SAVEt_STACK_CXPOS 44
#define SAVEt_PARSER 45
+#define SAVEt_PADSV_AND_MORTALIZE 46
#ifndef SCOPE_SAVES_SIGNAL_MASK
#define SCOPE_SAVES_SIGNAL_MASK 0
@@ -127,6 +128,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.10/perl/sv.c#28 (text) ====
Index: perl/sv.c
--- perl/sv.c#27~34480~ 2008-10-15 00:33:31.000000000 -0700
+++ perl/sv.c 2008-10-16 13:45:27.000000000 -0700
@@ -10532,8 +10532,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,
@@ -10846,13 +10844,13 @@
TOPPTR(nss,ix) = hv_dup_inc(hv, param);
}
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);
@@ -10937,6 +10935,17 @@
ptr = POPPTR(ss,ix);
TOPPTR(nss,ix) = parser_dup((const yy_parser*)ptr, param);
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.10/perl/t/op/ref.t#3 (xtext) ====
Index: perl/t/op/ref.t
--- perl/t/op/ref.t#2~34266~ 2008-09-04 08:33:04.000000000 -0700
+++ perl/t/op/ref.t 2008-10-16 13:45:27.000000000 -0700
@@ -8,7 +8,7 @@
require 'test.pl';
use strict qw(refs subs);
-plan(182);
+plan(189);
# Test glob operations.
@@ -584,6 +584,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.