va_list ap;
SV *svr;
int ret;
- unsigned int i, args, opinfo, eval;
+ unsigned int i, args, opinfo, eval, has_err = 0;
dSP;
args = flags & VMG_CB_CALL_ARGS_MASK;
flags >>= VMG_CB_CALL_ARGS_SHIFT;
opinfo = flags & VMG_CB_CALL_OPINFO;
- eval = flags & VMG_CB_CALL_EVAL ? G_EVAL : 0;
+ eval = flags & VMG_CB_CALL_EVAL;
ENTER;
SAVETMPS;
XPUSHs(vmg_op_info(opinfo));
PUTBACK;
- call_sv(cb, G_SCALAR | eval);
+ if (!eval) {
+ call_sv(cb, G_SCALAR);
+ } else {
+ unsigned int flags = G_SCALAR | G_EVAL;
+ unsigned int had_err = SvTRUE(ERRSV);
+ if (had_err)
+ flags |= G_KEEPERR;
+ call_sv(cb, flags);
+ has_err = SvTRUE(ERRSV);
+ if (IN_PERL_COMPILETIME && !had_err && has_err)
+ ++PL_error_count;
+ }
SPAGAIN;
- if (eval && IN_PERL_COMPILETIME && SvTRUE(ERRSV))
- ++PL_error_count;
svr = POPs;
ret = SvOK(svr) ? SvIV(svr) : 0;
PUTBACK;
FREETMPS;
LEAVE;
+ if (has_err) {
+ /* Get the eval context that was pushed by call_sv, and fake an entry for the
+ * namesv, as die_where will need it to be non NULL later */
+ PERL_CONTEXT *cx = cxstack + cxstack_ix + 1;
+ if (!cx->blk_eval.old_namesv)
+ cx->blk_eval.old_namesv
+ = sv_2mortal(newSVpvn_share("Variable/Magic/DUMMY.pm", 23, 0));
+ }
+
return ret;
}
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 8 + 1;
use Variable::Magic qw/wizard cast/;
}};
like $@, qr/pepperoni/, 'die in len callback in BEGIN';
+
+use lib 't/lib';
+eval "use Variable::Magic::TestDieRequired";
+
+like $@, qr/turnip/, 'die in required with localized hash gets the right error message';