From: Taylor R Campbell Date: Tue, 2 Nov 2010 01:42:15 +0000 (+0000) Subject: Make BSD feraiseexcept actually raise the exception. X-Git-Tag: 20101212-Gtk~16 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3849c54d71e39268ddc84d011412d1e67ea1c095;p=mit-scheme.git Make BSD feraiseexcept actually raise the exception. Forcing a floating-point operation by storing the (double) sum of two volatile variables in a volatile variable is pretty kludgey, but it works. --- diff --git a/src/microcode/floenv.h b/src/microcode/floenv.h index 40358f137..70ef9b37d 100644 --- a/src/microcode/floenv.h +++ b/src/microcode/floenv.h @@ -119,10 +119,19 @@ typedef fp_except fexcept_t; # ifndef HAVE_FERAISEEXCEPT # define HAVE_FERAISEEXCEPT -/* This isn't right -- it doesn't necessarily actually raise the - exception until some floating-point operation is performed. */ -# define feraiseexcept(excepts) \ - ((fpsetsticky ((fpgetsticky ()) | (FE_ALL_EXCEPT & (excepts)))), 0) +static inline int +feraiseexcept (int excepts) +{ + (void) fpsetsticky ((fpgetsticky ()) | (FE_ALL_EXCEPT & (excepts))); + /* Force a floating-point operation to happen, which ideally should + trap if there are unmasked exceptions pending, presumably because + of the above fpsetsticky. */ + volatile double x = 0; + volatile double y = 0; + volatile double z = (x + y); + (void) z; /* ignored */ + return (0); +} # endif # ifndef HAVE_FEGETEXCEPTFLAG @@ -208,8 +217,6 @@ feupdateenv (const fenv_t *fe) { fp_except exceptions = (fpgetsticky ()); (void) fesetenv (fe); - /* Unfortunately, this doesn't actually do anything, because of the - useless definition of feraiseexcept above. */ (void) feraiseexcept (exceptions); return (0); }