int ret = 0;
I32 oldscope;
OP *old_next;
+ SV * const oldwarnhook = PL_warnhook;
+ SV * const olddiehook = PL_diehook;
dJMPENV;
if (PL_opargs[type] & OA_RETSCALAR)
oldscope = PL_scopestack_ix;
create_eval_scope(G_FAKINGEVAL);
+ PL_warnhook = PERL_WARNHOOK_FATAL;
+ PL_diehook = NULL;
JMPENV_PUSH(ret);
switch (ret) {
SvTEMP_off(sv);
}
break;
- case 2:
- /* my_exit() was called; propagate it */
- JMPENV_POP;
- JMPENV_JUMP(2);
- /* NOTREACHED */
case 3:
/* Something tried to die. Abandon constant folding. */
/* Pretend the error never happened. */
break;
default:
JMPENV_POP;
- /* Don't expect 1 (setjmp failed) */
+ /* Don't expect 1 (setjmp failed) or 2 (something called my_exit) */
+ PL_warnhook = oldwarnhook;
+ PL_diehook = olddiehook;
+ /* XXX note that this croak may fail as we've already blown away
+ * the stack - eg any nested evals */
Perl_croak(aTHX_ "panic: fold_constants JMPENV_PUSH returned %d", ret);
}
-
JMPENV_POP;
+ PL_warnhook = oldwarnhook;
+ PL_diehook = olddiehook;
if (PL_scopestack_ix > oldscope)
delete_eval_scope();
use strict;
use warnings;
-plan (8);
+plan (13);
# Historically constant folding was performed by evaluating the ops, and if
# they threw an exception compilation failed. This was seen as buggy, because
# making constant folding consistent with many other languages, and purely an
# optimisation rather than a behaviour change.
+
my $a;
$a = eval '$b = 0/0 if 0; 3';
is ($a, 3);
is ($a, 5);
is ($@, "");
+# warn and die hooks should be disabled during constant folding
+
+{
+ my $c = 0;
+ local $SIG{__WARN__} = sub { $c++ };
+ local $SIG{__DIE__} = sub { $c+= 2 };
+ eval q{
+ is($c, 0, "premature warn/die: $c");
+ my $x = "a"+5;
+ is($c, 1, "missing warn hook");
+ is($x, 5, "a+5");
+ $c = 0;
+ $x = 1/0;
+ };
+ like ($@, qr/division/, "eval caught division");
+ is($c, 2, "missing die hook");
+}
Perl_vwarner(pTHX_ U32 err, const char* pat, va_list* args)
{
dVAR;
- if (ckDEAD(err)) {
+ if (PL_warnhook == PERL_WARNHOOK_FATAL || ckDEAD(err)) {
SV * const msv = vmess(pat, args);
STRLEN msglen;
const char * const message = SvPV_const(msv, msglen);
#define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
(x) == pWARN_NONE)
+/* if PL_warnhook is set to this value, then warnings die */
+#define PERL_WARNHOOK_FATAL (((SV*)0) + 1)
+
/* Warnings Categories added in Perl 5.008 */
#define WARN_ALL 0
#define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
(x) == pWARN_NONE)
+
+/* if PL_warnhook is set to this value, then warnings die */
+#define PERL_WARNHOOK_FATAL (((SV*)0) + 1)
EOM
my $offset = 0 ;