Skip to content

Commit be13138

Browse files
committed
pp_ctl.c - Consistently exit after 10 errors
Currently we only check the error count when we report an error via yyerror(), even though we say we will stop processing after 10 errors. Errors reported directly to qerror() bypass the check. This fixes this so that we check the number of errors reported in qerror() itself. We also change qerror() so that qerror(NULL) triggers the exception, this way we can move the logic out of yyerror and into qerror().
1 parent d060070 commit be13138

File tree

6 files changed

+46
-44
lines changed

6 files changed

+46
-44
lines changed

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ Apd |SV* |mess_sv |NN SV* basemsg|bool consume
13951395
Apd |SV* |vmess |NN const char* pat|NULLOK va_list* args
13961396
: FIXME - either make it public, or stop exporting it. (Data::Alias uses this)
13971397
: Used in gv.c, op.c, toke.c
1398-
EXp |void |qerror |NN SV* err
1398+
EXp |void |qerror |NULLOK SV* err
13991399
Apd |void |sortsv |NULLOK SV** array|size_t num_elts|NN SVCOMPARE_t cmp
14001400
Apd |void |sortsv_flags |NULLOK SV** array|size_t num_elts|NN SVCOMPARE_t cmp|U32 flags
14011401
Apd |int |mg_clear |NN SV* sv

pp_ctl.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,27 +1656,53 @@ void
16561656
Perl_qerror(pTHX_ SV *err)
16571657
{
16581658
PERL_ARGS_ASSERT_QERROR;
1659-
1660-
if (PL_in_eval) {
1661-
if (PL_in_eval & EVAL_KEEPERR) {
1662-
Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf,
1663-
SVfARG(err));
1659+
if (err!=NULL) {
1660+
if (PL_in_eval) {
1661+
if (PL_in_eval & EVAL_KEEPERR) {
1662+
Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf,
1663+
SVfARG(err));
1664+
}
1665+
else {
1666+
sv_catsv(ERRSV, err);
1667+
}
16641668
}
1669+
else if (PL_errors)
1670+
sv_catsv(PL_errors, err);
16651671
else
1666-
sv_catsv(ERRSV, err);
1672+
Perl_warn(aTHX_ "%" SVf, SVfARG(err));
1673+
1674+
if (PL_parser) {
1675+
++PL_parser->error_count;
1676+
}
16671677
}
1668-
else if (PL_errors)
1669-
sv_catsv(PL_errors, err);
1670-
else
1671-
Perl_warn(aTHX_ "%" SVf, SVfARG(err));
16721678

1673-
if (PL_parser) {
1674-
++PL_parser->error_count;
1679+
if ( PL_parser && (err == NULL ||
1680+
PL_parser->error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS)
1681+
) {
1682+
const char * const name = OutCopFILE(PL_curcop);
1683+
SV * errsv = NULL;
1684+
U8 raw_error_count = PERL_PARSE_ERROR_COUNT(PL_parser->error_count);
1685+
1686+
if (PL_in_eval) {
1687+
errsv = ERRSV;
1688+
}
1689+
1690+
if (err == NULL) {
1691+
abort_execution(errsv, name);
1692+
}
1693+
else
1694+
if (raw_error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS) {
1695+
if (errsv) {
1696+
Perl_croak(aTHX_ "%" SVf "%s has too many errors.\n",
1697+
SVfARG(errsv), name);
1698+
} else {
1699+
Perl_croak(aTHX_ "%s has too many errors.\n", name);
1700+
}
1701+
}
16751702
}
16761703
}
16771704

16781705

1679-
16801706
/* pop a CXt_EVAL context and in addition, if it was a require then
16811707
* based on action:
16821708
* 0: do nothing extra;

proto.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,8 +3258,7 @@ PERL_CALLCONV char* Perl_pv_uni_display(pTHX_ SV *dsv, const U8 *spv, STRLEN len
32583258
#define PERL_ARGS_ASSERT_PV_UNI_DISPLAY \
32593259
assert(dsv); assert(spv)
32603260
PERL_CALLCONV void Perl_qerror(pTHX_ SV* err);
3261-
#define PERL_ARGS_ASSERT_QERROR \
3262-
assert(err)
3261+
#define PERL_ARGS_ASSERT_QERROR
32633262
PERL_CALLCONV REGEXP* Perl_re_compile(pTHX_ SV * const pattern, U32 orig_rx_flags);
32643263
#define PERL_ARGS_ASSERT_RE_COMPILE \
32653264
assert(pattern)

t/lib/feature/bundle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ EXPECT
110110
Number found where operator expected at (eval 1) line 1, near "evalbytes 12345"
111111
(Do you need to predeclare evalbytes?)
112112
syntax error at (eval 1) line 1, near "evalbytes 12345"
113+
Execution of (eval 1) aborted due to compilation errors.

t/lib/strict/vars

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ Global symbol "$m" requires explicit package name (did you forget to declare "my
213213
Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at abc.pm line 6.
214214
Global symbol "$i" requires explicit package name (did you forget to declare "my $i"?) at abc.pm line 6.
215215
Global symbol "$n" requires explicit package name (did you forget to declare "my $n"?) at abc.pm line 6.
216-
Global symbol "$e" requires explicit package name (did you forget to declare "my $e"?) at abc.pm line 7.
217-
Global symbol "$j" requires explicit package name (did you forget to declare "my $j"?) at abc.pm line 7.
218-
Global symbol "$o" requires explicit package name (did you forget to declare "my $o"?) at abc.pm line 7.
219-
Global symbol "$p" requires explicit package name (did you forget to declare "my $p"?) at abc.pm line 8.
220-
Illegal binary digit '2' at abc.pm line 8, at end of line
221216
abc.pm has too many errors.
222217
Compilation failed in require at - line 1.
223218
BEGIN failed--compilation aborted at - line 1.

toke.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12654,30 +12654,11 @@ Perl_yyerror_pvn(pTHX_ const char *const s, STRLEN len, U32 flags)
1265412654
qerror(msg);
1265512655
}
1265612656
}
12657-
if ( s == NULL ||
12658-
PL_error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS
12659-
) {
12660-
const char * const name = OutCopFILE(PL_curcop);
12661-
SV * errsv = NULL;
12662-
U8 raw_error_count = PERL_PARSE_ERROR_COUNT(PL_error_count);
12663-
12664-
if (PL_in_eval) {
12665-
errsv = ERRSV;
12666-
}
12657+
/* if there was no message then this is a yyquit(), which is actualy handled
12658+
* by qerror() with a NULL argument */
12659+
if (s == NULL)
12660+
qerror(NULL);
1266712661

12668-
if (s == NULL) {
12669-
abort_execution(errsv, name);
12670-
}
12671-
else
12672-
if (raw_error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS) {
12673-
if (errsv) {
12674-
Perl_croak(aTHX_ "%" SVf "%s has too many errors.\n",
12675-
SVfARG(errsv), name);
12676-
} else {
12677-
Perl_croak(aTHX_ "%s has too many errors.\n", name);
12678-
}
12679-
}
12680-
}
1268112662
PL_in_my = 0;
1268212663
PL_in_my_stash = NULL;
1268312664
return 0;

0 commit comments

Comments
 (0)