b8c914
From 8fe3452cc6ac7af8c08c2044cd3757018a9c8887 Mon Sep 17 00:00:00 2001
b8c914
From: Zefram <zefram@fysh.org>
b8c914
Date: Fri, 22 Dec 2017 05:32:41 +0000
b8c914
Subject: [PATCH] preserve numericness of system() args on Win32
b8c914
MIME-Version: 1.0
b8c914
Content-Type: text/plain; charset=UTF-8
b8c914
Content-Transfer-Encoding: 8bit
b8c914
b8c914
On Windows there's a nasty variation in the meaning of arguments
b8c914
to Perl's system(), in which a numeric first argument isn't used as
b8c914
part of the command to run, but instead selects between two different
b8c914
operations to perform with the command (whether to wait for the command
b8c914
to complete or not).  Therefore the reduction of argument scalars to
b8c914
their operative values in the parent process, which was added in commit
b8c914
64def2aeaeb63f92dadc6dfa33486c1d7b311963, needs to preserve numericness
b8c914
of arguments on Windows.  Fixes [perl #132633].
b8c914
b8c914
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8c914
---
b8c914
 pp_sys.c | 35 +++++++++++++++++++++++++++++++----
b8c914
 1 file changed, 31 insertions(+), 4 deletions(-)
b8c914
b8c914
diff --git a/pp_sys.c b/pp_sys.c
b8c914
index beb60da4c6..0649794104 100644
b8c914
--- a/pp_sys.c
b8c914
+++ b/pp_sys.c
b8c914
@@ -4393,12 +4393,39 @@ PP(pp_system)
b8c914
 # endif
b8c914
 
b8c914
     while (++MARK <= SP) {
b8c914
-	SV *origsv = *MARK;
b8c914
+	SV *origsv = *MARK, *copysv;
b8c914
 	STRLEN len;
b8c914
 	char *pv;
b8c914
-	pv = SvPV(origsv, len);
b8c914
-	*MARK = newSVpvn_flags(pv, len,
b8c914
-		    (SvFLAGS(origsv) & SVf_UTF8) | SVs_TEMP);
b8c914
+	SvGETMAGIC(origsv);
b8c914
+#ifdef WIN32
b8c914
+	/*
b8c914
+	 * Because of a nasty platform-specific variation on the meaning
b8c914
+	 * of arguments to this op, we must preserve numeric arguments
b8c914
+	 * as numeric, not just retain the string value.
b8c914
+	 */
b8c914
+	if (SvNIOK(origsv) || SvNIOKp(origsv)) {
b8c914
+	    copysv = newSV_type(SVt_PVNV);
b8c914
+	    sv_2mortal(copysv);
b8c914
+	    if (SvPOK(origsv) || SvPOKp(origsv)) {
b8c914
+		pv = SvPV_nomg(origsv, len);
b8c914
+		sv_setpvn(copysv, pv, len);
b8c914
+		SvPOK_off(copysv);
b8c914
+	    }
b8c914
+	    if (SvIOK(origsv) || SvIOKp(origsv))
b8c914
+		SvIV_set(copysv, SvIVX(origsv));
b8c914
+	    if (SvNOK(origsv) || SvNOKp(origsv))
b8c914
+		SvNV_set(copysv, SvNVX(origsv));
b8c914
+	    SvFLAGS(copysv) |= SvFLAGS(origsv) &
b8c914
+		(SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK|
b8c914
+		    SVf_UTF8|SVf_IVisUV);
b8c914
+	} else
b8c914
+#endif
b8c914
+	{
b8c914
+	    pv = SvPV_nomg(origsv, len);
b8c914
+	    copysv = newSVpvn_flags(pv, len,
b8c914
+			(SvFLAGS(origsv) & SVf_UTF8) | SVs_TEMP);
b8c914
+	}
b8c914
+	*MARK = copysv;
b8c914
     }
b8c914
     MARK = ORIGMARK;
b8c914
 
b8c914
-- 
b8c914
2.13.6
b8c914