Skip to content

Commit 94caec9

Browse files
committed
remove PERL_STRICT_CR
Background: ----------- Before perl 5.004, the perl parser would skip over CR (carriage return) between tokens in source files, treating it as whitespace, but would retain CRs in quoted constructs such as multi-line strings and here-documents. In 5.004, the behavior was changed to make CR in source files a fatal error ("Illegal character %s (carriage return)") to avoid surprises with unexpected literal CRs in string constants when scripts were copied from DOS/Windows without newline conversion. In 5.005, the behavior changed again. Now CR was back to being ignored, but harder: Even in quoted constructs, CR was ignored when immediately followed by a newline. However, the 5.004 behavior could be restored by compiling perl with the `PERL_STRICT_CR` macro defined (e.g. with `./Configure -A ccflags=-DPERL_STRICT_CR ...`). This option was undocumented except for a brief note in perl5005delta. (Also, the "Illegal character ..." error was changed to a warning, but perldiag wasn't updated and so still listed the message as "fatal" (F).) And that's how things have been ever since 1998. Foreground: ----------- This patch removes all checks for PERL_STRICT_CR entirely, treating it as always off. Rationale: It simplifies the code and reduces clutter. (Plus I don't see the need to perpetually maintain an undocumented configuration option that enables compatibility with an ancient perl version used sometime around 1997-1998.) References: ----------- - 4fdae80 ("Make \r in script an error (per Larry)") - ff0cee6 ("Fix carriage-return message") - 5431012 ("Improve diagnostic on \r in program text") - 2db4f57 - f63a84b - 637e912 - b8957cf - 6a27c18
1 parent f0e1638 commit 94caec9

File tree

5 files changed

+16
-44
lines changed

5 files changed

+16
-44
lines changed

perl.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,9 +2231,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
22312231
reswitch:
22322232
switch ((c = *s)) {
22332233
case 'C':
2234-
#ifndef PERL_STRICT_CR
22352234
case '\r':
2236-
#endif
22372235
case ' ':
22382236
case '0':
22392237
case 'F':
@@ -3955,9 +3953,7 @@ Perl_moreswitches(pTHX_ const char *s)
39553953
break;
39563954
case '-':
39573955
case 0:
3958-
#if defined(WIN32) || !defined(PERL_STRICT_CR)
39593956
case '\r':
3960-
#endif
39613957
case '\n':
39623958
case '\t':
39633959
break;

pod/perldelta.pod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ L</Platform Support> section, instead.
256256

257257
XXX
258258

259+
=item *
260+
261+
The (mostly undocumented) configuration macro C<PERL_STRICT_CR> has been
262+
removed. When enabled (e.g. with C<./Configure -A ccflags=-DPERL_STRICT_CR>),
263+
it would make the perl parser throw a fatal error when it encountered a CR
264+
(carriage return) character in source files. The default (and now only)
265+
behavior of the perl parser is to strip CRs paired with newline characters and
266+
otherwise treat them as whitespace.
267+
268+
(C<PERL_STRICT_CR> was originally introduced in perl 5.005 to optionally
269+
restore backward compatibility with perl 5.004, which had made CR in source
270+
files an error. Before that, CR was accepted, but retained literally in quoted
271+
multi-line constructs such as here-documents, even at the end of a line.)
272+
259273
=back
260274

261275
=head1 Testing

pod/perldiag.pod

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,14 +2889,6 @@ declaration. The '_' in a prototype must be followed by a ';',
28892889
indicating the rest of the parameters are optional, or one of '@'
28902890
or '%', since those two will accept 0 or more final parameters.
28912891

2892-
=item Illegal character \%o (carriage return)
2893-
2894-
(F) Perl normally treats carriage returns in the program text as
2895-
it would any other whitespace, which means you should never see
2896-
this error when Perl was built using standard options. For some
2897-
reason, your version of Perl appears to have been built without
2898-
this support. Talk to your Perl administrator.
2899-
29002892
=item Illegal character following sigil in a subroutine signature
29012893

29022894
(F) A parameter in a subroutine signature contained an unexpected character

t/porting/diag.t

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,6 @@ Wrong syntax (suid) fd script name "%s"
740740
741741
__CATEGORIES__
742742
743-
# This is a warning, but is currently followed immediately by a croak (toke.c)
744-
Illegal character \%o (carriage return)
745-
746743
# Because uses WARN_MISSING as a synonym for WARN_UNINITIALIZED (sv.c)
747744
Missing argument in %s
748745

toke.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9244,13 +9244,7 @@ yyl_try(pTHX_ char *s)
92449244
return tok;
92459245
goto retry_bufptr;
92469246

9247-
case '\r':
9248-
#ifdef PERL_STRICT_CR
9249-
Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
9250-
Perl_croak(aTHX_
9251-
"\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
9252-
#endif
9253-
case ' ': case '\t': case '\f': case '\v':
9247+
case ' ': case '\t': case '\f': case '\r': case '\v':
92549248
s++;
92559249
goto retry;
92569250

@@ -9394,11 +9388,7 @@ yyl_try(pTHX_ char *s)
93949388
}
93959389
if (PL_expect == XBLOCK) {
93969390
const char *t = s;
9397-
while (SPACE_OR_TAB(*t)
9398-
#ifndef PERL_STRICT_CR
9399-
|| *t == '\r'
9400-
#endif
9401-
)
9391+
while (SPACE_OR_TAB(*t) || *t == '\r')
94029392
t++;
94039393
if (*t == '\n' || *t == '#') {
94049394
ENTER_with_name("lex_format");
@@ -9460,11 +9450,7 @@ yyl_try(pTHX_ char *s)
94609450

94619451
case '.':
94629452
if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
9463-
#ifdef PERL_STRICT_CR
9464-
&& s[1] == '\n'
9465-
#else
94669453
&& (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
9467-
#endif
94689454
&& (s == PL_linestart || s[-1] == '\n') )
94699455
{
94709456
PL_expect = XSTATE;
@@ -11016,7 +11002,6 @@ S_scan_heredoc(pTHX_ char *s)
1101611002
*d = '\0';
1101711003
len = d - PL_tokenbuf;
1101811004

11019-
#ifndef PERL_STRICT_CR
1102011005
d = (char *) memchr(s, '\r', PL_bufend - s);
1102111006
if (d) {
1102211007
char * const olds = s;
@@ -11039,7 +11024,6 @@ S_scan_heredoc(pTHX_ char *s)
1103911024
SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
1104011025
s = olds;
1104111026
}
11042-
#endif
1104311027

1104411028
tmpstr = newSV_type(SVt_PVIV);
1104511029
if (term == '\'') {
@@ -11245,7 +11229,6 @@ S_scan_heredoc(pTHX_ char *s)
1124511229
PL_parser->herelines++;
1124611230
PL_last_lop = PL_last_uni = NULL;
1124711231

11248-
#ifndef PERL_STRICT_CR
1124911232
if (PL_bufend - PL_linestart >= 2) {
1125011233
if ( (PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n')
1125111234
|| (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
@@ -11259,7 +11242,6 @@ S_scan_heredoc(pTHX_ char *s)
1125911242
}
1126011243
else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
1126111244
PL_bufend[-1] = '\n';
11262-
#endif
1126311245

1126411246
if (indented && (PL_bufend-s) >= len) {
1126511247
char * found = ninstr(s, PL_bufend, (PL_tokenbuf + 1), (PL_tokenbuf +1 + len));
@@ -11852,7 +11834,6 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int
1185211834
if (s < PL_bufend)
1185311835
break; /* handle case where we are done yet :-) */
1185411836

11855-
#ifndef PERL_STRICT_CR
1185611837
if (to - SvPVX_const(sv) >= 2) {
1185711838
if ( (to[-2] == '\r' && to[-1] == '\n')
1185811839
|| (to[-2] == '\n' && to[-1] == '\r'))
@@ -11866,7 +11847,6 @@ Perl_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int
1186611847
}
1186711848
else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
1186811849
to[-1] = '\n';
11869-
#endif
1187011850

1187111851
/* if we're out of file, or a read fails, bail and reset the current
1187211852
line marker so we can report where the unterminated string began
@@ -12611,13 +12591,8 @@ S_scan_formline(pTHX_ char *s)
1261112591
char *eol;
1261212592
if (*s == '.') {
1261312593
char *t = s+1;
12614-
#ifdef PERL_STRICT_CR
12615-
while (SPACE_OR_TAB(*t))
12616-
t++;
12617-
#else
1261812594
while (SPACE_OR_TAB(*t) || *t == '\r')
1261912595
t++;
12620-
#endif
1262112596
if (*t == '\n' || t == PL_bufend) {
1262212597
eofmt = TRUE;
1262312598
break;
@@ -12642,14 +12617,12 @@ S_scan_formline(pTHX_ char *s)
1264212617
}
1264312618
if (eol > s) {
1264412619
sv_catpvn(stuff, s, eol-s);
12645-
#ifndef PERL_STRICT_CR
1264612620
if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
1264712621
char *end = SvPVX(stuff) + SvCUR(stuff);
1264812622
end[-2] = '\n';
1264912623
end[-1] = '\0';
1265012624
SvCUR_set(stuff, SvCUR(stuff) - 1);
1265112625
}
12652-
#endif
1265312626
}
1265412627
else
1265512628
break;

0 commit comments

Comments
 (0)