ptable_delete(MY_CXT.map, o);
}
+/* --- Safe version of call_sv() ------------------------------------------- */
+
+static I32 indirect_call_sv(pTHX_ SV *sv, I32 flags) {
+#define indirect_call_sv(S, F) indirect_call_sv(aTHX_ (S), (F))
+ I32 ret, cxix;
+ PERL_CONTEXT saved_cx;
+ SV *saved_errsv = NULL;
+
+ if (SvTRUE(ERRSV)) {
+ if (IN_PERL_COMPILETIME && PL_errors)
+ sv_catsv(PL_errors, ERRSV);
+ else
+ saved_errsv = newSVsv(ERRSV);
+ SvCUR_set(ERRSV, 0);
+ }
+
+ cxix = (cxstack_ix < cxstack_max) ? (cxstack_ix + 1) : Perl_cxinc(aTHX);
+ /* The last popped context will be reused by call_sv(), but our callers may
+ * still need its previous value. Back it up so that it isn't clobbered. */
+ saved_cx = cxstack[cxix];
+
+ ret = call_sv(sv, flags | G_EVAL);
+
+ cxstack[cxix] = saved_cx;
+
+ if (SvTRUE(ERRSV)) {
+ /* Discard the old ERRSV, and reuse the variable to temporarily store the
+ * new one. */
+ if (saved_errsv)
+ sv_setsv(saved_errsv, ERRSV);
+ else
+ saved_errsv = newSVsv(ERRSV);
+ SvCUR_set(ERRSV, 0);
+ /* Immediately flush all errors. */
+ if (IN_PERL_COMPILETIME) {
+#if I_HAS_PERL(5, 10, 0) || defined(PL_parser)
+ if (PL_parser)
+ ++PL_parser->error_count;
+#elif defined(PL_error_count)
+ ++PL_error_count;
+#else
+ ++PL_Ierror_count;
+#endif
+ if (PL_errors) {
+ sv_setsv(ERRSV, PL_errors);
+ SvCUR_set(PL_errors, 0);
+ }
+ }
+ sv_catsv(ERRSV, saved_errsv);
+ SvREFCNT_dec(saved_errsv);
+ croak(NULL);
+ } else if (saved_errsv) {
+ /* If IN_PERL_COMPILETIME && PL_errors, then the old ERRSV has already been
+ * added to PL_errors. Otherwise, just restore it to ERRSV, as if no eval
+ * block has ever been executed. */
+ sv_setsv(ERRSV, saved_errsv);
+ SvREFCNT_dec(saved_errsv);
+ }
+
+ return ret;
+}
+
/* --- Check functions ----------------------------------------------------- */
static int indirect_find(pTHX_ SV *name_sv, const char *line_bufptr, STRLEN *name_pos) {
mPUSHu(moi->line);
PUTBACK;
- call_sv(code, G_VOID);
+ indirect_call_sv(code, G_VOID);
PUTBACK;
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use lib 't/lib';
+use VPIT::TestHelpers 'capture';
+
+BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
+
+sub compile_err_code {
+ my ($fatal) = @_;
+
+ if ($fatal) {
+ $fatal = 'no indirect q[fatal]; sub foo { \$bar }';
+ } else {
+ $fatal = 'no indirect;';
+ }
+
+ return "use strict; use warnings; $fatal; baz \$_; sub qux { \$ook }";
+}
+
+my $indirect_msg = qr/Indirect call of method "baz" on object "\$_"/;
+my $core_err1 = qr/Global symbol "\$bar"/;
+my $core_err2 = qr/Global symbol "\$ook"/;
+my $aborted = qr/Execution of -e aborted due to compilation errors\./;
+my $line_end = qr/[^\n]*\n/;
+my $compile_err_warn_exp = qr/$indirect_msg$line_end$core_err2$line_end/o;
+my $compile_err_fatal_exp = qr/$core_err1$line_end$indirect_msg$line_end/o;
+
+SKIP: {
+ my ($stat, $out, $err) = capture_perl compile_err_code(0);
+ skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
+ like $err, qr/\A$compile_err_warn_exp$aborted$line_end\z/o,
+ 'no indirect warn does not hide compilation errors outside of eval';
+}
+
+SKIP: {
+ my $code = compile_err_code(0);
+ my ($stat, $out, $err) = capture_perl "eval q[$code]; die \$@ if \$@";
+ skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
+ like $err, qr/\A$compile_err_warn_exp\z/o,
+ 'no indirect warn does not hide compilation errors inside of eval';
+}
+
+SKIP: {
+ my ($stat, $out, $err) = capture_perl compile_err_code(1);
+ skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
+ like $err, qr/\A$compile_err_fatal_exp\z/o,
+ 'no indirect fatal does not hide compilation errors outside of eval';
+}
+
+{
+ local $@;
+ eval compile_err_code(1);
+ like $@, qr/\A$compile_err_fatal_exp\z/o,
+ 'no indirect fatal does not hide compilation errors inside of eval';
+}