diff options
author | Leon Timmermans <fawaka@gmail.com> | 2021-01-19 20:21:05 +0100 |
---|---|---|
committer | Leon Timmermans <fawaka@gmail.com> | 2021-01-30 21:09:54 +0100 |
commit | 034aa3082b067ebeeb73f269627b26aa149f6e6f (patch) | |
tree | b50b69d687e535071c94759858bacb9378e028b1 /ext/PerlIO-encoding | |
parent | 370c6ab2e9608a94096854c61d976ccf65bb2c13 (diff) | |
download | perl-034aa3082b067ebeeb73f269627b26aa149f6e6f.tar.gz |
Force disable LEAVE_SRC in $PerlIO::encoding::fallback
Setting $PerlIO::encoding::fallback to any value containing LEAVE_SRC
will result in an infinite loop of the first buffer of input. This is
never desirable.
Diffstat (limited to 'ext/PerlIO-encoding')
-rw-r--r-- | ext/PerlIO-encoding/encoding.xs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/PerlIO-encoding/encoding.xs b/ext/PerlIO-encoding/encoding.xs index 15709d24dd..9deb20bf26 100644 --- a/ext/PerlIO-encoding/encoding.xs +++ b/ext/PerlIO-encoding/encoding.xs @@ -6,9 +6,11 @@ #define OUR_DEFAULT_FB "Encode::PERLQQ" #define OUR_STOP_AT_PARTIAL "Encode::STOP_AT_PARTIAL" +#define OUR_LEAVE_SRC "Encode::LEAVE_SRC" /* This will be set during BOOT */ static unsigned int encode_stop_at_partial = 0; +static unsigned int encode_leave_src = 0; #if defined(USE_PERLIO) @@ -170,7 +172,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs * e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0)); if (SvROK(e->chk)) Perl_croak(aTHX_ "PerlIO::encoding::fallback must be an integer"); - SvUV_set(e->chk, SvUV(e->chk) | encode_stop_at_partial); + SvUV_set(e->chk, SvUV(e->chk) & ~encode_leave_src | encode_stop_at_partial); e->inEncodeCall = 0; FREETMPS; @@ -667,6 +669,15 @@ BOOT: SPAGAIN; encode_stop_at_partial = POPu; + PUSHMARK(sp); + PUTBACK; + if (call_pv(OUR_LEAVE_SRC, G_SCALAR) != 1) { + /* should never happen */ + Perl_die(aTHX_ "%s did not return a value", OUR_LEAVE_SRC); + } + SPAGAIN; + encode_leave_src = POPu; + PUTBACK; #ifdef PERLIO_LAYERS PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_encode)); |