When this option is ON, opencascade::handle throws std::runtime_error() on NULL pointer dereference,
and Standard_OutOfRange_Raise_if throws std::runtime_error() instead of Standard_OutOfRange
to detect cases when broken code remains hidden by exception handling.
set (BUILD_RELEASE_DISABLE_EXCEPTIONS ON CACHE BOOL "${BUILD_RELEASE_DISABLE_EXCEPTIONS_DESCR}")
endif()
+# option enabling extra exceptions (OCCT_DEBUG_SANITIZE_EXCEPTIONS)
+if (NOT DEFINED BUILD_ENABLE_SANITIZE_EXCEPTIONS)
+ set (BUILD_ENABLE_SANITIZE_EXCEPTIONS OFF CACHE BOOL "${BUILD_ENABLE_SANITIZE_EXCEPTIONS_DESCR}")
+endif()
+
+if (BUILD_ENABLE_SANITIZE_EXCEPTIONS)
+ add_definitions (-DOCCT_DEBUG_SANITIZE_EXCEPTIONS)
+endif()
+# DEBUG
+add_definitions (-DOCCT_DEBUG_SANITIZE_EXCEPTIONS)
+
# option to enable or disable use of precompiled headers
if (NOT DEFINED BUILD_USE_PCH)
set (BUILD_USE_PCH OFF CACHE BOOL "${BUILD_USE_PCH_DESCR}")
Defines No_Exception macros for Release builds when enabled (default).
These exceptions are always enabled in Debug builds, but disable in Release for better performance")
+set (BUILD_ENABLE_SANITIZE_EXCEPTIONS_DESCR
+"Enables extra exceptions for detecting broken code. Should NOT be used for production.
+Defines OCCT_DEBUG_SANITIZE_EXCEPTIONS macros when enabled (OFF by default).")
+
set (BUILD_ENABLE_FPE_SIGNAL_HANDLER_DESCR
"Enable/Disable the floating point exceptions (FPE) during DRAW execution only.
Corresponding environment variable (CSF_FPE) can be changed manually
//# define _OSD_FPX ( _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW )
# define _OSD_FPX ( _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW )
+#ifdef OCCT_DEBUG_SANITIZE_EXCEPTIONS
+ #define THROW_OR_JUMP(Type,Message) throw std::runtime_error (Message)
+#else
#ifdef OCC_CONVERT_SIGNALS
-#define THROW_OR_JUMP(Type,Message) Type::NewInstance(Message)->Jump()
+ #define THROW_OR_JUMP(Type,Message) Type::NewInstance(Message)->Jump()
#else
-#define THROW_OR_JUMP(Type,Message) throw Type(Message)
+ #define THROW_OR_JUMP(Type,Message) throw Type(Message)
+#endif
#endif
//=======================================================================
#include <type_traits>
+#ifdef OCCT_DEBUG_SANITIZE_EXCEPTIONS
+ #include <stdexcept>
+#endif
+
class Standard_Transient;
//! Namespace opencascade is intended for low-level template classes and functions
T* get() const { return static_cast<T*>(this->entity); }
//! Member access operator (note non-const)
- T* operator-> () const { return static_cast<T*>(this->entity); }
+ T* operator-> () const
+ {
+ #ifdef OCCT_DEBUG_SANITIZE_EXCEPTIONS
+ if (entity == 0)
+ {
+ throw std::runtime_error ("null pointer exception");
+ }
+ #endif
+ return static_cast<T*>(this->entity);
+ }
//! Dereferencing operator (note non-const)
- T& operator* () const { return *get(); }
+ T& operator* () const
+ {
+ #ifdef OCCT_DEBUG_SANITIZE_EXCEPTIONS
+ if (entity == 0)
+ {
+ throw std::runtime_error ("null pointer exception");
+ }
+ #endif
+ return *get();
+ }
//! Check for equality
template <class T2>
class Standard_OutOfRange;
DEFINE_STANDARD_HANDLE(Standard_OutOfRange, Standard_RangeError)
-#if !defined No_Exception && !defined No_Standard_OutOfRange
+#ifdef OCCT_DEBUG_SANITIZE_EXCEPTIONS
+#define Standard_OutOfRange_Raise_if(CONDITION, MESSAGE) \
+ if (CONDITION) throw std::runtime_error (MESSAGE);
+#elif !defined No_Exception && !defined No_Standard_OutOfRange
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
// suppress false-positive warnings produced by GCC optimizer
#define Standard_OutOfRange_Raise_if(CONDITION, MESSAGE) \