Skip to content

Commit

Permalink
toke.c: remove PERL_CR_FILTER
Browse files Browse the repository at this point in the history
When enabled (e.g. with `./Configure -A ccflags=-DPERL_CR_FILTER`), this
would define an implicit source filter that turns \r\n pairs into \n
whenever the parser reads a line of Perl source code.

As far as I can tell, perl already does the equivalent of this (without
a source filter) on all platforms and has done so since 5.005.

(Also, the code could read out-of-bounds if the last character of the
line read was a \r.)
  • Loading branch information
mauke committed Nov 28, 2024
1 parent 8d585c6 commit c68c3ab
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 67 deletions.
6 changes: 0 additions & 6 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -5970,12 +5970,6 @@ Sf |void |printbuf |NN const char * const fmt \
S |int |tokereport |I32 rv \
|NN const YYSTYPE *lvalp
# endif
# if defined(PERL_CR_FILTER)
S |I32 |cr_textfilter |int idx \
|NULLOK SV *sv \
|int maxlen
S |void |strip_return |NN SV *sv
# endif
# if !defined(PERL_NO_UTF16_FILTER)
S |U8 * |add_utf16_textfilter \
|NN U8 * const s \
Expand Down
4 changes: 0 additions & 4 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1730,10 +1730,6 @@
# define printbuf(a,b) S_printbuf(aTHX_ a,b)
# define tokereport(a,b) S_tokereport(aTHX_ a,b)
# endif
# if defined(PERL_CR_FILTER)
# define cr_textfilter(a,b,c) S_cr_textfilter(aTHX_ a,b,c)
# define strip_return(a) S_strip_return(aTHX_ a)
# endif
# if !defined(PERL_NO_UTF16_FILTER)
# define add_utf16_textfilter(a,b) S_add_utf16_textfilter(aTHX_ a,b)
# define utf16_textfilter(a,b,c) S_utf16_textfilter(aTHX_ a,b,c)
Expand Down
11 changes: 0 additions & 11 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 5 additions & 46 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,47 +800,6 @@ S_scan_terminated(pTHX_ char *s, I32 ival) {

#include "feature.h"

/*
* experimental text filters for win32 carriage-returns, utf16-to-utf8 and
* utf16-to-utf8-reversed.
*/

#ifdef PERL_CR_FILTER
static void
strip_return(SV *sv)
{
const char *s = SvPVX_const(sv);
const char * const e = s + SvCUR(sv);

PERL_ARGS_ASSERT_STRIP_RETURN;

/* outer loop optimized to do nothing if there are no CR-LFs */
while (s < e) {
if (*s++ == '\r' && *s == '\n') {
/* hit a CR-LF, need to copy the rest */
char *d = s - 1;
*d++ = *s++;
while (s < e) {
if (*s == '\r' && s[1] == '\n')
s++;
*d++ = *s++;
}
SvCUR(sv) -= s - d;
return;
}
}
}

STATIC I32
S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
{
const I32 count = FILTER_READ(idx+1, sv, maxlen);
if (count > 0 && !maxlen)
strip_return(sv);
return count;
}
#endif

STATIC void
S_yyerror_non_ascii_message(pTHX_ const U8 * const s)
{
Expand Down Expand Up @@ -5126,11 +5085,6 @@ S_filter_gets(pTHX_ SV *sv, STRLEN append)
{
PERL_ARGS_ASSERT_FILTER_GETS;

#ifdef PERL_CR_FILTER
if (!PL_rsfp_filters) {
filter_add(S_cr_textfilter,NULL);
}
#endif
if (PL_rsfp_filters) {
if (!append)
SvCUR_set(sv, 0); /* start with empty line */
Expand Down Expand Up @@ -13091,6 +13045,11 @@ S_swallow_bom(pTHX_ U8 *s)


#ifndef PERL_NO_UTF16_FILTER
/*
* experimental text filter for utf16-to-utf8 and
* utf16-to-utf8-reversed.
*/

static I32
S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
{
Expand Down

0 comments on commit c68c3ab

Please sign in to comment.