summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-10-16 18:04:28 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-10-16 21:51:46 -0700
commit8771da69db30134352181c38401c7e50753a7ee8 (patch)
tree10c5d26ce8e3d86763deb53b5d0a1e68d860ea90
parent61c8799482f9e533904bfe832138c24064709f7d (diff)
downloadperl-8771da69db30134352181c38401c7e50753a7ee8.tar.gz
Used pad name lists for pad ids
I added pad IDs so that a pad could record which pad it closes over, to avoid problems with closures closing over the wrong pad, resulting in crashes or bizarre copies. These pad IDs were shared between clones of the same pad. In commit 9ef8d56, for efficiency I made clones of the same closure share the same pad name list. It has just occurred to be that each padlist containing the same pad name list also has the same pad ID, so we can just use the pad name list itself as the ID. This makes padlists 32 bits smaller and eliminates PL_pad_generation from the interpreter struct.
-rw-r--r--embedvar.h1
-rw-r--r--intrpvar.h1
-rw-r--r--pad.c8
-rw-r--r--pad.h3
-rw-r--r--pp_ctl.c3
-rw-r--r--toke.c3
6 files changed, 9 insertions, 10 deletions
diff --git a/embedvar.h b/embedvar.h
index dc2583dd85..65c2ff1617 100644
--- a/embedvar.h
+++ b/embedvar.h
@@ -255,7 +255,6 @@
#define PL_pad_reset_pending (vTHX->Ipad_reset_pending)
#define PL_padix (vTHX->Ipadix)
#define PL_padix_floor (vTHX->Ipadix_floor)
-#define PL_padlist_generation (vTHX->Ipadlist_generation)
#define PL_parser (vTHX->Iparser)
#define PL_patchlevel (vTHX->Ipatchlevel)
#define PL_peepp (vTHX->Ipeepp)
diff --git a/intrpvar.h b/intrpvar.h
index 3978dc1c5d..9cff6e4d55 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -768,7 +768,6 @@ PERLVAR(I, custom_ops, HV *) /* custom op registrations */
PERLVARI(I, globhook, globhook_t, NULL)
PERLVARI(I, glob_index, int, 0)
-PERLVARI(I, padlist_generation, U32, 1) /* id to identify padlist clones */
PERLVAR(I, reentrant_retint, int) /* Integer return value from reentrant functions */
/* The last unconditional member of the interpreter structure when 5.10.0 was
diff --git a/pad.c b/pad.c
index 88235663dc..673f8c7329 100644
--- a/pad.c
+++ b/pad.c
@@ -280,7 +280,6 @@ Perl_pad_new(pTHX_ int flags)
padname = (PAD *)SvREFCNT_inc_simple_NN(PL_comppad_name);
}
else {
- padlist->xpadl_id = PL_padlist_generation++;
av_store(pad, 0, NULL);
padname = newAV();
}
@@ -1994,7 +1993,8 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside)
outside = CvOUTSIDE(proto);
if ((CvCLONE(outside) && ! CvCLONED(outside))
|| !CvPADLIST(outside)
- || CvPADLIST(outside)->xpadl_id != protopadlist->xpadl_outid) {
+ || PadlistNAMES(CvPADLIST(outside))
+ != protopadlist->xpadl_outid) {
outside = find_runcv_where(
FIND_RUNCV_padid_eq, (IV)protopadlist->xpadl_outid, NULL
);
@@ -2016,7 +2016,6 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside)
SAVESPTR(PL_comppad_name);
PL_comppad_name = protopad_name;
CvPADLIST(cv) = pad_new(padnew_CLONE|padnew_SAVE);
- CvPADLIST(cv)->xpadl_id = protopadlist->xpadl_id;
av_fill(PL_comppad, fpad);
@@ -2025,7 +2024,8 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside)
outpad = outside && CvPADLIST(outside)
? AvARRAY(PadlistARRAY(CvPADLIST(outside))[depth])
: NULL;
- if (outpad) CvPADLIST(cv)->xpadl_outid = CvPADLIST(outside)->xpadl_id;
+ if (outpad)
+ CvPADLIST(cv)->xpadl_outid = PadlistNAMES(CvPADLIST(outside));
for (ix = fpad; ix > 0; ix--) {
SV* const namesv = (ix <= fname) ? pname[ix] : NULL;
diff --git a/pad.h b/pad.h
index f65af17a78..26e183ccd8 100644
--- a/pad.h
+++ b/pad.h
@@ -31,8 +31,7 @@ typedef U64TYPE PADOFFSET;
struct padlist {
SSize_t xpadl_max; /* max index for which array has space */
PAD ** xpadl_alloc; /* pointer to beginning of array of AVs */
- U32 xpadl_id; /* Semi-unique ID, shared between clones */
- U32 xpadl_outid; /* ID of outer pad */
+ PADNAMELIST*xpadl_outid; /* Padnamelist of outer pad; used as ID */
};
diff --git a/pp_ctl.c b/pp_ctl.c
index 1aaa26156b..bc9b647cf6 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3273,7 +3273,8 @@ Perl_find_runcv_where(pTHX_ U8 cond, IV arg, U32 *db_seqp)
switch (cond) {
case FIND_RUNCV_padid_eq:
if (!CvPADLIST(cv)
- || CvPADLIST(cv)->xpadl_id != (U32)arg) continue;
+ || PadlistNAMES(CvPADLIST(cv)) != (PADNAMELIST *)arg)
+ continue;
return cv;
case FIND_RUNCV_level_eq:
if (level++ != arg) continue;
diff --git a/toke.c b/toke.c
index 80144b771e..61f1e047e7 100644
--- a/toke.c
+++ b/toke.c
@@ -10985,7 +10985,8 @@ Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
if (outsidecv && CvPADLIST(outsidecv))
- CvPADLIST(PL_compcv)->xpadl_outid = CvPADLIST(outsidecv)->xpadl_id;
+ CvPADLIST(PL_compcv)->xpadl_outid =
+ PadlistNAMES(CvPADLIST(outsidecv));
return oldsavestack_ix;
}