Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit dd1ff8d

Browse files
author
Reini Urban
committed
siggoto+pad: fix cvdepth
with goto signatures, true tailcalls, we might overshoot CvDEPTH(cv) over PadlistMAX(padlist). When we do that store the adjusted cx->blk_sub.olddepth also. Closes #162, a SEGV in Test::CleanNamespaces with many tailcalls and overshooting CvDEPTH. Also harmonize -DXv Pad diagnostics. Fix -Dt for entersub/enterxssub: correct function name (if a CV)
1 parent 223e183 commit dd1ff8d

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

dump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,10 +2731,10 @@ Perl_debop(pTHX_ const OP *o)
27312731
case OP_ENTERSUB:
27322732
case OP_ENTERXSSUB:
27332733
{
2734-
CV* cv = deb_curcv(cxstack_ix);
2735-
if (cv && CvGV(cv))
2734+
SV* const sv = *PL_stack_sp;
2735+
if (sv && SvTYPE(sv) == SVt_PVCV) /* no GV or PV yet */
27362736
PerlIO_printf(Perl_debug_log, "(%"SVf")",
2737-
SVfARG(cv_name(cv,NULL,CV_NAME_NOMAIN)));
2737+
SVfARG(cv_name((CV*)sv, NULL, CV_NAME_NOMAIN)));
27382738
break;
27392739
}
27402740
case OP_METHOD_NAMED:

pad.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,8 @@ Perl_pad_sv(pTHX_ PADOFFSET po)
13961396
if (!po)
13971397
Perl_croak(aTHX_ "panic: pad_sv po");
13981398
DEBUG_X(PerlIO_printf(Perl_debug_log,
1399-
"Pad 0x%"UVxf" 0x%"UVxf"[%ld] [%d] sv=0x%"UVxf"\n",
1400-
PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)AvFILLp(PL_comppad),
1399+
"Pad 0x%"UVxf"[%ld] 0x%"UVxf" pad_sv: %d sv=0x%"UVxf"\n",
1400+
PTR2UV(PL_comppad), (long)AvFILLp(PL_comppad), PTR2UV(PL_curpad),
14011401
(int)po, PTR2UV(PL_curpad[po])));
14021402
assert(PL_comppad ? po <= (PADOFFSET)AvFILLp(PL_comppad) : 1);
14031403
return PL_curpad[po];

pp_ctl.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,8 @@ PP(pp_dbstate)
20412041
if (CvDEPTH(cv) >= 2) {
20422042
PADLIST *padlist = CvPADLIST(cv);
20432043
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
2044-
"Pad push padlist max=%d, CvDEPTH=%d (dbstate)\n",
2045-
(int)PadlistMAX(padlist), (int)CvDEPTH(cv)));
2044+
"Pad push padlist max=%d, CvDEPTH=%d (dbstate)\n",
2045+
(int)PadlistMAX(padlist), (int)CvDEPTH(cv)));
20462046
if (CvDEPTH(cv) == PERL_SUB_DEPTH_WARN && ckWARN(WARN_RECURSION))
20472047
sub_crush_depth(cv);
20482048
if (CvDEPTH(cv) > PadlistMAX(padlist)+1) { /* adjust siggoto */
@@ -2774,6 +2774,7 @@ PP(pp_goto)
27742774
CV* cursub = cx->blk_sub.cv;
27752775
PADLIST * const padlist = CvPADLIST(cv);
27762776
cx->blk_sub.cv = cv; /* adjust context */
2777+
cx->blk_sub.olddepth = CvDEPTH(cv);
27772778
if (CvHASSIG(cursub)) { /* sig2sig: no @_, just SP-MARK */
27782779
arg = av; /* mark */
27792780
DEBUG_kv(PerlIO_printf(Perl_debug_log,
@@ -2782,8 +2783,9 @@ PP(pp_goto)
27822783
(long int)(cx->blk_sub.savearray - av + 1))); /* sp-mark+1 */
27832784
/*PUSHMARK((SV**)cx->blk_sub.savearray);*/
27842785
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
2785-
"Pad padlist max=%d, CvDEPTH=%d (goto sig2sig)\n",
2786-
(int)PadlistMAX(padlist), (int)CvDEPTH(cv)));
2786+
"Pad padlist max=%d, CvDEPTH=%d (goto sig2sig %s)\n",
2787+
(int)PadlistMAX(padlist), (int)CvDEPTH(cv),
2788+
SvPVX_const(cv_name(cv, NULL, CV_NAME_NOMAIN))));
27872789
PAD_SET_CUR(padlist, PadlistMAX(padlist));
27882790
goto call_pp_sub;
27892791
}
@@ -2827,6 +2829,10 @@ PP(pp_goto)
28272829
}
28282830

28292831
if (CxTYPE(cx) == CXt_SUB) {
2832+
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
2833+
"Pad CvDEPTH %d => %d (%s)\n",
2834+
(int)CvDEPTH(cx->blk_sub.cv), (int) cx->blk_sub.olddepth,
2835+
SvPVX_const(cv_name(cx->blk_sub.cv, NULL, CV_NAME_NOMAIN))));
28302836
CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth;
28312837
SvREFCNT_dec_NN(cx->blk_sub.cv);
28322838
}
@@ -2869,6 +2875,7 @@ PP(pp_goto)
28692875
without new cx and padframe, reusing the old pads. retop is CvSTART */
28702876
PADLIST * const padlist = CvPADLIST(cv);
28712877
I32 depth = CvDEPTH(cv);
2878+
cx->blk_sub.cv = cv;
28722879
cx->blk_sub.argarray = MARK+1;
28732880
cx->blk_sub.savearray = (AV*)SP;
28742881
cx->blk_sub.olddepth = depth;
@@ -2892,13 +2899,13 @@ PP(pp_goto)
28922899
/* cpan/Test-Simple/t/capture.t? */
28932900
depth = PadlistMAX(padlist);
28942901
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
2895-
"Pad padlist max=%d, CvDEPTH=%d (tailcall)\n",
2896-
(int)depth, (int)CvDEPTH(cv)));
2897-
if (CvDEPTH(cv) <= depth) {
2902+
"Pad padlist max=%d, CvDEPTH=%d (tailcall %s)\n",
2903+
(int)depth, (int)CvDEPTH(cv),
2904+
SvPVX_const(cv_name(cv, NULL, CV_NAME_NOMAIN))));
2905+
if (CvDEPTH(cv) <= depth)
28982906
CvDEPTH(cv) = depth;
2899-
}
29002907
#endif
2901-
PAD_SET_CUR(padlist, depth);
2908+
PAD_SET_CUR_NOSAVE(padlist, depth);
29022909
goto call_pp_sub;
29032910
}
29042911
}
@@ -2939,8 +2946,9 @@ PP(pp_goto)
29392946
if (CvDEPTH(cv) == PERL_SUB_DEPTH_WARN && ckWARN(WARN_RECURSION))
29402947
sub_crush_depth(cv);
29412948
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
2942-
"Pad push padlist max=%d, CvDEPTH=%d (goto pp)\n",
2943-
(int)PadlistMAX(padlist), (int)CvDEPTH(cv)));
2949+
"Pad push padlist max=%d, CvDEPTH=%d (goto %s)\n",
2950+
(int)PadlistMAX(padlist), (int)CvDEPTH(cv),
2951+
SvPVX_const(cv_name(cv, NULL, CV_NAME_NOMAIN))));
29442952
pad_push(padlist, CvDEPTH(cv));
29452953
}
29462954
PL_curcop = cx->blk_oldcop;

pp_hot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,7 @@ PP(pp_entersub)
40334033
if (CvDEPTH(cv) > PadlistMAX(padlist)+1) { /* not with siggoto */
40344034
depth = PadlistMAX(padlist)+1;
40354035
CvDEPTH(cv) = depth;
4036+
cx->blk_sub.olddepth = depth-1;
40364037
}
40374038
pad_push(padlist, depth);
40384039
}

scope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ Perl_leave_scope(pTHX_ I32 base)
11381138
sv = *svp;
11391139

11401140
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1141-
"Pad 0x%"UVxf"[%ld] 0x%"UVxf" clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
1141+
"Pad 0x%"UVxf"[%ld] 0x%"UVxf" clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n",
11421142
PTR2UV(PL_comppad), (long)AvFILLp(PL_comppad), PTR2UV(PL_curpad),
11431143
(long)(svp-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv),
11441144
(SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"));

0 commit comments

Comments
 (0)