New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] local PerlIO::encoding::fallback settings + encoding causing infinite loop #15117
Comments
From zhouzhen1@gmail.comCreated by zhouzhen1@gmail.comI saw the issue when I use File::Slurper + Data::Table together in one use 5.022; my $file1 = '/tmp/foo'; { # what's in File::Slurper { # what's in Data::Table It can also be simplified to like below. use 5.022; my $file1 = '/tmp/foo'; { { Perl Info
|
From @tonycozOn Mon Jan 04 06:12:19 2016, zhouzhen1@gmail.com wrote:
The problem is that since PerlIO::encoding is loaded within the local's block, $PerlIO::encoding::fallback is restored to it's original value This can be prevented by explicitly loading PerlIO::encoding before localizing $PerlIO::encoding::fallback Also, since PerlIO::encoding is loaded *after* you initialized fallback, it's being reset to the default set in PerlIO/encoding.pm before the value is used. That said, PerlIO::encoding shouldn't go into an infinite loop, the attached patch fixes that for this case by ensuring the STOP_AT_PARTIAL flag is set, which is needed for decoding. Tony |
From @tonycoz0001-perl-127149-ensure-the-CHECK-value-has-STOP_AT_PARTI.patchFrom 460df6ceb4e243f5e2b68e72c445fc4e1e883897 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 13 Jan 2016 12:11:45 +1100
Subject: [perl #127149] ensure the CHECK value has STOP_AT_PARTIAL
This flag is required for PerlIO::encoding to do its job.
Also document the race between localizing
$PerlIO::encoding::fallback and loading PerlIO::encoding.
---
ext/PerlIO-encoding/encoding.pm | 7 ++++++-
ext/PerlIO-encoding/encoding.xs | 5 ++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ext/PerlIO-encoding/encoding.pm b/ext/PerlIO-encoding/encoding.pm
index 7bae036..df1ded6 100644
--- a/ext/PerlIO-encoding/encoding.pm
+++ b/ext/PerlIO-encoding/encoding.pm
@@ -1,7 +1,7 @@
package PerlIO::encoding;
use strict;
-our $VERSION = '0.23';
+our $VERSION = '0.24';
our $DEBUG = 0;
$DEBUG and warn __PACKAGE__, " called by ", join(", ", caller), "\n";
@@ -46,6 +46,11 @@ When the layer is pushed, the current value of C<$PerlIO::encoding::fallback>
is saved and used as the CHECK argument when calling the Encode methods
encode() and decode().
+Note: localizing C<$PerlIO::encoding::fallback> without
+PerlIO::encoding being loaded and then using the C<:encoding> layer
+will leave C<$PerlIO::encoding::fallback> as C<undef> at the end of
+the scope.
+
=head1 SEE ALSO
L<open>, L<Encode>, L<perlfunc/binmode>, L<perluniintro>
diff --git a/ext/PerlIO-encoding/encoding.xs b/ext/PerlIO-encoding/encoding.xs
index 3e4645c..599728c 100644
--- a/ext/PerlIO-encoding/encoding.xs
+++ b/ext/PerlIO-encoding/encoding.xs
@@ -6,6 +6,9 @@
#define OUR_DEFAULT_FB "Encode::PERLQQ"
+/* from Encode's encode.h */
+#define ENCODE_STOP_AT_PARTIAL 0x0800 /* stop at partial explicitly */
+
#if defined(USE_PERLIO)
/* Define an encoding "layer" in the perliol.h sense.
@@ -163,7 +166,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
PerlIOBase(f)->flags |= PERLIO_F_UTF8;
}
- e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0));
+ e->chk = newSViv(SvIV(get_sv("PerlIO::encoding::fallback", 0)) | ENCODE_STOP_AT_PARTIAL);
e->inEncodeCall = 0;
FREETMPS;
--
2.1.4
|
The RT System itself - Status changed from 'new' to 'open' |
Migrated from rt.perl.org#127149 (status was 'open')
Searchable as RT127149$
The text was updated successfully, but these errors were encountered: