in reply to FPE not deferred in 5.36

Here's the case that caused me to investigate and add this change in the first place:

% $PERL-5.34.0 -MMath::GMP -wle 'local $SIG{FPE} = sub { die "fpe" }; +$z=Math::GMP->new(1); print $z / 0' Maximal count of pending signals (120) exceeded at -e line 1. fpe at -e line 1. % % $PERL-5.36.0 -MMath::GMP -wle 'local $SIG{FPE} = sub { die "fpe" }; +$z=Math::GMP->new(1); print $z / 0' fpe at -e line 1. %

The original ticket was Catching SIGFPE. Not sure why my example above isn't reproducing that, but in my real-world code this was stopping me from getting a stack trace to find where the division by zero was occurring.

Despite the name, this exception is primarily raised for integer division by zero, so the Inline::C example needs s{float}{int}g to show it. See why was sigfpe used for integer arithmetic exceptions for some more detail.

Perl itself catches these when it performs a division, so you'll only see it from non-perl code linked to your program.

Replies are listed 'Best First'.
Re^2: FPE not deferred in 5.36
by choroba (Cardinal) on May 31, 2022 at 15:32 UTC
    I can confirm that with ints, it emits "Maximal count of pending signals". It still outputs the line number, as you noted. Probably not worth including into Syntax::Construct, as the change in behaviour is hard to test and the code probably doesn't depend on that (the user debugging the code, though, might well do).

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      This is rather strange - removing the 'local' stops the die message from showing up:

      % perl-5.34.0 -MMath::GMP -wle 'local $SIG{FPE} = sub { die "divide by + zero" }; $z=Math::GMP->new(1); print $z / 0' Maximal count of pending signals (120) exceeded at -e line 1. divide by zero at -e line 1. % % perl-5.34.0 -MMath::GMP -wle '$SIG{FPE} = sub { die "divide by zero" + }; $z=Math::GMP->new(1); print $z / 0' Maximal count of pending signals (120) exceeded at -e line 1. %

      I don't know why that's occurring. I guess it's possible there's a bug here, but I'm not sure how I might start investigating it. If anything I'd have imagined it working the other way round.

        If there's a bug, we'll need to find a different reproducer, as the fix to FPE makes the behaviour of the code identical in 5.36.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]