summaryrefslogtreecommitdiff
path: root/perly.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-06-16 14:00:01 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-07-25 23:47:59 -0700
commit325e1816dc5cd0a76cbe852add810d33cb1a95fb (patch)
treec57ad779f45c257efc04f15f39a3220213598f22 /perly.c
parent833bf1cd69463bf6a806f451560f3a1039bd09ca (diff)
downloadperl-325e1816dc5cd0a76cbe852add810d33cb1a95fb.tar.gz
pad.c: Use &PL_sv_no for const pad names
Currently &PL_sv_undef as a pad name can indicate either a free slot available for use by pad_alloc or a slot used by an op target (or, under ithreads, a constant or GV). Currently pad_alloc distinguishes between free slots and unnamed slots based on whether the value in the pad has PADMY or PADTMP set. If neither is set, then the slot is free. If either is set, the slot is in use. This makes it rather difficult to distinguish between constants stored in the pad (under ithreads) and targets. The latter need to be copied when referenced, to give the impression that a new scalar is being returned by an operator each time. (So \"$a" has to return a refer- ence to a new scalar each time, but \1 should return the same one.) Also, constants are shared between recursion levels. Currently, if the value is marked READONLY or is a shared hash key scalar, it is shared. But targets can also me shared hash keys, resulting in bugs. It also makes it impossible for the same constant to be shared by mul- tiple pad slots, as freeing one const op will turn off the PADTMP flag while the other slot still uses it, making the latter appear to be free. Hence a lot of copying occurs under ithreads. (Actually, that may not be true any more since 3b1c21fabed, as freed const ops swipe their constants from the pad. But right now, a lot of copying does still happen.) Also, XS modules may want to create const ops that return the same mutable SV each time. That is currently not possible without various workarounds including custom ops and references. (See <https://rt.perl.org/rt3/Ticket/Display.html?id=105906#txn-1075354>.) This commit changes pad_alloc and pad_free to use &PL_sv_no for con- stants and updates other code to keep all tests passing. Subsequent commits will actually use that information to fix bugs. This will probably break PadWalker, but I think it is an acceptable trade-off. The alternative would be to make PadnamePV forever more complex than necessary, by giving it a special case for &PL_sv_no and having it return NULL. I gave PadnameLEN a special case for &PL_sv_undef, so it may appear that I have simply shifted the complexity around. But if pad names stop being SVs, then this exception will simply disappear, since the global &PL_padname_undef will have 0 in its length field.
Diffstat (limited to 'perly.c')
-rw-r--r--perly.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/perly.c b/perly.c
index d17f19b78a..d7d9ea34c6 100644
--- a/perly.c
+++ b/perly.c
@@ -221,6 +221,7 @@ S_clear_yystack(pTHX_ const yy_parser *parser)
if (ps->compcv != PL_compcv) {
PL_compcv = ps->compcv;
PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
+ PL_comppad_name = PadlistNAMES(CvPADLIST(PL_compcv));
}
YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
op_free(ps->val.opval);