Fix line numbers with perl -x

This commit is contained in:
Petr Písař 2016-07-04 12:32:23 +02:00
parent 754a66c1ac
commit b3a20db42c
2 changed files with 105 additions and 1 deletions

View File

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

View File

@ -28,7 +28,7 @@
Name: perl Name: perl
Version: %{perl_version} Version: %{perl_version}
# release number must be even higher, because dual-lived modules will be broken otherwise # release number must be even higher, because dual-lived modules will be broken otherwise
Release: 369%{?dist} Release: 370%{?dist}
Epoch: %{perl_epoch} Epoch: %{perl_epoch}
Summary: Practical Extraction and Report Language Summary: Practical Extraction and Report Language
Group: Development/Languages Group: Development/Languages
@ -139,6 +139,9 @@ Patch36: perl-5.25.2-only-treat-stash-entries-with-.-as-sub-stashes.patch
# in upstream after 5.25.2 # in upstream after 5.25.2
Patch37: perl-5.25.2-perl-128238-Crash-with-non-stash-in-stash.patch Patch37: perl-5.25.2-perl-128238-Crash-with-non-stash-in-stash.patch
# Fix line numbers with perl -x, RT#128508, in upstream after 5.25.2
Patch38: perl-5.25.2-perl-128508-Fix-line-numbers-with-perl-x.patch
# Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048 # Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@ -2795,6 +2798,7 @@ Perl extension for Version Objects
%patch35 -p1 %patch35 -p1
%patch36 -p1 %patch36 -p1
%patch37 -p1 %patch37 -p1
%patch38 -p1
%patch200 -p1 %patch200 -p1
%patch201 -p1 %patch201 -p1
@ -2823,6 +2827,7 @@ perl -x patchlevel.h \
'Fedora Patch35: Fix precedence in hv_ename_delete (RT#128086)' \ 'Fedora Patch35: Fix precedence in hv_ename_delete (RT#128086)' \
'Fedora Patch36: Do not treat %: as a stash (RT#128238)' \ 'Fedora Patch36: Do not treat %: as a stash (RT#128238)' \
'Fedora Patch37: Do not crash when inserting a non-stash into a stash (RT#128238)' \ 'Fedora Patch37: Do not crash when inserting a non-stash into a stash (RT#128238)' \
'Fedora Patch38: Fix line numbers with perl -x (RT#128508)' \
'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \ 'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \
'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \ 'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
%{nil} %{nil}
@ -5089,6 +5094,9 @@ popd
# Old changelog entries are preserved in CVS. # Old changelog entries are preserved in CVS.
%changelog %changelog
* Mon Jul 04 2016 Petr Pisar <ppisar@redhat.com> - 4:5.24.0-370
- Fix line numbers with perl -x (RT#128508)
* Fri Jun 24 2016 Petr Pisar <ppisar@redhat.com> - 4:5.24.0-369 * Fri Jun 24 2016 Petr Pisar <ppisar@redhat.com> - 4:5.24.0-369
- Do not crash when inserting a non-stash into a stash (RT#128238) - Do not crash when inserting a non-stash into a stash (RT#128238)