diff options
author | Yves Orton <demerphq@gmail.com> | 2022-09-26 16:44:44 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-20 11:34:22 +0800 |
commit | 248b96b9665b816ea8d1c3415b674dabccf7190b (patch) | |
tree | 0396746d950c1122ba37856ef6bd77c23f1f61c1 /pp_ctl.c | |
parent | 21938ae5a278f0b48443561333c47714921e7566 (diff) | |
download | perl-248b96b9665b816ea8d1c3415b674dabccf7190b.tar.gz |
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().
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 52 |
1 files changed, 39 insertions, 13 deletions
@@ -1656,27 +1656,53 @@ void Perl_qerror(pTHX_ SV *err) { PERL_ARGS_ASSERT_QERROR; - - if (PL_in_eval) { - if (PL_in_eval & EVAL_KEEPERR) { - Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf, - SVfARG(err)); + if (err!=NULL) { + if (PL_in_eval) { + if (PL_in_eval & EVAL_KEEPERR) { + Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf, + SVfARG(err)); + } + else { + sv_catsv(ERRSV, err); + } } + else if (PL_errors) + sv_catsv(PL_errors, err); else - sv_catsv(ERRSV, err); + Perl_warn(aTHX_ "%" SVf, SVfARG(err)); + + if (PL_parser) { + ++PL_parser->error_count; + } } - else if (PL_errors) - sv_catsv(PL_errors, err); - else - Perl_warn(aTHX_ "%" SVf, SVfARG(err)); - if (PL_parser) { - ++PL_parser->error_count; + if ( PL_parser && (err == NULL || + PL_parser->error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS) + ) { + const char * const name = OutCopFILE(PL_curcop); + SV * errsv = NULL; + U8 raw_error_count = PERL_PARSE_ERROR_COUNT(PL_parser->error_count); + + if (PL_in_eval) { + errsv = ERRSV; + } + + if (err == NULL) { + abort_execution(errsv, name); + } + else + if (raw_error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS) { + if (errsv) { + Perl_croak(aTHX_ "%" SVf "%s has too many errors.\n", + SVfARG(errsv), name); + } else { + Perl_croak(aTHX_ "%s has too many errors.\n", name); + } + } } } - /* pop a CXt_EVAL context and in addition, if it was a require then * based on action: * 0: do nothing extra; |