summaryrefslogtreecommitdiff
path: root/cop.h
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-06-03 20:06:24 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-06-03 20:06:24 -0700
commit767eda446920b18c91ad2d91822428141c99301f (patch)
treeb09e6e97b02d1fbd51b456eba16ae55a6aaac4d3 /cop.h
parent339c6c60f3062528eca01e318da233bdf2b57ff2 (diff)
downloadperl-767eda446920b18c91ad2d91822428141c99301f.tar.gz
[perl #7946] Lvalue subs do not autovivify
This commit makes autovivification work with lvalue subs. It follows the same technique used by other autovivifiable ops (aelem, helem, tc.), except that, due to flag constraints, it uses a single flag and instead checks the op tree at run time to find out what sort of thing to vivify. The flag constraints are that these two flags: #define OPpENTERSUB_HASTARG 32 /* Called from OP tree. */ #define OPpENTERSUB_NOMOD 64 /* Immune to op_lvalue() for :attrlist. */ conflict with these: #define OPpDEREF (32|64) /* autovivify: Want ref to something: */ #define OPpDEREF_AV 32 /* Want ref to AV. */ #define OPpDEREF_HV 64 /* Want ref to HV. */ #define OPpDEREF_SV (32|64) /* Want ref to SV. */ Renumbering HASTARG and NOMOD is problematic, as there are places in op.c that change entersubs into rv2cvs, and the entersub and rv2cv flags would conflict. Setting the flags correctly when changing the type is hard and would result in subtle bugs if not done perfectly. Ops like ${...} don’t actually autovivify; it’s the op inside that does it. In those cases, the parent op is flagged with OPpDEREFed, and it skips get-magic, as it has already been called by the inner op. Since entersub is now marked as being an autovivifying op, ${...} in lvalue context ends up skipping get-magic if there is a foo() inside. And this affects even regular subs. So pp_leavesub and pp_return have to call get-magic; hence the new tests in gmagic.t.
Diffstat (limited to 'cop.h')
-rw-r--r--cop.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/cop.h b/cop.h
index 2f926c80f1..82eee29fa9 100644
--- a/cop.h
+++ b/cop.h
@@ -635,7 +635,7 @@ struct block_format {
#define PUSHSUB(cx) \
PUSHSUB_BASE(cx) \
cx->blk_u16 = PL_op->op_private & \
- (OPpLVAL_INTRO|OPpENTERSUB_INARGS);
+ (OPpLVAL_INTRO|OPpENTERSUB_INARGS|OPpENTERSUB_DEREF);
/* variant for use by OP_DBSTATE, where op_private holds hint bits */
#define PUSHSUB_DB(cx) \