From 5e3de39d43d7b9736a5583073112e237a5da00a9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 26 Aug 2019 03:14:22 +0000 Subject: [PATCH] If enabling fp traps for first time, clear sticky exceptions. Otherwise, the indeterminate state of the sticky exceptions -- possibly from another thread -- may cause the machine to trap merely by enabling traps. Also, don't bother marking the floating-point environment in use when disabling traps. --- src/runtime/floenv.scm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runtime/floenv.scm b/src/runtime/floenv.scm index fc6254859..149e815da 100644 --- a/src/runtime/floenv.scm +++ b/src/runtime/floenv.scm @@ -245,15 +245,20 @@ USA. ((ucode-primitive restore-float-exception-flags 2) fexcept exceptions)) (define (flo:set-trapped-exceptions! exceptions) - (use-floating-point-environment!) + (if (not (using-floating-point-environment?)) + (begin + ((ucode-primitive clear-float-exceptions 1) exceptions) + (use-floating-point-environment!))) ((ucode-primitive set-trapped-float-exceptions 1) exceptions)) (define (flo:trap-exceptions! exceptions) - (use-floating-point-environment!) + (if (not (using-floating-point-environment?)) + (begin + ((ucode-primitive clear-float-exceptions 1) exceptions) + (use-floating-point-environment!))) ((ucode-primitive trap-float-exceptions 1) exceptions)) (define (flo:untrap-exceptions! exceptions) - (use-floating-point-environment!) ((ucode-primitive untrap-float-exceptions 1) exceptions)) (define (flo:defer-exception-traps!) -- 2.25.1