summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-08-31 22:44:57 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-09-01 06:20:48 -0700
commit9da346da98617273964d333ee33ca5cdbddae4a1 (patch)
treea4870ef2ca4ef8a9e1f6ce9456aaf9175e8447d0 /pp.c
parent7d953ba8a0841912423af9b3e7d1daef726d5fb0 (diff)
downloadperl-9da346da98617273964d333ee33ca5cdbddae4a1.tar.gz
[perl #97484] Make defined &{...} vivify CORE subs
Magical variables usually get autovivified, even in rvalue context, because Perl is trying to pretend they have been there all along. That means defined(${"."}) will autovivify $. and return true. Until CORE subs were introduced, there were no subroutines that popped into existence when looked at. This commit makes rv_2cv use the GV_ADDMG flag added in commit 23496c6ea. When this flag is passed, gv_fetchpvn_flags creates a GV but does not add it to the stash until it finds out that it is creat- ing a magical one. The CORE sub code calls newATTRSUB, which expects to add the CV to the stash itself. So the gv has to be added there and then. So gv_fetchpvn_flags is also adjusted to add the gv to the stash right before calling newATTRSUB, and to tell itself that the GV_ADDMG flag is actually off. It might be better to move the CV-creation code into op.c and inline parts of newATTRSUB, to avoid fiddling with the addmg variable (and avoid prototype checks on CORE subs), but that refactoring should probably come in separate commits.
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/pp.c b/pp.c
index ab933c984b..c732c5ba86 100644
--- a/pp.c
+++ b/pp.c
@@ -427,7 +427,7 @@ PP(pp_rv2cv)
GV *gv;
HV *stash_unused;
const I32 flags = (PL_op->op_flags & OPf_SPECIAL)
- ? 0
+ ? GV_ADDMG
: ((PL_op->op_private & (OPpLVAL_INTRO|OPpMAY_RETURN_CONSTANT)) == OPpMAY_RETURN_CONSTANT)
? GV_ADD|GV_NOEXPAND
: GV_ADD;