diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-11-29 09:08:08 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-11-29 09:11:32 -0800 |
commit | db9306af4ddf47b54fb142041f8f950b1ec18f08 (patch) | |
tree | 2d966d7a75b8edd8f159f089f96b4e9f061395ee /scope.c | |
parent | af5aa9e378e68e5202ada6a61d269e74cc9fe298 (diff) | |
download | perl-db9306af4ddf47b54fb142041f8f950b1ec18f08.tar.gz |
Clear method caches when unwinding local *foo=sub{}
local *foo=sub{} is done in two stages:
• First the local *foo localises the GP (the glob pointer, or list of
slots), setting a flag on the GV.
• Then scalar assignment sees the flag on the GV on the LHS and loca-
lises a single slot.
The slot localisation only stores on the savestack a pointer into the
GP struct and the old value. There is no reference to the GV.
To restore a method properly, we have to have a reference to the GV
when the slot localisation is undone.
So in this commit I have added a new save type, SAVEt_GVSLOT. It is
like SAVEt_GENERIC_SV, except it pushes the GV as well. Currently
it is used only for CVs, but I will need it for HVs and maybe
AVs as well.
It is possible for the unwinding of the slot localisation to affect
only a GV other than the one that is pushed, if glob assignments have
taken place since the local *foo. So we have to check whether the
pointer is inside the GP and use PL_sub_generation++ if it is not.
Diffstat (limited to 'scope.c')
-rw-r--r-- | scope.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -783,6 +783,23 @@ Perl_leave_scope(pTHX_ I32 base) SvREFCNT_dec(sv); SvREFCNT_dec(value); break; + case SAVEt_GVSLOT: /* any slot in GV */ + value = MUTABLE_SV(SSPOPPTR); + ptr = SSPOPPTR; + gv = MUTABLE_GV(SSPOPPTR); + hv = GvSTASH(gv); + if (hv && HvENAME(hv) && ( + (value && SvTYPE(value) == SVt_PVCV) + || (*(SV **)ptr && SvTYPE(*(SV**)ptr) == SVt_PVCV) + )) + { + if ((char *)ptr < (char *)GvGP(gv) + || (char *)ptr > (char *)GvGP(gv) + sizeof(struct gp) + || GvREFCNT(gv) > 1) + PL_sub_generation++; + else mro_method_changed_in(hv); + } + goto restore_svp; case SAVEt_AV: /* array reference */ av = MUTABLE_AV(SSPOPPTR); gv = MUTABLE_GV(SSPOPPTR); |