Blame SOURCES/perl-5.25.2-perl-128508-Fix-line-numbers-with-perl-x.patch

276c98
From b3dd0aba3d2bf0b22280303ef6f068e976e31888 Mon Sep 17 00:00:00 2001
276c98
From: Father Chrysostomos <sprout@cpan.org>
276c98
Date: Sat, 2 Jul 2016 00:08:48 -0700
276c98
Subject: [PATCH] [perl #128508] Fix line numbers with perl -x
276c98
MIME-Version: 1.0
276c98
Content-Type: text/plain; charset=UTF-8
276c98
Content-Transfer-Encoding: 8bit
276c98
276c98
When lex_start is invoked with an SV and a handle pointer, it expects
276c98
the SV to contain the beginning of the code to be parsed.  The handle
276c98
will be read from for subsequent code.
276c98
276c98
The -x command line option happens to invoke lex_start with two non-
276c98
null pointers like this (a line and a handle), since, to find the
276c98
#!perl line, it has to read that first line out of the file handle.
276c98
276c98
There is a line of code in lex_start that adds "\n;" to the buffer
276c98
goes back to 8990e30710 (perl 5.0 alpha 6) and string eval fails
276c98
catastrophically without it.
276c98
276c98
As of v5.19.1-485-g2179133 multiple lines are supported in the current
276c98
parsing buffer (PL_linestr) when there is a file handle, and as of
276c98
v5.19.3-63-gbf1b738 the line number is correctly incremented when the
276c98
parser goes past a newline.
276c98
276c98
So, for -x, "#!perl\n" turns into "#!perl\n\n" (the final ; is skipped
276c98
as of v5.19.3-63-gbf1b738 if there is a handle).  That throws line
276c98
numbers off by one.
276c98
276c98
In the case where we have a string to parse and a file handle, the
276c98
extra "\n;" added to the end of the buffer turns out to be completely
276c98
unnecessary.  So this commit makes it conditional on rsfp.
276c98
276c98
The existing tests for -x are quite exotic.  I have made no effort to
276c98
make them less so.
276c98
276c98
Signed-off-by: Petr Písař <ppisar@redhat.com>
276c98
---
276c98
 t/run/switchx.aux | 7 ++++---
276c98
 t/run/switchx.t   | 4 ++--
276c98
 toke.c            | 3 ++-
276c98
 3 files changed, 8 insertions(+), 6 deletions(-)
276c98
276c98
diff --git a/t/run/switchx.aux b/t/run/switchx.aux
276c98
index b59df4a..106b2f7 100644
276c98
--- a/t/run/switchx.aux
276c98
+++ b/t/run/switchx.aux
276c98
@@ -17,11 +17,12 @@ still not perl
276c98
 
276c98
 #!/some/path/that/leads/to/perl -l
276c98
 
276c98
-print "1..7";
276c98
+print "1..8";
276c98
+print "ok 1 - Correct line number" if __LINE__ == 4;
276c98
 if (-f 'run/switchx.aux') {
276c98
-    print "ok 1 - Test file exists";
276c98
+    print "ok 2 - Test file exists";
276c98
 }
276c98
-print "ok 2 - Test file utilized";
276c98
+print "ok 3 - Test file utilized";
276c98
 # other tests are in switchx2.aux
276c98
 
276c98
 __END__
276c98
diff --git a/t/run/switchx.t b/t/run/switchx.t
276c98
index bcea3d0..4e57d04 100644
276c98
--- a/t/run/switchx.t
276c98
+++ b/t/run/switchx.t
276c98
@@ -15,9 +15,9 @@ print runperl( switches => ['-x'],
276c98
 # Test '-xdir'
276c98
 print runperl( switches => ['-x./run'],
276c98
                progfile => 'run/switchx2.aux',
276c98
-               args     => [ 3 ] );
276c98
+               args     => [ 4 ] );
276c98
 
276c98
-curr_test(5);
276c98
+curr_test(6);
276c98
 
276c98
 # Test the error message for not found
276c98
 like(runperl(switches => ['-x'], progfile => 'run/switchx3.aux', stderr => 1),
276c98
diff --git a/toke.c b/toke.c
276c98
index aebeebb..7e77fae 100644
276c98
--- a/toke.c
276c98
+++ b/toke.c
276c98
@@ -723,7 +723,8 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
276c98
 	parser->linestr = flags & LEX_START_COPIED
276c98
 			    ? SvREFCNT_inc_simple_NN(line)
276c98
 			    : newSVpvn_flags(s, len, SvUTF8(line));
276c98
-	sv_catpvn(parser->linestr, "\n;", rsfp ? 1 : 2);
276c98
+	if (!rsfp)
276c98
+	    sv_catpvs(parser->linestr, "\n;");
276c98
     } else {
276c98
 	parser->linestr = newSVpvn("\n;", rsfp ? 1 : 2);
276c98
     }
276c98
-- 
276c98
2.5.5
276c98