summaryrefslogtreecommitdiff
path: root/gv.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 /gv.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 'gv.c')
-rw-r--r--gv.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gv.c b/gv.c
index e4c1d211f7..07ff3b2ac1 100644
--- a/gv.c
+++ b/gv.c
@@ -1050,7 +1050,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
const I32 no_init = flags & (GV_NOADD_NOINIT | GV_NOINIT);
const I32 no_expand = flags & GV_NOEXPAND;
const I32 add = flags & ~GV_NOADD_MASK;
- const bool addmg = !!(flags & GV_ADDMG);
+ bool addmg = !!(flags & GV_ADDMG);
const char *const name_end = nambeg + full_len;
const char *const name_em1 = name_end - 1;
U32 faking_it;
@@ -1402,6 +1402,10 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
new ATTRSUB. */
(void)core_prototype((SV *)cv, name, code, &opnum);
if (ampable) {
+ if (addmg) {
+ hv_store(stash,name,len,(SV *)gv,0);
+ addmg = FALSE;
+ }
CvLVALUE_on(cv);
newATTRSUB(oldsavestack_ix,
newSVOP(