summaryrefslogtreecommitdiff
path: root/op.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 /op.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 'op.h')
-rw-r--r--op.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/op.h b/op.h
index 5466e57e3d..74030d966b 100644
--- a/op.h
+++ b/op.h
@@ -204,6 +204,7 @@ Deprecated. Use C<GIMME_V> instead.
#define OPpENTERSUB_HASTARG 32 /* Called from OP tree. */
#define OPpENTERSUB_NOMOD 64 /* Immune to op_lvalue() for :attrlist. */
#define OPpENTERSUB_INARGS 4 /* Lval used as arg to a sub. */
+#define OPpENTERSUB_DEREF 1 /* Lval call that autovivifies. */
/* OP_RV2CV only */
#define OPpENTERSUB_AMPER 8 /* Used & form to call. */
#define OPpENTERSUB_NOPAREN 128 /* bare sub call (without parens) */