- /* Still from commit b5c19bd7, cv_clone() is no longer able to clone named
- * subs propery. With this commit, pad_findlex() stores the parent index of a
- * fake pad entry in the NV slot of the corresponding pad name SV, but only
- * for anonymous subs (since named subs aren't supposed to be cloned in pure
- * Perl land). To fix this, we just manually relink the new fake pad entries
- * to the new ones.
- * For some reason perl 5.8 crashes too without this, supposedly because of
- * other closure bugs. Hence we enable it everywhere. */
- if (!CvCLONE(old_cv)) {
- const AV *old_padname = (const AV *) AvARRAY(CvPADLIST(old_cv))[0];
- AV *old_pad = (AV *) AvARRAY(CvPADLIST(old_cv))[1];
- AV *new_pad = (AV *) AvARRAY(CvPADLIST(new_cv))[1];
- const SV **old_aryname = (const SV **) AvARRAY(old_padname);
- SV **old_ary = AvARRAY(old_pad);
- SV **new_ary = AvARRAY(new_pad);
- I32 fname = AvFILLp(old_padname);
- I32 fpad = AvFILLp(old_pad);
- I32 ix;
-
- for (ix = fpad; ix > 0; ix--) {
- const SV *namesv = (ix <= fname) ? old_aryname[ix] : NULL;
-
- if (namesv && namesv != &PL_sv_undef && SvFAKE(namesv)) {
- SvREFCNT_dec(new_ary[ix]);
- new_ary[ix] = SvREFCNT_inc(old_ary[ix]);
+ padlist = newAV();
+ AvREAL_off(padlist);
+ av_fill(padlist, fpadlist);
+ CvPADLIST(cv) = padlist;
+
+ padname = newAV();
+ av_fill(padname, fpadname);
+ if (fpadname >= 0) {
+ I32 j;
+ SV **psvp = AvARRAY(protopadname);
+ SV **svp = AvARRAY(padname);
+
+ svp[0] = &PL_sv_undef;
+ for (j = 1; j <= fpadname; ++j)
+ svp[j] = SvREFCNT_inc(psvp[j]);
+ }
+ AvARRAY(padlist)[0] = MUTABLE_SV(padname);
+
+ if (fpadlist >= 1) {
+ I32 i;
+
+ for (i = 1; i <= fpadlist; ++i) {
+ AV *protoframe = MUTABLE_AV(AvARRAY(protopadlist)[i]);
+ AV *frame = newAV();
+ SV **psvp = AvARRAY(protoframe);
+ SV **svp;
+ I32 j, fframe = AvFILLp(protoframe);
+
+ av_fill(frame, fframe);
+ svp = AvARRAY(frame);
+ if (i == 1) {
+ AV *a0 = newAV(); /* will be @_ */
+ AvREAL_off(a0);
+ AvREIFY_on(a0);
+ svp[0] = MUTABLE_SV(a0);
+ } else {
+ svp[0] = SvREFCNT_inc(psvp[0]);