← Back to team overview

kicad-developers team mailing list archive

[PATCH] Enable floating point exceptions in Debug, disable in Release

 

Hi,

this enables FP exceptions everywhere in Debug mode, and disables them in
Release mode. This is for testing only, and should *not* yet go into
mainline.

Still needed:

 - signal handler that complains and allows continuing
 - context library handling
 - tests

   Simon

---
 common/single_top.cpp                 | 6 ++++++
 kicad/kicad.cpp                       | 6 ++++++
 qa/qa_utils/pcb_test_frame.cpp        | 8 ++++++++
 utils/idftools/idf2vrml.cpp           | 6 ++++++
 utils/kicad-ogltest/kicad-ogltest.cpp | 6 ++++++
 utils/kicad2step/kicad2step.cpp       | 6 ++++++
 6 files changed, 38 insertions(+)

diff --git a/common/single_top.cpp b/common/single_top.cpp
index b50ecf18a..f527c8b35 100644
--- a/common/single_top.cpp
+++ b/common/single_top.cpp
@@ -47,6 +47,7 @@
 #include <kiway_player.h>
 #include <confirm.h>
 
+#include <fenv.h>
 
 // Only a single KIWAY is supported in this single_top top level component,
 // which is dedicated to loading only a single DSO.
@@ -150,6 +151,11 @@ struct APP_SINGLE_TOP : public wxApp
 
     bool OnInit() override
     {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
         // Force wxHtmlWinParser initialization when a wxHtmlWindow is used only
         // in a shared modules (.so or .dll file)
         // Otherwise the Html text is displayed as plain text.
diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp
index 2ca33d77e..84b5b1acc 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -41,6 +41,7 @@
 #include <systemdirsappend.h>
 
 #include <stdexcept>
+#include <fenv.h>
 
 #include "pgm_kicad.h"
 
@@ -245,6 +246,11 @@ struct APP_KICAD : public wxApp
 
     bool OnInit()           override
     {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
         return program.OnPgmInit();
     }
 
diff --git a/qa/qa_utils/pcb_test_frame.cpp b/qa/qa_utils/pcb_test_frame.cpp
index 04b403fa2..2a8ea950e 100644
--- a/qa/qa_utils/pcb_test_frame.cpp
+++ b/qa/qa_utils/pcb_test_frame.cpp
@@ -59,6 +59,9 @@
 #include <tools/selection_tool.h>
 #include <kicad_plugin.h>
 
+#include <fenv.h>
+
+
 #include "pcb_test_frame.h"
 
 IMPLEMENT_APP( GAL_TEST_APP )
@@ -67,6 +70,11 @@ using namespace KIGFX;
 
 bool GAL_TEST_APP::OnInit()
 {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
     if( !wxApp::OnInit() )
         return false;
 
diff --git a/utils/idftools/idf2vrml.cpp b/utils/idftools/idf2vrml.cpp
index 4eb34c6d1..cb9212c3f 100644
--- a/utils/idftools/idf2vrml.cpp
+++ b/utils/idftools/idf2vrml.cpp
@@ -52,6 +52,7 @@
 #include <cstring>
 #include <algorithm>
 #include <boost/ptr_container/ptr_map.hpp>
+#include <fenv.h>
 
 #include "idf_helpers.h"
 #include "idf_common.h"
@@ -105,6 +106,11 @@ bool showObjectMapping;
 
 bool IDF2VRML::OnInit()
 {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
     m_ScaleFactor = 1.0;
     m_Compact = true;
     m_NoOutlineSubs = false;
diff --git a/utils/kicad-ogltest/kicad-ogltest.cpp b/utils/kicad-ogltest/kicad-ogltest.cpp
index 31157b900..a1b56edc5 100644
--- a/utils/kicad-ogltest/kicad-ogltest.cpp
+++ b/utils/kicad-ogltest/kicad-ogltest.cpp
@@ -32,6 +32,7 @@
 #include <gal/opengl/opengl_gal.h>
 #include <pgm_base.h>
 #include <iostream>
+#include <fenv.h>
 
 // Required OpenGL version
 #define REQUIRED_MAJOR 2L
@@ -79,6 +80,11 @@ public:
 
 bool OGLTEST_APP::OnInit()
 {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
     WX_QUIET be_quiet;
 
     auto frame = new wxFrame( nullptr, wxID_ANY, "OpenGL test", wxDefaultPosition, wxDefaultSize,
diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp
index df3dc8e7a..701db7a63 100644
--- a/utils/kicad2step/kicad2step.cpp
+++ b/utils/kicad2step/kicad2step.cpp
@@ -31,6 +31,7 @@
 #include <iostream>
 #include <sstream>
 #include <Standard_Failure.hxx>
+#include <fenv.h>
 
 #include "pcb/kicadpcb.h"
 
@@ -96,6 +97,11 @@ wxIMPLEMENT_APP_CONSOLE( KICAD2MCAD );
 
 bool KICAD2MCAD::OnInit()
 {
+#ifdef NDEBUG
+        fedisableexcept(FE_ALL_EXCEPT);
+#else
+        feenableexcept(FE_ALL_EXCEPT);
+#endif
 #ifdef SUPPORTS_IGES
     m_fmtIGES = false;
 #endif

Follow ups

References