summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-09-08 08:14:28 +0000
committerNicholas Clark <nick@ccl4.org>2021-09-08 08:30:38 +0000
commit034242a8a539b024648b18318271eabddf40ca48 (patch)
treef9a1052d4707295238f142ad435573602a564def /pp_hot.c
parent0ae3a5cd82ef1c87a47925be64da85d49c7a79f7 (diff)
downloadperl-034242a8a539b024648b18318271eabddf40ca48.tar.gz
In pp_defined assert that the SV is not a hash or array.
The code that handled hashes and arrays was removed by commit 2517717a8902: The cases for SVt_PVAV and SVt_PVHV in pp_defined are unreachable. Remove them, and hit to the C compiler that it's unlikely that someone used `defined` on a subroutine. These have been unreachable since `defined @array` and `defined %hash` became syntax errors. Whilst the same PP code is used for // and //=, expressions such as`@a // @b` put the left array (or hash) in scalar context, meaning that it always returns a define value. (Should we warn on these?) However, it turns out that that the removed code was reachable by XS code generating data structures that would be "illegal" in pure Perl (eg also triggering "Bizarre copy of ..." errors). Hence with -DDEBUGGING, add logic to report problematic cases, instead of silently continuing with changed behaviour.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 17683ff000..43c61bd272 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1365,6 +1365,15 @@ PP(pp_defined)
RETSETNO;
}
+ /* Historically what followed was a switch on SvTYPE(sv), handling SVt_PVAV,
+ * SVt_PVCV, SVt_PVHV and "default". `defined &sub` is still valid syntax,
+ * hence we still need the special case PVCV code. But AVs and HVs now
+ * should never arrive here... */
+#ifdef DEBUGGING
+ assert(SvTYPE(sv) != SVt_PVAV);
+ assert(SvTYPE(sv) != SVt_PVHV);
+#endif
+
if (UNLIKELY(SvTYPE(sv) == SVt_PVCV)) {
if (CvROOT(sv) || CvXSUB(sv))
defined = TRUE;