Blame SOURCES/perl-5.31.0-Don-t-use-PL_check-op_type-to-check-for-filetets-ops.patch

7586d2
From 1d31efef7dd4388fd606972e67bda3318e8838fe Mon Sep 17 00:00:00 2001
7586d2
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
7586d2
Date: Tue, 21 May 2019 17:34:49 +0100
7586d2
Subject: [PATCH] Don't use PL_check[op_type] to check for filetets ops to
7586d2
 stack
7586d2
MIME-Version: 1.0
7586d2
Content-Type: text/plain; charset=UTF-8
7586d2
Content-Transfer-Encoding: 8bit
7586d2
7586d2
This breaks hooking the filetest ops' check function by modules like
7586d2
bareword::filehandles.  Instead use the OP_IS_FILETEST() macro to decide
7586d2
check for filetest ops.  Also add an OP_IS_STAT() macro for when we want
7586d2
to check for (l)stat as well as the filetest ops.
7586d2
7586d2
c.f. https://rt.cpan.org/Ticket/Display.html?id=127073
7586d2
7586d2
Signed-off-by: Petr Písař <ppisar@redhat.com>
7586d2
---
7586d2
 op.c          | 11 ++++-------
7586d2
 op.h          |  2 ++
7586d2
 regen/opcodes |  1 +
7586d2
 3 files changed, 7 insertions(+), 7 deletions(-)
7586d2
7586d2
diff --git a/op.c b/op.c
7586d2
index 29181ba731..dba7ac7fea 100644
7586d2
--- a/op.c
7586d2
+++ b/op.c
7586d2
@@ -991,8 +991,7 @@ Perl_op_clear(pTHX_ OP *o)
7586d2
 	o->op_targ = 0;
7586d2
 	break;
7586d2
     default:
7586d2
-	if (!(o->op_flags & OPf_REF)
7586d2
-	    || (PL_check[o->op_type] != Perl_ck_ftst))
7586d2
+	if (!(o->op_flags & OPf_REF) || !OP_IS_STAT(o->op_type))
7586d2
 	    break;
7586d2
 	/* FALLTHROUGH */
7586d2
     case OP_GVSV:
7586d2
@@ -4413,8 +4412,7 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
7586d2
     /* [20011101.069 (#7861)] File test operators interpret OPf_REF to mean that
7586d2
        their argument is a filehandle; thus \stat(".") should not set
7586d2
        it. AMS 20011102 */
7586d2
-    if (type == OP_REFGEN &&
7586d2
-        PL_check[o->op_type] == Perl_ck_ftst)
7586d2
+    if (type == OP_REFGEN && OP_IS_STAT(o->op_type))
7586d2
         return o;
7586d2
 
7586d2
     if (type != OP_LEAVESUBLV)
7586d2
@@ -11696,9 +11694,8 @@ Perl_ck_ftst(pTHX_ OP *o)
7586d2
 	scalar((OP *) kid);
7586d2
 	if ((PL_hints & HINT_FILETEST_ACCESS) && OP_IS_FILETEST_ACCESS(o->op_type))
7586d2
 	    o->op_private |= OPpFT_ACCESS;
7586d2
-	if (type != OP_STAT && type != OP_LSTAT
7586d2
-            && PL_check[kidtype] == Perl_ck_ftst
7586d2
-            && kidtype != OP_STAT && kidtype != OP_LSTAT
7586d2
+	if (OP_IS_FILETEST(type)
7586d2
+            && OP_IS_FILETEST(kidtype)
7586d2
         ) {
7586d2
 	    o->op_private |= OPpFT_STACKED;
7586d2
 	    kid->op_private |= OPpFT_STACKING;
7586d2
diff --git a/op.h b/op.h
7586d2
index c9f05b2271..ad6cf7fe49 100644
7586d2
--- a/op.h
7586d2
+++ b/op.h
7586d2
@@ -1021,6 +1021,8 @@ C<sib> is non-null. For a higher-level interface, see C<L</op_sibling_splice>>.
7586d2
 #define OP_TYPE_ISNT_AND_WASNT(o, type) \
7586d2
     ( (o) && OP_TYPE_ISNT_AND_WASNT_NN(o, type) )
7586d2
 
7586d2
+/* should match anything that uses ck_ftst in regen/opcodes */
7586d2
+#define OP_IS_STAT(op) (OP_IS_FILETEST(op) || (op) == OP_LSTAT || (op) == OP_STAT)
7586d2
 
7586d2
 #  define OpHAS_SIBLING(o)	(cBOOL((o)->op_moresib))
7586d2
 #  define OpSIBLING(o)		(0 + (o)->op_moresib ? (o)->op_sibparent : NULL)
7586d2
diff --git a/regen/opcodes b/regen/opcodes
7586d2
index b4bf904fdc..4e8236947a 100644
7586d2
--- a/regen/opcodes
7586d2
+++ b/regen/opcodes
7586d2
@@ -397,6 +397,7 @@ getsockname	getsockname		ck_fun		is%	Fs
7586d2
 getpeername	getpeername		ck_fun		is%	Fs
7586d2
 
7586d2
 # Stat calls.  OP_IS_FILETEST wants them consecutive.
7586d2
+# Also needs to match OP_IS_STAT() in op.h
7586d2
 
7586d2
 lstat		lstat			ck_ftst		u-	F?
7586d2
 stat		stat			ck_ftst		u-	F?
7586d2
-- 
7586d2
2.20.1
7586d2