John Darrington <[EMAIL PROTECTED]> writes: > Furthermore, I doubt it's possible portably. I suspect that some > CPUs will in fact retry the instruction and fault again in a loop. > > They all will. A signal handler returns to the address that caused it. > Provided that sigaction (part of the POSIX standard) is supported we > can reliably overcome this problem thus: > > We have two signal handlers: fpe_handler_ignore, which does nothing, > and fpe_handler_warn which a) logs a warning message, b) resets the > handler to fpe_handler_ignore, and c) returns. > > At the start of every procedure, the active handler is reset to > fpe_handler_warn. Thus, when a FPE occurs, the user gets a warning, > the handler is set to ignore further FPEs and the procedure completes > normally. The user gets his results, but has been warned that they > might not be correct.
You know, I take back my earlier comments. This is pretty reasonable, but only as long as the signal handler only sets a flag that indicates an error has occurred, and masks further exceptions. Then leave the real handling up to the caller. If the caller notices, it can comment on it (and reset it); otherwise, the main loop can issue a warning after the procedure completes. (Doing I/O in a signal handler is really a bad idea.) We still need to be able to mask exceptions, though. Otherwise, fpe_handler_ignore will just get called in an infinite loop, which is not an improvement. Thus, I believe that we really want "fpe_handler_record". -- "There's only one thing that will make them stop hating you. And that's being so good at what you do that they can't ignore you. I told them you were the best. Now you damn well better be." --Orson Scott Card, _Ender's Game_ _______________________________________________ pspp-dev mailing list [email protected] http://lists.gnu.org/mailman/listinfo/pspp-dev
